Creating variables via a "for/next" loop..?
BlitzPlus Forums/BlitzPlus Programming/Creating variables via a "for/next" loop..?
| ||
Hello people, I have a special question.. I have this 'type': Type bingo Field Number Field Value End Type ..for this code..: If EventSource()=Button01 And EventID()=$401 Then For b.bingo = Each bingo If b\Number = 1 Then Found=True : Exit Next If Found=True Then Found=False b\Value = b\Value + 1 Else b.bingo = New bingo b\Number = 1 b\Value = 1 End If SetGadgetText label01,"1: "+b\Value End If If EventSource()=Button02 And EventID()=$401 Then For b.bingo = Each bingo If b\Number = 2 Then Found=True : Exit Next If Found=True Then Found=False b\Value = b\Value + 1 Else b.bingo = New bingo b\Number = 2 b\Value = 1 End If SetGadgetText label02,"2: "+b\Value End If It is for button-clicking. When a certain button is clicked, some values will change. This is the code for the first two buttons. The code for each button is 14 lines, and I need 90 (ninety!) buttons. This code works fine and dandy, but it's gonna be big as hell!!! 1260 lines, not counting spaces in between.. I would hope there was a way of doing this for all 90 buttons, in 10-20 lines of code.. Question: Is there a way to create variables with a 'for/next' loop? Like this (not possible): for a=1 to 90 a$="Button"+a ;a$ would then be "Button1" first.. If EventSource()=a$ ;"a$" instead of "Button1".. ..blah blah.. next Like I said, that code is not legal, but you get my point. I have been experimenting with it, but I cannot find a "legal" way of doing it.. :( Is there ANY way of pulling this off?? Thanks in advance, people. ;-) |
| ||
Just use arrays first create the buttons dim button(90) for i=1 to 90 button(i)=createbutton() ;whatever button code you need here next Then to update the buttons you just do for i=1 to 90 If EventSource()=Button(i) And EventID()=$401 Then For b.bingo = Each bingo If b\Number = i Then Found=True : Exit Next ;rest of the stuff here End If next |
| ||
Oh yes! Thank you very much! :) |