增量变量定义 [英] Incremental variable definition

查看:42
本文介绍了增量变量定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想自动定义递增的变量名.

所以不是这样:

$Var1 = '这是变量一:P'$Var2 = '这是变量二:P'

我想要这个(伪代码):

对于 $i = 1 到 UBound($People)-1**$var[$i]** = GUICtrlCreateCheckbox($var[$i], 24, $y, 200, 17)$y = $y + 25下一个

有人知道怎么做吗?

代码应该创建与数组中定义的一样多的复选框,并且每个复选框都应该有自己的变量.

解决方案

您正在寻找 Assign 功能!

看看这个例子:

对于 $i = 1 到 5分配('var' & $i, $i);下一个

然后您可以通过以下方式访问这些变量:

MsgBox(4096, "我的动态变量", $var1)MsgBox(4096, "我的动态变量", $var3)MsgBox(4096, "我的动态变量", $var5)

显然,var2var3 也可以使用 :)

为了清楚起见,如果您做得正确,您会做的是将这些值存储在数组中 - 这是处理此类事情的最佳方法.>

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.

解决方案

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.

这篇关于增量变量定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆