JDK Posted July 29, 2009 Share Posted July 29, 2009 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!! Link to comment Share on other sites More sharing options...
Richard Robertson Posted July 29, 2009 Share Posted July 29, 2009 There is no case where you can't use an array. If you choose to do it this way, you use Eval("var" & $i). Link to comment Share on other sites More sharing options...
Authenticity Posted July 29, 2009 Share Posted July 29, 2009 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. Link to comment Share on other sites More sharing options...
JDK Posted July 30, 2009 Author Share Posted July 30, 2009 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! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now