sliceofpie Posted October 1, 2010 Share Posted October 1, 2010 Hello AUTOIT Forum! I have a question: My script has checkboxes and I'd like to pass on whichever one is checked and display the results in one line.Sample output: " MON, TUE, WED, THU, FRI " expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIonEventMode", 1) $Form1 = GUICreate("Select Days of the Week", 146, 258, 201, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit") $FirstBox = GUICtrlCreateCheckbox("Monday", 32, 32, 97, 17) $SecondBox = GUICtrlCreateCheckbox("Tuesday", 32, 64, 97, 17) $ThirdBox = GUICtrlCreateCheckbox("Wednesday", 32, 96, 97, 17) $FourthBox = GUICtrlCreateCheckbox("Thursday", 32, 128, 97, 17) $BoxFive = GUICtrlCreateCheckbox("Friday", 32, 160, 97, 17) $Button1 = GUICtrlCreateButton("Weekdays", 32, 200, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_buttonpressed") Global $string GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(10) WEnd Func _buttonpressed() Local $value_of_FirstBox, $value_of_SecondBox, $value_of_ThirdBox, $value_of_FourthBox, $value_of_BoxFive If GUICtrlRead($FirstBox) = 1 Then $value_of_FirstBox = "MON" If GUICtrlRead($SecondBox) = 1 Then $value_of_SecondBox = "TUE" If GUICtrlRead($ThirdBox) = 1 Then $value_of_ThirdBox = "WED" If GUICtrlRead($FourthBox) = 1 Then $value_of_FourthBox = "THU" If GUICtrlRead($BoxFive) = 1 Then $value_of_BoxFive = "FRI" For $i = $value_of_FirstBox To $value_of_BoxFive If $i <> 4 Then $string = ($string & ", " & $i) Next MsgBox(0, "", $string) EndFunc Func __Exit() Exit EndFuncThe problem is that if I only pass on the values, I can get an output of " 1, 1, 1, 1 " but I want something like " MON, TUE, WED "Any help would be appreciated. I'm not sure of what I'm doing wrong. Link to comment Share on other sites More sharing options...
JohnOne Posted October 1, 2010 Share Posted October 1, 2010 I dont think autoit can count mon to fri, uless tou show it hoe via a function. If you create your checkbox controls in an array, you can loop through it that way. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
UEZ Posted October 1, 2010 Share Posted October 1, 2010 Your For Next loop make no sense this way. You have to use e.g. arrays to run through! But you can try this method without arrays: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIonEventMode", 1) $Form1 = GUICreate("Select Days of the Week", 146, 258, 201, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit") $FirstBox = GUICtrlCreateCheckbox("Monday", 32, 32, 97, 17) $SecondBox = GUICtrlCreateCheckbox("Tuesday", 32, 64, 97, 17) $ThirdBox = GUICtrlCreateCheckbox("Wednesday", 32, 96, 97, 17) $FourthBox = GUICtrlCreateCheckbox("Thursday", 32, 128, 97, 17) $BoxFive = GUICtrlCreateCheckbox("Friday", 32, 160, 97, 17) $Button1 = GUICtrlCreateButton("Weekdays", 32, 200, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_buttonpressed") Global $string GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(10) WEnd Func _buttonpressed() Local $string If GUICtrlRead($FirstBox) = 1 Then $string &= "MON, " If GUICtrlRead($SecondBox) = 1 Then $string &= "TUE, " If GUICtrlRead($ThirdBox) = 1 Then $string &= "WED, " If GUICtrlRead($FourthBox) = 1 Then $string &= "THU, " If GUICtrlRead($BoxFive) = 1 Then $string &= "FRI, " $string = StringMid($string, 1, StringLen($string) - 2) MsgBox(0, "", $string) EndFunc Func __Exit() Exit EndFunc Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
sliceofpie Posted October 1, 2010 Author Share Posted October 1, 2010 (edited) Thank you UEZ for the method of use.Just so I understand how to use it with arrays, if I were to do it that way, how would I be able to get the same result? Here's as far as I've gotten with it:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIonEventMode", 1) Global $CheckBox[5] $Form1 = GUICreate("Select Days of the Week", 146, 258, 201, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit") $CheckBox[0] = GUICtrlCreateCheckbox("Monday", 32, 32, 97, 17) $CheckBox[1] = GUICtrlCreateCheckbox("Tuesday", 32, 64, 97, 17) $CheckBox[2] = GUICtrlCreateCheckbox("Wednesday", 32, 96, 97, 17) $CheckBox[3] = GUICtrlCreateCheckbox("Thursday", 32, 128, 97, 17) $CheckBox[4] = GUICtrlCreateCheckbox("Friday", 32, 160, 97, 17) $Button1 = GUICtrlCreateButton("Weekdays", 32, 200, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_buttonpressed") Global $string GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(10) WEnd Func _buttonpressed() Local $value_of_CheckBox[5] If GUICtrlRead($CheckBox[0]) = 1 Then $value_of_CheckBox[0] = "MON" If GUICtrlRead($CheckBox[1]) = 1 Then $value_of_CheckBox[1] = "TUE" If GUICtrlRead($CheckBox[2]) = 1 Then $value_of_CheckBox[2] = "WED" If GUICtrlRead($CheckBox[3]) = 1 Then $value_of_CheckBox[3] = "THU" If GUICtrlRead($CheckBox[4]) = 1 Then $value_of_CheckBox[4] = "FRI" For $i = 0 to UBound($value_of_CheckBox[$i]) - 1 If GUICtrlRead($CheckBox[$i]) = 1 Then $string = ($string &= ", " &= $value_of_CheckBox[$i]) Next MsgBox(0, "", $string) EndFunc Func __Exit() Exit EndFunc Edited October 1, 2010 by sliceofpie Link to comment Share on other sites More sharing options...
UEZ Posted October 1, 2010 Share Posted October 1, 2010 (edited) This is the version with arrays. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Opt("GUIonEventMode", 1) $Form1 = GUICreate("Select Days of the Week", 146, 258, 201, 142) GUISetOnEvent($GUI_EVENT_CLOSE, "__Exit") Local $aDays[5][3] = [["Monday", "MON"], ["Tuesday", "TUE"], ["Wednesday", "WED"], ["Thursday", "THU"], ["Friday", "FRI"]] Local $y = 32 For $i = 0 To UBound($aDays) - 1 $aDays[$i][2] = GUICtrlCreateCheckbox($aDays[$i][0], 32, $y, 97, 17) $y += 32 Next $Button1 = GUICtrlCreateButton("Weekdays", 32, 200, 75, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_buttonpressed") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(10) WEnd Func _buttonpressed() Local $i, $string For $i = 0 To UBound($aDays) - 1 If GUICtrlRead($aDays[$i][2]) = 1 Then $string &= $aDays[$i][1] & ", " Next $string = StringMid($string, 1, StringLen($string) - 2) MsgBox(0, "", $string) EndFunc Func __Exit() Exit EndFunc Br, UEZ Edited October 1, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
sliceofpie Posted October 2, 2010 Author Share Posted October 2, 2010 UEZ,I see how arrays can make a difference. There are some great things you've included here. Danke fuer das liebvolle detail Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now