[已解决]复选框,循环问题
本帖最后由 laomao127 于 2010-11-30 22:21 编辑$Checkbox1 = GUICtrlCreateCheckbox("榴莲1", 64, 40, 97, 17)
$Checkbox2 = GUICtrlCreateCheckbox("榴莲1", 80, 64, 97, 17)
$Checkbox3 = GUICtrlCreateCheckbox("榴莲1", 64, 88, 97, 17)
$Checkbox4 = GUICtrlCreateCheckbox("榴莲1", 80, 112, 97, 17)
$Checkbox5 = GUICtrlCreateCheckbox("榴莲1", 64, 136, 97, 17)
$Checkbox6 = GUICtrlCreateCheckbox("榴莲1", 80, 160, 97, 17)
$Checkbox7 = GUICtrlCreateCheckbox("榴莲1", 64, 184, 97, 17)
$Checkbox8 = GUICtrlCreateCheckbox("榴莲1", 80, 208, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 56, 264, 75, 25)
创建了8个复选框,用循环提取复选框的名称"榴莲1"请看我写的代码:
For $i = 1 To 8
$Checkbox = IniRead("config.ini", "Server","Checkbox" & $i, "") ;config.ini文件里Checkbox1 = 1
If $Checkbox = 1 Then
$Check_box = "$Checkbox" & $i
$Checkbox_1 = ControlGetText("","",&Check_box)
MsgBox(0,"",$Checkbox_1)
EndIf
Next
MsgBox(0,"","错误")
输出的结果总是空,我知道问题肯定是出在"$Checkbox_1 = ControlGetText("","",&Check_box)" 这里 但是怎么解决呢? 请高手帮忙
答案: 可以参考三楼
谢谢 飘云 、shenrenba
下面是我写的代码
$Checkbox_1 = ControlGetText("","",Eval( "Checkbox" & $i))
MsgBox(0,"",$Checkbox_1)
这样就可以提取 复选框 的值了 $Checkbox_1 = ControlGetText("","",$Checkbox1 )
这个可以正常运行,
$Check_box = "$Checkbox" & $i
这个输出的结果是:$Checkbox1
为什么就不能正常运行了呢? #include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("", 623, 449)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Checkbox, $iCheckbox = ["1", "0", "1", "0", "1", "0", "1", "1"]
For $ii = 0 To 7
$Checkbox[$ii] = GUICtrlCreateCheckbox("榴莲" & $ii, 64 + 16 * BitAND($ii, 1), 40 + 24 * $ii, 97, 17)
Next
$Button1 = GUICtrlCreateButton("Button1", 56, 264, 75, 25)
GUICtrlSetOnEvent(-1, "Button1Click")
GUISetState(@SW_SHOW)
While 1
Sleep(100)
WEnd
Func Button1Click()
For $i = 0 To 7
If $iCheckbox[$i] = 1 Then
GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
MsgBox(0, "", "选中了" & "$iCheckbox[" & $i & "] 文本是" & ControlGetText("", "", $Checkbox[$i]))
EndIf
Next
EndFunc
Func Form1Close()
Exit
EndFunc 回复 3# shenrenba
您可以这样
For $ii = 0 To 7
$Checkbox[$ii] = GUICtrlCreateCheckbox("榴莲" & $ii, 64 + 16 * BitAND($ii, 1), 40 + 24 * $ii, 97, 17)
Next
$Button1 = GUICtrlCreateButton("Button1", 56, 264, 75, 25)
为什么我这样就不行呢?
$Form1 = GUICreate("Form1", 320, 449, 344, 154)
$Checkbox = GUICtrlCreateCheckbox("榴莲", 64, 40, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("榴莲", 80, 64, 97, 17)
$Checkbox = GUICtrlCreateCheckbox("榴莲", 64, 88, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 56, 264, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ### 本帖最后由 飘云 于 2010-11-30 21:45 编辑
$Checkbox_1 = ControlGetText("","",&Check_box).......
控件ID可以是&的吗?不应该是$Check_box吗。。。 另外,把 $Check_box = "$Checkbox" & $i作为ID是无效的,应该用函数Eval,即$Check_box = Eval( "$Checkbox" & $i) 回复 4# laomao127
数组需要先定义 看我第7行
页:
[1]