Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

arrays - Incremental variable definition

I want to automatically define incrementing variable names.

So instead of this:

$Var1 = 'This is variable one :P'
$Var2 = 'This is variable two :P'

I'd like this (pseudo code):

For $i = 1 to UBound($People)-1     
    **$var[$i]** = GUICtrlCreateCheckbox($var[$i], 24, $y, 200, 17) 
    $y = $y + 25 
Next

Does anyone know how?

The code should make as many checkboxes as defined in an array and every checkbox should have its own variable.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You're looking for the Assign function!

Check out this example:

For $i = 1 To 5
    Assign('var' & $i, $i);
Next

Then you can access these variables with:

MsgBox(4096, "My dynamic variables", $var1)
MsgBox(4096, "My dynamic variables", $var3)
MsgBox(4096, "My dynamic variables", $var5)

Obviously, var2 and var3 can be utilised too :)

Edit: For clarity, what you would have been doing, if you had done it properly, was storing those values in an array - which is the best method for this kind of thing.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...