Jump to content
Sign in to follow this  
Sublime

Buttons

Recommended Posts

Sublime

O_o this may sound strange but here we go:

how do you set a button up to get the state of say 20 or so checkboxes than perform the actions for each.

Here they are if you were wondering:

$Checkbox_5 = GuiCtrlCreateCheckbox("A", 10, 90, 30, 20)
$Checkbox_6 = GuiCtrlCreateCheckbox("B", 10, 110, 30, 20)
$Checkbox_7 = GuiCtrlCreateCheckbox("C", 10, 130, 30, 20)
$Checkbox_8 = GuiCtrlCreateCheckbox("D", 10, 150, 30, 20)
$Checkbox_9 = GuiCtrlCreateCheckbox("E", 10, 170, 30, 20)
$Checkbox_10 = GuiCtrlCreateCheckbox("F", 10, 190, 30, 20)
$Checkbox_11 = GuiCtrlCreateCheckbox("F", 10, 210, 30, 20)
$Checkbox_12 = GuiCtrlCreateCheckbox("G", 10, 230, 30, 20)
$Checkbox_13 = GuiCtrlCreateCheckbox("H", 10, 250, 30, 20)
$Checkbox_14 = GuiCtrlCreateCheckbox("I", 10, 270, 30, 20)
$Checkbox_15 = GuiCtrlCreateCheckbox("J", 10, 290, 30, 20)
$Checkbox_16 = GuiCtrlCreateCheckbox("K", 140, 90, 30, 20)
$Checkbox_17 = GuiCtrlCreateCheckbox("L", 140, 110, 30, 20)
$Checkbox_18 = GuiCtrlCreateCheckbox("M", 140, 130, 30, 20)
$Checkbox_19 = GuiCtrlCreateCheckbox("N", 140, 150, 30, 20)
$Checkbox_20 = GuiCtrlCreateCheckbox("O", 140, 170, 30, 20)
$Checkbox_21 = GuiCtrlCreateCheckbox("P", 140, 190, 30, 20)
$Checkbox_23 = GuiCtrlCreateCheckbox("R", 140, 210, 30, 20)
$Checkbox_24 = GuiCtrlCreateCheckbox("S", 140, 230, 30, 20)
$Checkbox_25 = GuiCtrlCreateCheckbox("T", 140, 250, 30, 20)
$Checkbox_26 = GuiCtrlCreateCheckbox("U", 140, 270, 30, 20)
$Checkbox_27 = GuiCtrlCreateCheckbox("V", 140, 290, 30, 20)
$Checkbox_28 = GuiCtrlCreateCheckbox("W", 270, 90, 30, 20)
$Checkbox_29 = GuiCtrlCreateCheckbox("X", 270, 110, 30, 20)

Share this post


Link to post
Share on other sites
greenmachine

I'll assume by "state" of the checkbox you mean whether it is checked or not.

For your code exactly how it is, this should work:

$msg = ""
For $i = 5 to 29
    $msg &= "Checkbox " & $i & " state: " & GUICtrlRead (Eval ("Checkbox_" & $i)) & @CRLF
Next
MsgBox (0, "State - 1 is checked, 4 is unchecked", $msg)

Uses beta for &=, change to $msg = $msg & ... for production.

You could also turn the checkbox vars into an array and make accessing them simpler.

Edit - this is how to check the state of each one. To attach it to a button, put it in the GUIGetMsg() loop (if you have one), or set a GUI Event to point to that function. In order to do something if a certain checkbox is checked, just use if statements where applicable.

Edited by greenmachine

Share this post


Link to post
Share on other sites
SmOke_N

O_o this may sound strange but here we go:

how do you set a button up to get the state of say 20 or so checkboxes than perform the actions for each.

Here they are if you were wondering:

$Checkbox_5 = GuiCtrlCreateCheckbox("A", 10, 90, 30, 20)
$Checkbox_6 = GuiCtrlCreateCheckbox("B", 10, 110, 30, 20)
$Checkbox_7 = GuiCtrlCreateCheckbox("C", 10, 130, 30, 20)
$Checkbox_8 = GuiCtrlCreateCheckbox("D", 10, 150, 30, 20)
$Checkbox_9 = GuiCtrlCreateCheckbox("E", 10, 170, 30, 20)
$Checkbox_10 = GuiCtrlCreateCheckbox("F", 10, 190, 30, 20)
$Checkbox_11 = GuiCtrlCreateCheckbox("F", 10, 210, 30, 20)
$Checkbox_12 = GuiCtrlCreateCheckbox("G", 10, 230, 30, 20)
$Checkbox_13 = GuiCtrlCreateCheckbox("H", 10, 250, 30, 20)
$Checkbox_14 = GuiCtrlCreateCheckbox("I", 10, 270, 30, 20)
$Checkbox_15 = GuiCtrlCreateCheckbox("J", 10, 290, 30, 20)
$Checkbox_16 = GuiCtrlCreateCheckbox("K", 140, 90, 30, 20)
$Checkbox_17 = GuiCtrlCreateCheckbox("L", 140, 110, 30, 20)
$Checkbox_18 = GuiCtrlCreateCheckbox("M", 140, 130, 30, 20)
$Checkbox_19 = GuiCtrlCreateCheckbox("N", 140, 150, 30, 20)
$Checkbox_20 = GuiCtrlCreateCheckbox("O", 140, 170, 30, 20)
$Checkbox_21 = GuiCtrlCreateCheckbox("P", 140, 190, 30, 20)
$Checkbox_23 = GuiCtrlCreateCheckbox("R", 140, 210, 30, 20)
$Checkbox_24 = GuiCtrlCreateCheckbox("S", 140, 230, 30, 20)
$Checkbox_25 = GuiCtrlCreateCheckbox("T", 140, 250, 30, 20)
$Checkbox_26 = GuiCtrlCreateCheckbox("U", 140, 270, 30, 20)
$Checkbox_27 = GuiCtrlCreateCheckbox("V", 140, 290, 30, 20)
$Checkbox_28 = GuiCtrlCreateCheckbox("W", 270, 90, 30, 20)
$Checkbox_29 = GuiCtrlCreateCheckbox("X", 270, 110, 30, 20)
Your code could be more efficient if you used loops for creating large scopes like this:
#include <GUIConstants.au3
; == GUI generated with Koda ==);
Dim $Checkbox[30]
$Main = GUICreate("", 405, 400)
For $i = 1 To 24
    If $i < 12 Then
        $Checkbox[$i + 4] = GuiCtrlCreateCheckbox(Chr(64 + $i), 10, 70 + ($i * 20), 30, 20)
    ElseIf $i < 23 Then
        $Checkbox[$i + 4] = GuiCtrlCreateCheckbox(Chr(64 + $i), 140, 70 + (($i - 11) * 20), 30, 20)
    ElseIf $i > 22 Then
        $Checkbox[$i + 4] = GuiCtrlCreateCheckbox(Chr(64 + $i), 270, 70 + (($i - 22) * 20), 30, 20)
    EndIf
Next


GUISetState()
While GUIGetMsg() <> - 3
    Sleep(10)
WEnd

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.