Jump to content

Recommended Posts

Posted

I would like to get a reference to a global variable by name dynamically because I can't use an array in my particular case. What I want to do is something like this:

Global $var1
Global $var2
Global $var3

Func test()
For $i = 1 To 3
$targetVar = $("var" & $i)   ; THIS LINE WILL NOT WORK!!! WHAT IS THE CORRECT SYNTAX???
GUICtrlSetData($targetVar, "data for label " & $i & " goes here") 
Next
EndFunc

Can anyone give me an example of the proper syntax?

Thanks!!

Posted

Opt('ExpandVarStrings', 1)

Global $var1 = 1
Global $var2 = 2
Global $var3 = 3

test()

Func test()
    For $i = 1 To 3
        ConsoleWrite(Eval("var" & $i) & @CRLF)
        GUICtrlSetData(Eval("var$i$"), "data for label " & $i & " goes here")
    Next
EndFunc   ;==>test

This is the correct syntax, but you should consider using arrays. There is only array equivalence to such an iteration construct.

Thanks, I'll give this a shot. My problem is, Koda Form Designer doesn't appear to allow GUI elements with name fields that are arrays. It wants simple variables. I'll see if I can use this syntax rather than resort to a whole lot of simple variables and a big Select. Thanks!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...