找回密码
 加入
搜索
查看: 3932|回复: 6

[效率算法] [已解决]复选框,循环问题

[复制链接]
发表于 2010-11-30 17:36:47 | 显示全部楼层 |阅读模式
本帖最后由 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)

这样就可以提取 复选框 的值了
 楼主| 发表于 2010-11-30 17:41:37 | 显示全部楼层
$Checkbox_1 = ControlGetText("","",$Checkbox1 )
这个可以正常运行,

$Check_box = "$Checkbox" & $i
这个输出的结果是:$Checkbox1

为什么就不能正常运行了呢?
发表于 2010-11-30 18:30:49 | 显示全部楼层
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("", 623, 449)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Global $Checkbox[8], $iCheckbox[8] = ["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

评分

参与人数 1金钱 +20 贡献 +1 收起 理由
afan + 20 + 1

查看全部评分

 楼主| 发表于 2010-11-30 21:26:14 | 显示全部楼层
回复 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[1] = GUICtrlCreateCheckbox("榴莲", 64, 40, 97, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("榴莲", 80, 64, 97, 17)
$Checkbox[3] = GUICtrlCreateCheckbox("榴莲", 64, 88, 97, 17)
$Button1 = GUICtrlCreateButton("Button1", 56, 264, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
发表于 2010-11-30 21:43:43 | 显示全部楼层
本帖最后由 飘云 于 2010-11-30 21:45 编辑

$Checkbox_1 = ControlGetText("","",&Check_box).......
控件ID可以是&的吗?不应该是$Check_box吗。。。
发表于 2010-11-30 21:46:18 | 显示全部楼层
另外,把 $Check_box = "$Checkbox" & $i作为ID是无效的,应该用函数Eval,即$Check_box = Eval( "$Checkbox" & $i)
发表于 2010-12-1 10:02:18 | 显示全部楼层
回复 4# laomao127


    数组需要先定义 看我第7行
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-21 06:05 , Processed in 0.082474 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表