Sign in to follow this  
Followers 0
twinches

executing actions for multipule checkboxes

3 posts in this topic

I'm very new to scripting and autoit and I was hoping to get some help here.

I'm trying to make a GUI with a list of checkboxes. So far If box 1 and 2 are checked, it will process the command for each box. If just box 1 is checked, it also works. However if I just check Box 2, it will not do anything. How can I get it to work if only box 2 is checked?

thanks for your help.

#include <GUIConstants.au3>

GUICreate("My GUI Checkbox")  ; will create a dialog box that when displayed is centered

$Server1 = GUICtrlCreateCheckbox ("Server 1", 10, 10, 120, 20)
$Server2 = GUICtrlCreateCheckbox ("Server 2", 10, 30, 120, 20)
$btn = GUICtrlCreateButton( "Test", 100, 100, 100, 20)
GUISetState ()       ; will display an  dialog box with 1 checkbox


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    
    If $msg = $btn Then
        
$User = InputBox("Logon", "Enter User Name:","","")
if @error = 1 Then Exit
;Asks the user to enter a password.  
$passwd = InputBox("Logon", "Enter your password.", "", "*")
if @error = 1 Then Exit

        If BitAND(GUICtrlRead($Server1), $GUI_CHECKED) = $GUI_CHECKED Then
            Run ("mstsc.exe /public /v:ddcmsctxp02")    
        
        If BitAND(GUICtrlRead($Server2), $GUI_CHECKED) = $GUI_CHECKED Then
            Run ("mstsc.exe /public /v:ddcmsctxp03")    
        EndIf
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
Wend

Share this post


Link to post
Share on other sites



twinches,

Welcome to the AutoIt forum. ;)

Here is one way to do it - although there are many others: ;)

#include <GUIConstants.au3>

GUICreate("My GUI Checkbox") ; will create a dialog box that when displayed is centered

$Server1 = GUICtrlCreateCheckbox("Server 1", 10, 10, 120, 20)
$Server2 = GUICtrlCreateCheckbox("Server 2", 10, 30, 120, 20)
$btn = GUICtrlCreateButton("Test", 100, 100, 100, 20)
GUISetState() ; will display an  dialog box with 1 checkbox

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()

    If $msg = $btn Then

        $User = InputBox("Logon", "Enter User Name:", "", "")
        If @error = 1 Then Exit
        ;Asks the user to enter a password.
        $passwd = InputBox("Logon", "Enter your password.", "", "*")
        If @error = 1 Then Exit


        If BitAND(GUICtrlRead($Server1), $GUI_CHECKED) = $GUI_CHECKED Then
            If BitAND(GUICtrlRead($Server2), $GUI_CHECKED) = $GUI_CHECKED Then
                MsgBox(0, "", "Both checked!")
            Else
                MsgBox(0, "", "Box 1 checked")
            EndIf
        Else
            If BitAND(GUICtrlRead($Server2), $GUI_CHECKED) = $GUI_CHECKED Then
                MsgBox(0, "", "Box 2 checked!")
            EndIf
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

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

Thanks for the quick help. Yeah that is clear to me!

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