Lakes Posted July 29, 2012 Share Posted July 29, 2012 I need to reverse the sequence of checkboxes so they align with the number sequence. Run the script and you will see what is wrong... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $Checkbox[8] Global $Check[8] $Title = GUICreate("CheckBox Test", 234, 155, 191, 125) $Numbers = GUICtrlCreateLabel("128 64 32 16 8 4 2 0", 26, 36, 173, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Checkbox[0] = GUICtrlCreateCheckbox("", 33, 54, 17, 17) $Checkbox[1] = GUICtrlCreateCheckbox("", 55, 54, 17, 17) $Checkbox[2] = GUICtrlCreateCheckbox("", 77, 54, 17, 17) $Checkbox[3] = GUICtrlCreateCheckbox("", 99, 54, 17, 17) $Checkbox[4] = GUICtrlCreateCheckbox("", 121, 54, 17, 17) $Checkbox[5] = GUICtrlCreateCheckbox("", 143, 54, 17, 17) $Checkbox[6] = GUICtrlCreateCheckbox("", 165, 54, 17, 17) $Checkbox[7] = GUICtrlCreateCheckbox("", 187, 54, 17, 17) $UnCheckAll = GUICtrlCreateCheckbox("UnCheck", 17, 6, 17, 17) $UnCheck_label = GUICtrlCreateLabel("UnCheck All", 36, 8, 63, 17) $Number = GUICtrlCreateInput("Number", 20, 112, 195, 21) $BinLabel = GUICtrlCreateLabel(" 0 0 0 0 0 0 0 0", 31, 72, 168, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) Global $Num, $BinChar While 1 $msg = GUIGetMsg(0) Switch $msg Case $Checkbox[0] to $Checkbox[7] $Num =0 $x = $msg - $Checkbox[0] ConsoleWrite ("Debug: X = " &$x &@CRLF) If GUICtrlRead($Checkbox[$x]) = $GUI_CHECKED Then $Check[$x] = 1 Else $Check[$x] = 0 EndIf For $n = 0 to 7 If $Check[$n] = 1 then $Num = $Num + (2 ^ $n) $BinChar &= "1" EndIf Next ConsoleWrite("Number = " &$Num &@CRLF) $Num =0 Case $UncheckAll For $i = 7 To 0 step -1 GUICtrlSetState($CheckBox[$i], $GUI_UNCHECKED) Sleep(100) Next GUICtrlSetState($UncheckAll, $GUI_UNCHECKED) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Global $Checkbox[8] Global $Check[8] $Title = GUICreate("CheckBox Test", 234, 155, 191, 125) $Numbers = GUICtrlCreateLabel("128 64 32 16 8 4 2 0", 26, 36, 173, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $Checkbox[0] = GUICtrlCreateCheckbox("", 33, 54, 17, 17) $Checkbox[1] = GUICtrlCreateCheckbox("", 55, 54, 17, 17) $Checkbox[2] = GUICtrlCreateCheckbox("", 77, 54, 17, 17) $Checkbox[3] = GUICtrlCreateCheckbox("", 99, 54, 17, 17) $Checkbox[4] = GUICtrlCreateCheckbox("", 121, 54, 17, 17) $Checkbox[5] = GUICtrlCreateCheckbox("", 143, 54, 17, 17) $Checkbox[6] = GUICtrlCreateCheckbox("", 165, 54, 17, 17) $Checkbox[7] = GUICtrlCreateCheckbox("", 187, 54, 17, 17) $UnCheckAll = GUICtrlCreateCheckbox("UnCheck", 17, 6, 17, 17) $UnCheck_label = GUICtrlCreateLabel("UnCheck All", 36, 8, 63, 17) $Number = GUICtrlCreateInput("Number", 20, 112, 195, 21) $BinLabel = GUICtrlCreateLabel(" 0 0 0 0 0 0 0 0", 31, 72, 168, 20, $SS_CENTER) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) Global $Num, $BinChar While 1 $msg = GUIGetMsg(0) Switch $msg Case $Checkbox[0] to $Checkbox[7] $Num =0 $x = $msg - $Checkbox[0] ConsoleWrite ("Debug: X = " &$x &@CRLF) If GUICtrlRead($Checkbox[$x]) = $GUI_CHECKED Then $Check[$x] = 1 Else $Check[$x] = 0 EndIf For $n = 0 to 7 If $Check[$n] = 1 then $Num = $Num + (2 ^ $n) $BinChar &= "1" EndIf Next ConsoleWrite("Number = " &$Num &@CRLF) $Num =0 Case $UncheckAll For $i = 7 To 0 step -1 GUICtrlSetState($CheckBox[$i], $GUI_UNCHECKED) Sleep(100) Next GUICtrlSetState($UncheckAll, $GUI_UNCHECKED) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd 2015 - Still no flying cars, instead blankets with sleeves. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 29, 2012 Moderators Share Posted July 29, 2012 Lakes, Just reverse the order in which you create them: expandcollapse popup#include <GUIConstantsEx.au3> Global $Checkbox[8] Global $Check[8] Global $aNumbers[8] = ["128", " 64", " 32", " 16", " 8", " 4", " 2", " 1"] Global $aBits[8] = ["0", "0", "0", "0", "0", "0", "0", "0"] Global $Num, $BinChar $Title = GUICreate("CheckBox Test", 234, 155, 191, 125) For $i = 0 To 7 GUICtrlCreateLabel($aNumbers[$i], 30 + (22 * $i), 34, 20, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlCreateLabel($aBits[$i], 35 + (22 * $i), 74, 20, 20) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") Next For $i = 0 To 7 $Checkbox[$i] = GUICtrlCreateCheckbox("", 187 - (22 * $i), 54, 17, 17) Next $UnCheckAll = GUICtrlCreateCheckbox("UnCheck All", 17, 6, 117, 17) $Number = GUICtrlCreateInput("Number", 20, 112, 195, 21) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg(0) Switch $msg Case $Checkbox[0] To $Checkbox[7] $Num = 0 $x = $msg - $Checkbox[0] ConsoleWrite("Debug: X = " & $x & @CRLF) If GUICtrlRead($Checkbox[$x]) = $GUI_CHECKED Then $Check[$x] = 1 Else $Check[$x] = 0 EndIf For $n = 0 To 7 If $Check[$n] = 1 Then $Num = $Num + (2 ^ $n) $BinChar &= "1" EndIf Next ConsoleWrite("Number = " & $Num & @CRLF) $Num = 0 Case $UnCheckAll For $i = 0 To 7 GUICtrlSetState($Checkbox[$i], $GUI_UNCHECKED) Sleep(100) Next GUICtrlSetState($UnCheckAll, $GUI_UNCHECKED) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I have also used loops to create the labels - looks a lot neater that way. All clear? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Lakes Posted July 29, 2012 Author Share Posted July 29, 2012 (edited) Yup, I tried that, and I see what I was doing wrong now..... your way is neater though #cs Wrong! $Checkbox[7] = GUICtrlCreateCheckbox("", 33, 54, 17, 17) $Checkbox[6] = GUICtrlCreateCheckbox("", 55, 54, 17, 17) $Checkbox[5] = GUICtrlCreateCheckbox("", 77, 54, 17, 17) $Checkbox[4] = GUICtrlCreateCheckbox("", 99, 54, 17, 17) $Checkbox[3] = GUICtrlCreateCheckbox("", 121, 54, 17, 17) $Checkbox[2] = GUICtrlCreateCheckbox("", 143, 54, 17, 17) $Checkbox[1] = GUICtrlCreateCheckbox("", 165, 54, 17, 17) $Checkbox[0] = GUICtrlCreateCheckbox("", 187, 54, 17, 17) #ce $Checkbox[0] = GUICtrlCreateCheckbox("", 187, 54, 17, 17) $Checkbox[1] = GUICtrlCreateCheckbox("", 165, 54, 17, 17) $Checkbox[2] = GUICtrlCreateCheckbox("", 143, 54, 17, 17) $Checkbox[3] = GUICtrlCreateCheckbox("", 121, 54, 17, 17) $Checkbox[4] = GUICtrlCreateCheckbox("", 99, 54, 17, 17) $Checkbox[5] = GUICtrlCreateCheckbox("", 77, 54, 17, 17) $Checkbox[6] = GUICtrlCreateCheckbox("", 55, 54, 17, 17) $Checkbox[7] = GUICtrlCreateCheckbox("", 33, 54, 17, 17) Thanks! Edited July 29, 2012 by Lakes 2015 - Still no flying cars, instead blankets with sleeves. 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