Jump to content

$GUI_Checked and $GUI_Unchecked


Recommended Posts

Hi, I need help with the following.

I am creating a script that displays a GUI for selection, I  want the user to have the option of pressing Yes/No to confirm whether he/she wants to select that checkbox, If he/she presses yes then select if they press No then unselect. and the unselect is what i am not able to get to work. Can someone help me finalize this?

#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <GUIConstantsEx.au3>
#include <GUIConstants.au3>

SelectComputer()

Func SelectComputer()
   Local $hGUI = GUICreate("Select Computer", 300, 300)
   Opt("GUICoordMode", 0) ;1=absolute, 0=relative, 2=cell
    Local $idCheckbox1 = GUICtrlCreateCheckbox("022", 10, 10)
    Local $idCheckbox2 = GUICtrlCreateCheckbox("023", -1, 25)
    Local $idCheckbox3 = GUICtrlCreateCheckbox("024", -1, 25)
    Local $idCheckbox4 = GUICtrlCreateCheckbox("025", -1, 25)
    Local $idCheckbox5 = GUICtrlCreateCheckbox("027", -1, 25)
    Local $idCheckbox6 = GUICtrlCreateCheckbox("080", -1, 25)
    Local $idCheckbox7 = GUICtrlCreateCheckbox("113", -1, 25)
    Local $idCheckbox8 = GUICtrlCreateCheckbox("114", -1, 25)
    Local $idCheckbox9 = GUICtrlCreateCheckbox("116", -1, 25)
    Local $idCheckbox10 = GUICtrlCreateCheckbox("119", -1, 25)
    Local $idButton_Insert = GUICtrlCreateButton("Done", 150, 10)
    Local $idButton_Close = GUICtrlCreateButton("Close", 50, 0)

   GUISetState(@SW_SHOW, $hGUI)

   While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop

            Case $idCheckbox1
                If _IsChecked($idCheckbox1) Then
                    MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        _IsUnChecked($idCheckbox1)
                        EndSelect
                     Else
                    EndIf
            Case $idCheckbox2
                If _IsChecked($idCheckbox2) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 023", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox3
                If _IsChecked($idCheckbox3) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 024", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox4
                If _IsChecked($idCheckbox4) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 025", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox5
                If _IsChecked($idCheckbox5) Then
                        MsgBox($MB_YESNO, "", "Do you want to run the procedure over 027", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox6
                If _IsChecked($idCheckbox6) Then
                        MsgBox($MB_YESNO, "", "Do you want to run the procedure over 080", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox7
                If _IsChecked($idCheckbox7) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 113", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox8
                If _IsChecked($idCheckbox8) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 114", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox9
                If _IsChecked($idCheckbox9) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 116", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf
            Case $idCheckbox10
                If _IsChecked($idCheckbox10) Then
                         MsgBox($MB_YESNO, "", "Do you want to run the procedure over 119", 0, $hGUI)
                    Select
                     Case MsgBox = 6 ;Yes
                        ;Run the procedure
                     Case MsgBox = 7 ;No
                        EndSelect
                     Else
                    ;If uncheck what should it do?
                    EndIf

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
 EndFunc   ;==>_IsChecked

 Func _IsUnChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_UNCHECKED
EndFunc   ;==>_IsUnChecked

 

Link to comment
Share on other sites

Link to comment
Share on other sites

Also have a look at whether or not your select statements are being triggered.  There is a lot of repetitive code that you could probably do with a function - but this is a snippet with a debug msgbox to see if the function is being triggered and then un-checking it if it is a "no":

$response=MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI)
                    if $response=6 then
                        ;Run the procedure
                    else
                        MsgBox(0,'','you selected no')
                        _IsUnChecked($idCheckbox1)
                    EndIf
                    
                    
;then I changed the other function to this:
 Func _IsUnChecked($idControlID)
    GUICtrlSetState($idControlID,$GUI_UNCHECKED)
EndFunc   ;==>_IsUnChecked

I didn't test this very much, but here is an example of reducing some of the code into a function:

While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idButton_Close
                ExitLoop
            Case $idCheckbox1
                _buttonResponse($idCheckbox1)
            Case $idCheckbox2
                _buttonResponse($idCheckbox2)
            Case $idCheckbox3
                _buttonResponse($idCheckbox3)
            Case $idCheckbox4
                _buttonResponse($idCheckbox4)
            Case $idCheckbox5
                _buttonResponse($idCheckbox5)
            Case $idCheckbox6
                _buttonResponse($idCheckbox6)
            Case $idCheckbox7
               _buttonResponse($idCheckbox7)
            Case $idCheckbox8
                _buttonResponse($idCheckbox8)
            Case $idCheckbox9
                _buttonResponse($idCheckbox9)
            Case $idCheckbox10
                _buttonResponse($idCheckbox10)
        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

func _buttonResponse($idControlID)
    If _IsChecked($idControlID) Then
        $response=MsgBox($MB_YESNO, "", "Do you want to run the procedure over 022", 0, $hGUI)
        if $response=6 then
           ;Run the procedure
        else
            MsgBox(0,'','you selected no')
            _IsUnChecked($idControlID)
        EndIf
    Else
        ;If uncheck what should it do?
    EndIf
EndFunc


Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
 EndFunc   ;==>_IsChecked

 Func _IsUnChecked($idControlID)
    GUICtrlSetState($idControlID,$GUI_UNCHECKED)
EndFunc   ;==>_IsUnChecked

 

Edited by Jfish

Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt

Link to comment
Share on other sites

If you really want to reduce redundancy, you could do something like :

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE, $idButton_Close
      ExitLoop
    Case $idCheckbox1 to $idCheckbox10
      _buttonResponse($nMsg)
  EndSwitch
Wend

 

Link to comment
Share on other sites

Hi,

 

Thanks it looks like though we are gonna go for a pull rather than using this push script. as we really want a single step install of our code base. So I am going to create a new post for that.

Thanks for all your efforts it really helped me get close to a solution although I didn't get to implement it due to the different direction the company wants me to work on.

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