Jump to content

reading multiple Checkboxes


butcha
 Share

Recommended Posts

Hi there

yep it's my first post!

basically I'm trying to write a script that will allow me to check (tick) certain checkboxes (server names) then press a button which will copy files to the selected servers. I've managed so far to to do that but I would like to be able to pop a message up if no servers are selected when the "copy" button was clicked. All I can manage at the moment is the following.

if BitAND(GUICtrlRead($checkC1), $gui_unchecked) and BitAND(GUICtrlRead($checkC2), $gui_unchecked) and BitAND(GUICtrlRead($checkC3), $gui_unchecked) and BitAND(GUICtrlRead($checkC4), $gui_unchecked) and BitAND(GUICtrlRead($checkC5), $gui_unchecked) and BitAND(GUICtrlRead($checkC6), $gui_unchecked) and BitAND(GUICtrlRead($checkC7), $gui_unchecked) and BitAND(GUICtrlRead($checkC8), $gui_unchecked) Then
    MsgBox(4096, "Test", "no servers selected")
    Else
    MsgBox(4096, "Test", "copy files")
    EndIf

as you can see it's a long winded way so i would like to change it to a variable like $checkc[8] (number of check boxes)

hope this makes sense

I can post all my code if necessary

thanks

Edited by butcha
Link to comment
Share on other sites

What you could do is make your checkboxes a 1D array so you can loop through them. Just do a loop that checks each checkbox state that sets some boolean to true if it sees one that is checked. The boolean's default value before the start of the loop would be false, of course.

Link to comment
Share on other sites

Hi there

yep it's my first post!

basically I'm trying to write a script that will allow me to check (tick) certain checkboxes (server names) then press a button which will copy files to the selected servers. I've managed so far to to do that but I would like to be able to pop a message up if no servers are selected when the "copy" button was clicked. All I can manage at the moment is the following.

if BitAND(GUICtrlRead($checkC1), $gui_unchecked) and BitAND(GUICtrlRead($checkC2), $gui_unchecked) and BitAND(GUICtrlRead($checkC3), $gui_unchecked) and BitAND(GUICtrlRead($checkC4), $gui_unchecked) and BitAND(GUICtrlRead($checkC5), $gui_unchecked) and BitAND(GUICtrlRead($checkC6), $gui_unchecked) and BitAND(GUICtrlRead($checkC7), $gui_unchecked) and BitAND(GUICtrlRead($checkC8), $gui_unchecked) Then
    MsgBox(4096, "Test", "no servers selected")
    Else
    MsgBox(4096, "Test", "copy files")
    EndIf

as you can see it's a long winded way so i would like to change it to a variable like $checkc[8] (number of check boxes)

hope this makes sense

I can post all my code if necessary

thanks

Good first post, and welcome to AutoIt.

You should have all your checkbox control IDs in an array instead of separate variables. Then the check (or any thing else you need to do to them) can be done with a simple loop:

; $avCheck array contains all the checkbox control IDs
$fSelection = False
For $n = 0 To UBound($avCheck) - 1
    If BitAND(GUICtrlRead($avCheck[$n]), $GUI_CHECKED) Then
        $fSelection = True
        ExitLoop
    EndIf
Next
    
If $fSelection Then 
    MsgBox(4096, "Test", "copy files")
Else
    MsgBox(4096, "Test", "no servers selected")
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Good news!

Managed to change most of my script now to using variables after working out to declare variable ( for example "dim $checkbox[8]" )

and now working ok. still trying to understand the UBound command

I didnt find a way to change this command to variable but not sure if I spent long enough looking

does anyone no a better way to do it see code below

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
        if $answer = 6 then
            $status1 = GUICtrlRead($checkbox[0])
            $status2 = GUICtrlRead($checkbox[1])
            $status3 = GUICtrlRead($checkbox[2])
            $status4 = GUICtrlRead($checkbox[3])
            $status5 = GUICtrlRead($checkbox[4])
            $status6 = GUICtrlRead($checkbox[5])
            $status7 = GUICtrlRead($checkbox[6])
            $status8 = GUICtrlRead($checkbox[7])

            If $status1 = 1 then call ("o1copy")
            If $status2 = 1 then call ("o2copy")
            If $status3 = 1 then call ("o3copy")
            If $status4 = 1 then call ("o4copy")
            If $status5 = 1 then call ("o5copy")
            If $status6 = 1 then call ("o6copy")
        endif
        if $answer = 7 Then
        EndIf

second thoughts i'll post the whole script might be easier to determine what I am trying to do!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=H:\Autoit\Forms\epack.kxf
$Form1 = GUICreate("E-Pack Copy for Citrix", 223, 295, 192, 133)
GUISetIcon("H:\Misc\mblogo.ico")
$Label1 = GUICtrlCreateLabel("Select the servers to", 8, 8, 146, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("copy the E-Pack files to:", 8, 25, 171, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Select All", 128, 80, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Select all Citrix servers")
$Button2 = GUICtrlCreateButton("Clear All", 128, 112, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Clear all selected Citrix servers")
$Button3 = GUICtrlCreateButton("Copy Files", 128, 176, 89, 65, $WS_GROUP)
GUICtrlSetTip(-1, "Copy EPack files to the selected servers")
$Button4 = GUICtrlCreateButton("Exit", 128, 144, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "User Acceptance Testing Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Development Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
$Progress1 = GUICtrlCreateProgress(8, 256, 201, 25)
$Button5 = GUICtrlCreateButton("Please Read", 128, 48, 89, 25, $WS_GROUP)
$Label3 = GUICtrlCreateLabel("Copy Progress. . .", 8, 240, 87, 17)
dim $checkbox[8]
$checkbox[0] = GUICtrlCreateCheckbox("LonCtxPS1", 8, 48, 81, 17)
$checkbox[1] = GUICtrlCreateCheckbox("LonCtxPS2", 8, 72, 81, 17)
$checkbox[2] = GUICtrlCreateCheckbox("LonCtxPS3", 8, 96, 81, 17)
$checkbox[3] = GUICtrlCreateCheckbox("LonCtxPS4", 8, 120, 81, 17)
$checkbox[4] = GUICtrlCreateCheckbox("PetCtxPS1", 8, 144, 81, 17)
$checkbox[5] = GUICtrlCreateCheckbox("PetCtxPS2", 8, 168, 81, 17)
$checkbox[6] = GUICtrlCreateCheckbox("UATCtxPS1", 8, 192, 81, 17)
$checkbox[7] = GUICtrlCreateCheckbox("DEVCtxPS1", 8, 216, 81, 17)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()

Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
        Case $nMsg = $Button1   ;Check All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_CHECKED )
            Next

        case $nmsg = $Button2   ;Clear All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_UNCHECKED )
            Next

        case $nmsg = $Button3   ;Copy Files

$fSelection = False
For $n = 0 To UBound($checkbox) - 1
    If BitAND(GUICtrlRead($checkbox[$n]), $GUI_CHECKED) Then
        $fSelection = True
        ExitLoop
    EndIf
Next

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
        if $answer = 6 then
            $status1 = GUICtrlRead($checkbox[0])
            $status2 = GUICtrlRead($checkbox[1])
            $status3 = GUICtrlRead($checkbox[2])
            $status4 = GUICtrlRead($checkbox[3])
            $status5 = GUICtrlRead($checkbox[4])
            $status6 = GUICtrlRead($checkbox[5])
            $status7 = GUICtrlRead($checkbox[6])
            $status8 = GUICtrlRead($checkbox[7])

            If $status1 = 1 then call ("o1copy")
            If $status2 = 1 then call ("o2copy")
            If $status3 = 1 then call ("o3copy")
            If $status4 = 1 then call ("o4copy")
            If $status5 = 1 then call ("o5copy")
            If $status6 = 1 then call ("o6copy")
        endif
        if $answer = 7 Then
        EndIf
Else
    MsgBox(48, 'No Items Selected', 'You have not selected any Citrix servers to copy E-Pack files to, Please select from the list')
EndIf

                case $nmsg = $Button4
        Exit

        case $nmsg = $Button5
            MsgBox(64, 'Please Read. . .', '1. You need to be logged in with your admin account on the network.' & @CRLF & @CRLF & '2. Epack Files need to be located in'& @CRLF & '    \\ad.saffery.net\saffery\IT\Rollout\Software\CaseWare\Updates')

EndSelect

WEnd

;Functions for copying files
Func o1copy()
    DirCopy("C:\Temp\test\1", "C:\Temp\end", 1)
EndFunc

Func o2copy()
    DirCopy("C:\Temp\test\2", "C:\Temp\end", 1)
EndFunc

Func o3copy()
    DirCopy("C:\Temp\test\3", "C:\Temp\end", 1)
EndFunc

Func o4copy()
    DirCopy("C:\Temp\test\4", "C:\Temp\end", 1)
EndFunc

Func o5copy()
    DirCopy("C:\Temp\test\5", "C:\Temp\end", 1)
EndFunc

Func o6copy()
    DirCopy("C:\Temp\test\6", "C:\Temp\end", 1)
EndFunc
Link to comment
Share on other sites

Good news!

Managed to change most of my script now to using variables after working out to declare variable ( for example "dim $checkbox[8]" )

and now working ok. still trying to understand the UBound command

I didnt find a way to change this command to variable but not sure if I spent long enough looking

does anyone no a better way to do it see code below

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
        if $answer = 6 then
            $status1 = GUICtrlRead($checkbox[0])
            $status2 = GUICtrlRead($checkbox[1])
            $status3 = GUICtrlRead($checkbox[2])
            $status4 = GUICtrlRead($checkbox[3])
            $status5 = GUICtrlRead($checkbox[4])
            $status6 = GUICtrlRead($checkbox[5])
            $status7 = GUICtrlRead($checkbox[6])
            $status8 = GUICtrlRead($checkbox[7])

            If $status1 = 1 then call ("o1copy")
            If $status2 = 1 then call ("o2copy")
            If $status3 = 1 then call ("o3copy")
            If $status4 = 1 then call ("o4copy")
            If $status5 = 1 then call ("o5copy")
            If $status6 = 1 then call ("o6copy")
        endif
        if $answer = 7 Then
        EndIf

second thoughts i'll post the whole script might be easier to determine what I am trying to do!

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=H:\Autoit\Forms\epack.kxf
$Form1 = GUICreate("E-Pack Copy for Citrix", 223, 295, 192, 133)
GUISetIcon("H:\Misc\mblogo.ico")
$Label1 = GUICtrlCreateLabel("Select the servers to", 8, 8, 146, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("copy the E-Pack files to:", 8, 25, 171, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Select All", 128, 80, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Select all Citrix servers")
$Button2 = GUICtrlCreateButton("Clear All", 128, 112, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Clear all selected Citrix servers")
$Button3 = GUICtrlCreateButton("Copy Files", 128, 176, 89, 65, $WS_GROUP)
GUICtrlSetTip(-1, "Copy EPack files to the selected servers")
$Button4 = GUICtrlCreateButton("Exit", 128, 144, 89, 25, $WS_GROUP)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Live Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "DR Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "User Acceptance Testing Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
GUICtrlSetTip(-1, "Development Citrix Presentation Server")
GUICtrlSetCursor (-1, 0)
$Progress1 = GUICtrlCreateProgress(8, 256, 201, 25)
$Button5 = GUICtrlCreateButton("Please Read", 128, 48, 89, 25, $WS_GROUP)
$Label3 = GUICtrlCreateLabel("Copy Progress. . .", 8, 240, 87, 17)
dim $checkbox[8]
$checkbox[0] = GUICtrlCreateCheckbox("LonCtxPS1", 8, 48, 81, 17)
$checkbox[1] = GUICtrlCreateCheckbox("LonCtxPS2", 8, 72, 81, 17)
$checkbox[2] = GUICtrlCreateCheckbox("LonCtxPS3", 8, 96, 81, 17)
$checkbox[3] = GUICtrlCreateCheckbox("LonCtxPS4", 8, 120, 81, 17)
$checkbox[4] = GUICtrlCreateCheckbox("PetCtxPS1", 8, 144, 81, 17)
$checkbox[5] = GUICtrlCreateCheckbox("PetCtxPS2", 8, 168, 81, 17)
$checkbox[6] = GUICtrlCreateCheckbox("UATCtxPS1", 8, 192, 81, 17)
$checkbox[7] = GUICtrlCreateCheckbox("DEVCtxPS1", 8, 216, 81, 17)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()

Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
        Case $nMsg = $Button1   ;Check All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_CHECKED )
            Next

        case $nmsg = $Button2   ;Clear All
            For $n = 0 To UBound($checkbox) - 1
            ;For $n = 0 To 7 Step 1
                GUICtrlSetState ( $checkbox[$n] , $GUI_UNCHECKED )
            Next

        case $nmsg = $Button3   ;Copy Files

$fSelection = False
For $n = 0 To UBound($checkbox) - 1
    If BitAND(GUICtrlRead($checkbox[$n]), $GUI_CHECKED) Then
        $fSelection = True
        ExitLoop
    EndIf
Next

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
        if $answer = 6 then
            $status1 = GUICtrlRead($checkbox[0])
            $status2 = GUICtrlRead($checkbox[1])
            $status3 = GUICtrlRead($checkbox[2])
            $status4 = GUICtrlRead($checkbox[3])
            $status5 = GUICtrlRead($checkbox[4])
            $status6 = GUICtrlRead($checkbox[5])
            $status7 = GUICtrlRead($checkbox[6])
            $status8 = GUICtrlRead($checkbox[7])

            If $status1 = 1 then call ("o1copy")
            If $status2 = 1 then call ("o2copy")
            If $status3 = 1 then call ("o3copy")
            If $status4 = 1 then call ("o4copy")
            If $status5 = 1 then call ("o5copy")
            If $status6 = 1 then call ("o6copy")
        endif
        if $answer = 7 Then
        EndIf
Else
    MsgBox(48, 'No Items Selected', 'You have not selected any Citrix servers to copy E-Pack files to, Please select from the list')
EndIf

                case $nmsg = $Button4
        Exit

        case $nmsg = $Button5
            MsgBox(64, 'Please Read. . .', '1. You need to be logged in with your admin account on the network.' & @CRLF & @CRLF & '2. Epack Files need to be located in'& @CRLF & '    \\ad.saffery.net\saffery\IT\Rollout\Software\CaseWare\Updates')

EndSelect

WEnd

;Functions for copying files
Func o1copy()
    DirCopy("C:\Temp\test\1", "C:\Temp\end", 1)
EndFunc

Func o2copy()
    DirCopy("C:\Temp\test\2", "C:\Temp\end", 1)
EndFunc

Func o3copy()
    DirCopy("C:\Temp\test\3", "C:\Temp\end", 1)
EndFunc

Func o4copy()
    DirCopy("C:\Temp\test\4", "C:\Temp\end", 1)
EndFunc

Func o5copy()
    DirCopy("C:\Temp\test\5", "C:\Temp\end", 1)
EndFunc

Func o6copy()
    DirCopy("C:\Temp\test\6", "C:\Temp\end", 1)
EndFunc

Hi,

suggestions for 1st part and a bit of 2nd:

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
    if $answer = 6 then
        For $i = 0 To UBound ($checkbox) - 1
            Assign ("status" & $i + 1, GUICtrlRead($checkbox[$i])
        Next
        
        For $i = 1 to UBound ($checkbox)    
            If Eval ("status" & $i) = 1 Then
                ;Call ("o" & $i & "copy") ; if you want to call the functions directly, remove ; before the call and comment or delete the following DirCopy statement
                DirCopy("C:\Temp\test\" & $i, "C:\Temp\end", 1) ; if you need only the DirCopy 
            EndIf
        Next
    EndIf
    if $answer = 7 Then      
    EndIf

The UBound function is pretty well explained in help file!

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

  • 8 years later...

Hey Guys,

Thoroughly appreciated this thread - has helped me a lot in GUI/checkbox for/ubounds etc.

I have one question, is there a way to count how many check boxes are ticked?

Would the best way be inserting a $count = $count + 1 after the eval funtion? (using the above code as an example)

If $fSelection Then
    $answer = msgBox(36, 'Copy Files to Citrix servers', 'Are you sure you want to copy E-Packs files to the selected servers?')
    if $answer = 6 then
        For $i = 0 To UBound ($checkbox) - 1
            Assign ("status" & $i + 1, GUICtrlRead($checkbox[$i])
        Next
        count = 0 ; resetting count
        For $i = 1 to UBound ($checkbox)    
            If Eval ("status" & $i) = 1 Then
            $count = $count + 1 ; counting how many are checked
                ;Call ("o" & $i & "copy") ; if you want to call the functions directly, remove ; before the call and comment or delete the following DirCopy statement
                DirCopy("C:\Temp\test\" & $i, "C:\Temp\end", 1) ; if you need only the DirCopy 
            EndIf
        Next
    EndIf
    if $answer = 7 Then      
    EndIf

 

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...