Sign in to follow this  
Followers 0
Lakes

Binary CheckBoxes

3 posts in this topic

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

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites



Lakes,

Just reverse the order in which you create them: ;)

#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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yup, I tried that, and I see what I was doing wrong now..... :oops::lmao: 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 by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0