Search the Community
Showing results for tags 'Binary to Number'.
-
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... #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