Jump to content

Problems with menus and Checkboxes


 Share

Recommended Posts

Below is my code. I have run into a few problems.

1. When I take out all the stuff about Case $btnok, then the menu msgbox's work as they are supposed to, as well as the exit option under file. The way that it is now they will not work.

2. I managed to get it to where when you click on OK button and no check boxes are selected that it will MSgbox you telling you to select an option. However, when I applied the same principal to have it popup a msgbox if more than one was selected it doesn't work the way I want it to. It just msgbox's that "the selected script will now be run which is not what I want it to do.

3. If i'm wanting to have a "long list" of stuff happen for each option is it best to make that option its own .au3 then have it called via the button or is it wise to just leave it all in one script?

4. General script clean up advice as I'm sure it can be much better, "and I haven't even started on the "real meat" of this thing either."

Thanks in advance for any help in these matters >_<

#comments-start
    This script will launch a GUI asking what you want to do
    1. Login to CRM
    2. Close an open Case
    3. Close an alert
    4. Create a new case for MSS
    5. Exit
    
    Written by atnextc
    July 30th 2009
#comments-end

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

#Region ### START Koda GUI section ### Form=C:\Users\atnextc\Documents\CRM AutoIT Scripts\VIA.kxf
$nMSG = GUICreate("VIA Networks CRM Helper", 547, 375, 192, 133)
$mnufile = GUICtrlCreateMenu("&File")
$mnuexit = GUICtrlCreateMenuItem("Exit", $mnufile)
$mnuhelp = GUICtrlCreateMenu("&Help")
$mnunone = GUICtrlCreateMenuItem("There Is None", $mnuhelp)
$mnuabout = GUICtrlCreateMenu("&About")
$mnucrm = GUICtrlCreateMenuItem("About CRM Helper", $mnuabout)
$Pic1 = GUICtrlCreatePic("C:\Users\atnextc\Documents\CRM AutoIT Scripts\vialogo.jpg", 168, 32, 249, 57, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$lbl1 = GUICtrlCreateLabel("1.", 160, 160, 13, 17)
$lbl2 = GUICtrlCreateLabel("2.", 160, 184, 13, 17)
$lbl3 = GUICtrlCreateLabel("3.", 160, 208, 13, 17)
$lbl4 = GUICtrlCreateLabel("4.", 160, 232, 13, 17)
$lblcrm = GUICtrlCreateLabel("Login To CRM", 184, 160, 73, 17)
$lblalert = GUICtrlCreateLabel("Close an Alert", 184, 184, 69, 17)
$lblclose = GUICtrlCreateLabel("Close a Case", 184, 208, 66, 17)
$lblcreate = GUICtrlCreateLabel("Create New Case", 184, 232, 87, 17)
$lbl5 = GUICtrlCreateLabel("5.", 160, 256, 13, 17)
$lblexit = GUICtrlCreateLabel("Exit", 184, 256, 21, 17)
$lbltitle = GUICtrlCreateLabel("Please Select An Option From The List Below", 176, 112, 218, 17)
$btnok = GUICtrlCreateButton("OK", 168, 304, 75, 25, $WS_GROUP)
$btnexit = GUICtrlCreateButton("Exit", 288, 304, 75, 25, $WS_GROUP)
$chkcrm = GUICtrlCreateCheckbox("", 288, 160, 17, 17)
$chkalert = GUICtrlCreateCheckbox("", 288, 184, 17, 17)
$chkclose = GUICtrlCreateCheckbox("", 288, 208, 17, 17)
$chkcreate = GUICtrlCreateCheckbox("", 288, 232, 17, 17)
$chkexit = GUICtrlCreateCheckbox("", 288, 256, 17, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1 = 1
    $nMSG = GUIGetMsg()
    If $nMSG = $mnufile Then
                $mnufile = GUICtrlCreateMenuItem($mnufile, $mnuexit)
                Exit
            EndIf

            If $nMSG = $mnunone Then
                MsgBox(0, "CRM Helper", "Sorry There Is No Help!")
            EndIf

            If $nMSG = $GUI_EVENT_CLOSE Or $nMSG = $btnexit Or $nMSG = $mnuexit Then ExitLoop
            If $nMSG = $mnucrm Then MsgBox(0, "About CRM Helper", "Created by atnextc")
            WEnd
    Switch GUIGetMsg()
        Case $chkexit
            If GUICtrlRead($chkexit) = $GUI_CHECKED Then
                GUICtrlSetData($chkexit, 'Checked')
            Else
                GUICtrlSetData($chkexit, 'Unchecked')
            EndIf
        
            
        
        Case $btnok
            $IsChecked = GUICtrlRead($chkexit) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkexit) = $GUI_UNCHECKED Then
            Else
                Exit
            EndIf
            $IsChecked = GUICtrlRead($chkalert) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkalert) = $GUI_UNCHECKED Then
            Else
                MsgBox(0, "CRM Helper", "This will close an alert in CRM!")
                Exit
            EndIf
            $IsChecked = GUICtrlRead($chkcrm) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkcrm) = $GUI_UNCHECKED Then
            Else
                MsgBox(0, "CRM Helper", "This will log you into CRM!")
                Exit
            EndIf
            $IsChecked = GUICtrlRead($chkclose) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkclose) = $GUI_UNCHECKED Then
            Else
                MsgBox(0, "CRM Helper", "This will close a case in CRM!")
                Exit
            EndIf

            $IsChecked = GUICtrlRead($chkcreate) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkcreate) = $GUI_UNCHECKED Then
            Else
                MsgBox(0, "CRM Helper", "This will create a new case in CRM!")
                Exit
            EndIf
            $IsChecked = GUICtrlRead($chkcreate) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkcreate) = $GUI_UNCHECKED Then
                $IsChecked = GUICtrlRead($chkclose) = $GUI_CHECKED
                ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                If GUICtrlRead($chkclose) = $GUI_UNCHECKED Then
                    $IsChecked = GUICtrlRead($chkcrm) = $GUI_CHECKED
                    ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                    If GUICtrlRead($chkcrm) = $GUI_UNCHECKED Then
                        $IsChecked = GUICtrlRead($chkexit) = $GUI_CHECKED
                        ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                        If GUICtrlRead($chkexit) = $GUI_UNCHECKED Then
                            $IsChecked = GUICtrlRead($chkalert) = $GUI_CHECKED
                            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                            If GUICtrlRead($chkalert) = $GUI_UNCHECKED Then
                                MsgBox(0, "CRM Helper", "Please Select An Option!")
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndIf
            
            $IsChecked = GUICtrlRead($chkcreate) = $GUI_CHECKED
            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
            If GUICtrlRead($chkcreate) = $GUI_CHECKED Then
                $IsChecked = GUICtrlRead($chkclose) = $GUI_CHECKED
                ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                If GUICtrlRead($chkclose) = $GUI_CHECKED Then
                    MsgBox(0, "CRM Helper", "Please Select Only 1 Option!")

                    $IsChecked = GUICtrlRead($chkcrm) = $GUI_CHECKED
                    ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                    If GUICtrlRead($chkcrm) = $GUI_CHECKED Then
                        $IsChecked = GUICtrlRead($chkexit) = $GUI_CHECKED
                        ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                        If GUICtrlRead($chkexit) = $GUI_CHECKED Then
                            $IsChecked = GUICtrlRead($chkalert) = $GUI_CHECKED
                            ConsoleWrite($IsChecked & ', ' & Hex($GUI_CHECKED) & @CRLF)
                            If GUICtrlRead($chkalert) = $GUI_CHECKED Then
                                MsgBox(0, "CRM Helper", "Please Select Only 1 Option!")
                            EndIf
                        EndIf
                    EndIf
                EndIf
            EndIf
        Case $GUI_EVENT_CLOSE
            Exit;Loop
    EndSwitch
;WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate
Edited by atnextc
Link to comment
Share on other sites

  • Moderators

atnextc,

As you only want one option to be selected at a time, I would use a group and radio buttons instead of checkboxes. You can then use a much simpler While...WEnd loop. >_<

Take a look at this:

#comments-start
    This script will launch a GUI asking what you want to do
    1. Login to CRM
    2. Close an open Case
    3. Close an alert
    4. Create a new case for MSS
    5. Exit

    Written by atnextc
    July 30th 2009
#comments-end

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")

#Region ### START Koda GUI section ### Form=C:\Users\atnextc\Documents\CRM AutoIT Scripts\VIA.kxf
$nMSG = GUICreate("VIA Networks CRM Helper", 547, 375, 192, 133)

$mnufile = GUICtrlCreateMenu("&File")
$mnuexit = GUICtrlCreateMenuItem("Exit", $mnufile)
$mnuhelp = GUICtrlCreateMenu("&Help")
$mnunone = GUICtrlCreateMenuItem("There Is None", $mnuhelp)
$mnuabout = GUICtrlCreateMenu("&About")
$mnucrm = GUICtrlCreateMenuItem("About CRM Helper", $mnuabout)

$Pic1 = GUICtrlCreatePic("C:\Users\atnextc\Documents\CRM AutoIT Scripts\vialogo.jpg", 168, 32, 249, 57, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
$lbl1 = GUICtrlCreateLabel("1.", 160, 160, 13, 17)
$lbl2 = GUICtrlCreateLabel("2.", 160, 184, 13, 17)
$lbl3 = GUICtrlCreateLabel("3.", 160, 208, 13, 17)
$lbl4 = GUICtrlCreateLabel("4.", 160, 232, 13, 17)
$lblcrm = GUICtrlCreateLabel("Login To CRM", 184, 160, 73, 17)
$lblalert = GUICtrlCreateLabel("Close an Alert", 184, 184, 69, 17)
$lblclose = GUICtrlCreateLabel("Close a Case", 184, 208, 66, 17)
$lblcreate = GUICtrlCreateLabel("Create New Case", 184, 232, 87, 17)
$lbl5 = GUICtrlCreateLabel("5.", 160, 256, 13, 17)
$lblexit = GUICtrlCreateLabel("Exit", 184, 256, 21, 17)
$lbltitle = GUICtrlCreateLabel("Please Select An Option From The List Below", 176, 112, 218, 17)
$btnok = GUICtrlCreateButton("OK", 168, 304, 75, 25, $WS_GROUP)
$btnexit = GUICtrlCreateButton("Exit", 288, 304, 75, 25, $WS_GROUP)

; Create a group so only one radio canbe selected at a time
GUICtrlCreateGroup("", 275, 145, 37, 140)

$chkcrm = GUICtrlCreateRadio("", 288, 160, 17, 17)
$chkalert = GUICtrlCreateRadio("", 288, 184, 17, 17)
$chkclose = GUICtrlCreateRadio("", 288, 208, 17, 17)
$chkcreate = GUICtrlCreateRadio("", 288, 232, 17, 17)
$chkexit = GUICtrlCreateRadio("", 288, 256, 17, 17)
GUICtrlSetState(-1, $GUI_CHECKED) ; Set this as the default setting

GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group

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

While 1

    Switch GUIGetMsg()

    Case $GUI_EVENT_CLOSE, $btnexit, $mnuexit
        Exit
    Case $mnunone
        MsgBox(0, "CRM Helper", "Sorry There Is No Help!")
    Case $mnucrm
        MsgBox(0, "About CRM Helper", "Created by atnextc")
    Case $btnok
        ; Check which radio is selected - 1 = checked, 4 = unchecked
        For $iSelected_Radio = $chkcrm To $chkexit
            If GUICtrlRead($iSelected_Radio) = 1 Then ExitLoop ; Found the only possibilty so exit the For...Next loop
        Next
        ; Run code for selected radio
        Switch $iSelected_Radio
            Case $chkcrm
                MsgBox(0, "CRM Helper", "This will log you into CRM!")
                Exit
            Case $chkalert
                MsgBox(0, "CRM Helper", "This will close an alert in CRM!")
                Exit
            Case $chkclose
                MsgBox(0, "CRM Helper", "This will close a case in CRM!")
                Exit
            Case $chkcreate
                MsgBox(0, "CRM Helper", "This will create a new case in CRM!")
                Exit
            Case $chkexit
                Exit
        EndSwitch
    EndSwitch

WEnd

Func TogglePause()
    $Paused = Not $Paused
    While $Paused
        Sleep(100)
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Ask if anything is unclear.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Thanks works great now. I had tried radio buttons but still basically ended up where I was at with the checkboxes.

I'll keep messing with it and let you know if I run into anymore problems.

Oh yea, one more thing, how can I make it to where my pic I have will show up on any computer that this is run on?

Link to comment
Share on other sites

@M23

You don't need that GUICtrlCreateGroup() at all. Use GUIStartGroup() instead unless are looking to have the frame border created around group.

GUIStartGroup()
$chkcrm = GUICtrlCreateRadio("", 288, 160, 17, 17)
$chkalert = GUICtrlCreateRadio("", 288, 184, 17, 17)
$chkclose = GUICtrlCreateRadio("", 288, 208, 17, 17)
$chkcreate = GUICtrlCreateRadio("", 288, 232, 17, 17)
$chkexit = GUICtrlCreateRadio("", 288, 256, 17, 17)
GUICtrlSetState(-1, $GUI_CHECKED) ; Set this as the default setting
GUIStartGroup() ;; To end the group

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

GEOSoft,

Thank you for that reminder. I always forget that you can do it without the border - it is age, you know. >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

GEOSoft,

Thank you for that reminder. I always forget that you can do it without the border - it is age, you know. >_<

M23

Good excuse. I'll have to remember that one.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 3 weeks later...

@M23

You don't need that GUICtrlCreateGroup() at all. Use GUIStartGroup() instead unless are looking to have the frame border created around group.

GUIStartGroup()
$chkcrm = GUICtrlCreateRadio("", 288, 160, 17, 17)
$chkalert = GUICtrlCreateRadio("", 288, 184, 17, 17)
$chkclose = GUICtrlCreateRadio("", 288, 208, 17, 17)
$chkcreate = GUICtrlCreateRadio("", 288, 232, 17, 17)
$chkexit = GUICtrlCreateRadio("", 288, 256, 17, 17)
GUICtrlSetState(-1, $GUI_CHECKED) ; Set this as the default setting
GUIStartGroup() ;; To end the group

If I want to do the same with check boxes which run the selected programs in series, what should i do?

thankyou

Link to comment
Share on other sites

  • Moderators

SolidSnake26,

run the selected programs in series

The point of using a group is to have only one selection at a time - that is why radiobuttons are the preferred control. If you want several options to run in sequence (which is how I understand your quote above), you do not need a group - you can just run through the checkboxes in turn and check their state - then run whatever is associated with that checkbox.

If I have misunderstood you and this is not what you wanted to do, please give some more explanation. >_<

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

#include <ButtonConstants.au3>
#include<GUIConstantsEx.au3>

GUICreate("Test")
GUIStartGroup()
$Btn_1 = GUICtrlCreateCheckBox(" 1", 10, 10, 25, 17)
$Btn_2 = GUICtrlCreateCheckBox(" 2", 10, 40, 25, 17)
$Btn_3 = GUICtrlCreateCheckBox(" 3", 10, 70, 25, 17)
GUIStartGroup()
GUISetState()
While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $Btn_1 To $Btn_3
            For $i = $Btn_1 To $Btn_3
                If $i = $Msg Then ContinueLoop
                If BitAND(GUICtrlRead($Msg), $GUI_CHECKED) Then GUICtrlSetState($i, $GUI_UNCHECKED)
            Next
    EndSwitch
WEnd

EDIT: Changed the code to use BitAND()

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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