Jump to content

Can someone give me a quick pointer on Checkboxes?


Recommended Posts

I am building a script that will allow an SMS Administrator to enable logging on all of the SMS Executive Threads - of which there are 36 of them. I just picked up AutoIt3 yesterday, so I am quite the AutoIt newbie, although I've been doing OK with KiX for a while.

I am able to create a simple GUI layour with a checkbox for each service, and a checkbox at the bottom to enable ALL services, but I can't figure out how to poll the status of the ALL services checkbox and make it select all the other checkboxes if it becomes checked. Does that make sense?

I have a GUI with 36 individual services listed, and at the bottom, an additional checkbox that I would like to be able to check, and have it check all the others. Similarly, uncheck it, and have it uncheck all the others.

If someone could give me a short piece of code that would work for this, that would be great, or point me to an example script somewhere and I will learn from that.

Thanks!

Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $CheckBox[6]
$CheckBox[0] = 5
$Checkbox[1] = GuiCtrlCreateCheckbox("Checkbox1", 50, 40, 1, 1)
$Checkbox[2] = GuiCtrlCreateCheckbox("Checkbox2", 30, 20, 140, 20)
$Checkbox[3] = GuiCtrlCreateCheckbox("Checkbox3", 30, 50, 140, 20)
$Checkbox[4] = GuiCtrlCreateCheckbox("Checkbox4", 30, 80, 140, 20)
$Checkbox[5] = GuiCtrlCreateCheckbox("Checkbox5", 30, 110, 140, 20)
$Checkbox_All = GuiCtrlCreateCheckbox("Check/Uncheck All", 30, 140, 140, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Checkbox_All
        $check_state = GUICtrlRead($CheckBox_All)
        for $i = 1 To $CheckBox[0]
            GUICtrlSetState($CheckBox[$i],$check_state)
        Next
    EndSelect
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $CheckBox[6]
$CheckBox[0] = 5
$Checkbox[1] = GuiCtrlCreateCheckbox("Checkbox1", 50, 40, 1, 1)
$Checkbox[2] = GuiCtrlCreateCheckbox("Checkbox2", 30, 20, 140, 20)
$Checkbox[3] = GuiCtrlCreateCheckbox("Checkbox3", 30, 50, 140, 20)
$Checkbox[4] = GuiCtrlCreateCheckbox("Checkbox4", 30, 80, 140, 20)
$Checkbox[5] = GuiCtrlCreateCheckbox("Checkbox5", 30, 110, 140, 20)
$Checkbox_All = GuiCtrlCreateCheckbox("Check/Uncheck All", 30, 140, 140, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Checkbox_All
        $check_state = GUICtrlRead($CheckBox_All)
        for $i = 1 To $CheckBox[0]
            GUICtrlSetState($CheckBox[$i],$check_state)
        Next
    EndSelect
WEnd

<{POST_SNAPBACK}>

Thanks a million! That worked perfectly.
Link to comment
Share on other sites

Thanks a million! That worked perfectly.

<{POST_SNAPBACK}>

OK - I have another question: Is there any way to get the value of the text displayed per checkbox?

For Instance:

$checkbox[31] = GUICtrlCreateCheckbox ("SMS_WINNT_SERVER_DISCOVERY_AGENT", 10, 610, 250, 20)

Is there a way to get the text read into a string?

Thanks

Link to comment
Share on other sites

OK - I have another question: Is there any way to get the value of the text displayed per checkbox?

For Instance:

$checkbox[31] = GUICtrlCreateCheckbox ("SMS_WINNT_SERVER_DISCOVERY_AGENT", 10, 610, 250, 20)

Is there a way to get the text read into a string?

Thanks

<{POST_SNAPBACK}>

...or do I have to add 30 lines of code to define them all and then create the checkboxes using the string?
Link to comment
Share on other sites

#include <GuiConstants.au3>

GuiCreate("MyGUI", 392, 323)
Dim $CheckBox[6], $Data[6]
$CheckBox[0] = 5
$Checkbox[1] = GuiCtrlCreateCheckbox("Checkbox1", 50, 40, 1, 1)
$Checkbox[2] = GuiCtrlCreateCheckbox("Checkbox2", 30, 20, 140, 20)
$Checkbox[3] = GuiCtrlCreateCheckbox("Checkbox3", 30, 50, 140, 20)
$Checkbox[4] = GuiCtrlCreateCheckbox("Checkbox4", 30, 80, 140, 20)
$Checkbox[5] = GuiCtrlCreateCheckbox("Checkbox5", 30, 110, 140, 20)
$Checkbox_All = GuiCtrlCreateCheckbox("Check/Uncheck All", 30, 140, 140, 20)
$Button_1 = GUICtrlCreateButton("Next >", 330, 270, 40, 30)
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Checkbox_All
        $check_state = GUICtrlRead($CheckBox_All)
        for $i = 1 To $CheckBox[0]
            GUICtrlSetState($CheckBox[$i],$check_state)
        Next
    Case $msg = $Button_1
        for $i = 1 To $CheckBox[0]
        $result = GUICtrlRead($CheckBox[$i], 1)
        $Data[$i] = $result[0]
        MsgBox(0,"Checkbox text", "CheckBox #" & $i & "  Text = " & $data[$i]) 
        Next
    EndSelect
WEnd

Edited by Valuater

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...