如何將選取多checkbox的值存入變數
大大您好:小弟新手想請問如何將以下每次值存入$caption 該如何寫,如選1,2,5,要的結果是1,2,5將最後豆號去掉
謝謝會的請大大幫忙#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox,$caption
$Checkbox = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox = 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 回复 1# cks1203
没明白你的意思,象下面这样?
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox
$Checkbox = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox = 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
IfGUICtrlRead($Checkbox[$i]) == $GUI_CHECKED Then $caption &= $i
Next
MsgBox(0, 0, $caption)
EndSwitch
WEnd
回复 2# happytc
謝謝大大的回覆:
這正是小弟要的,但是還有一個問題想請問就是變數存入後要以 , 區隔開以便資料庫數據select用,如何將最後一個, 拿掉#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox
$Checkbox = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox = 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
IfGUICtrlRead($Checkbox[$i]) == $GUI_CHECKED Then $caption &= $i & ","
Next
MsgBox(0, 0, $caption)
EndSwitch
WEnd 回复 3# cks1203
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("test", 260, 280)
Dim $Checkbox
$Checkbox = GUICtrlCreateCheckbox("1", 50, 50, 25, 17)
$Checkbox = GUICtrlCreateCheckbox("2", 120, 50)
$Checkbox = GUICtrlCreateCheckbox("3", 190, 50)
$Checkbox = GUICtrlCreateCheckbox("4", 50, 100)
$Checkbox = GUICtrlCreateCheckbox("5", 120, 100)
$Checkbox = GUICtrlCreateCheckbox("6", 190, 100)
$Checkbox = GUICtrlCreateCheckbox("7", 50, 150)
$Checkbox = GUICtrlCreateCheckbox("8", 120, 150)
$Checkbox = 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
謝謝大大,大大真是厲害啊
页:
[1]