找回密码
 加入
搜索
查看: 2073|回复: 4

[AU3基础] 如何將選取多checkbox的值存入變數

[复制链接]
发表于 2011-9-9 10:24:36 | 显示全部楼层 |阅读模式
大大您好:
小弟新手想請問如何將以下每次值存入$caption 該如何寫,如選1,2,5,要的結果是1,2,5將最後豆號去掉
謝謝會的請大大幫忙
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox[10],$caption
$Checkbox[1] = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox[3] = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox[4] = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox[5] = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox[6] = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox[7] = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox[8] = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox[9] = GUICtrlCreateCheckbox("9", 190, 150)

$Button1 = GUICtrlCreateButton("確認", 50, 240, 170, 25, $WS_GROUP)
GUISetState()
For $i = 1 To 9
GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
                                                                                
Next





While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
              
                                                        
                Case $Button1
                For $i = 1 To 9
                $state=GUICtrlRead($Checkbox[$i])
                                           
                IF $state==$GUI_CHECKED Then
                                             
                $caption =GUICtrlRead($Checkbox[$i],1)
                
                EndIf
                                                                        
                Next
                                                                
        EndSwitch
WEnd
发表于 2011-9-9 10:48:33 | 显示全部楼层
回复 1# cks1203


    没明白你的意思,象下面这样?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox[10]
$Checkbox[1] = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox[3] = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox[4] = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox[5] = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox[6] = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox[7] = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox[8] = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox[9] = GUICtrlCreateCheckbox("9", 190, 150)
For $i = 1 To 9
        GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
Next
$Button1 = GUICtrlCreateButton("確認", 50, 240, 170, 25, $WS_GROUP)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Local $caption = ""
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        For $i = 1 To 9
                                If  GUICtrlRead($Checkbox[$i]) == $GUI_CHECKED Then $caption &= $i
                        Next
                        MsgBox(0, 0, $caption)
        EndSwitch
WEnd
 楼主| 发表于 2011-9-9 11:30:14 | 显示全部楼层
回复 2# happytc

謝謝大大的回覆:
這正是小弟要的,但是還有一個問題想請問就是變數存入後要以 , 區隔開以便資料庫數據select用,如何將最後一個, 拿掉
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
 
$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox[10]
$Checkbox[1] = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox[3] = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox[4] = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox[5] = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox[6] = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox[7] = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox[8] = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox[9] = GUICtrlCreateCheckbox("9", 190, 150)
For $i = 1 To 9
        GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
Next
$Button1 = GUICtrlCreateButton("確認", 50, 240, 170, 25, $WS_GROUP)
GUISetState()
 
While 1
        $nMsg = GUIGetMsg()
        Local $caption = ""
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        For $i = 1 To 9
                                If  GUICtrlRead($Checkbox[$i]) == $GUI_CHECKED Then $caption &= $i & ","
                        Next
                        MsgBox(0, 0, $caption)
        EndSwitch
WEnd
发表于 2011-9-9 11:46:02 | 显示全部楼层
回复 3# cks1203

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox[10]
$Checkbox[1] = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox[2] = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox[3] = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox[4] = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox[5] = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox[6] = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox[7] = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox[8] = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox[9] = GUICtrlCreateCheckbox("9", 190, 150)
For $i = 1 To 9
        GUICtrlSetState($Checkbox[$i], $GUI_CHECKED)
Next
$Button1 = GUICtrlCreateButton("確認", 50, 240, 170, 25, $WS_GROUP)
GUISetState()

While 1
        $nMsg = GUIGetMsg()
        Local $caption = ""
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        For $i = 1 To 9
                                If GUICtrlRead($Checkbox[$i]) == $GUI_CHECKED Then 
                                        If $caption == "" Then
                                                $caption &= $i
                                        Else
                                                $caption &= "," & $i
                                        EndIf
                                EndIf
                        Next
                        MsgBox(0, 0, $caption)
        EndSwitch
WEnd
 楼主| 发表于 2011-9-9 12:05:33 | 显示全部楼层
謝謝大大,大大真是厲害啊
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 00:44 , Processed in 0.106944 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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