Sign in to follow this  
Followers 0
Kmurray

How to return to GUI after input validation

6 posts in this topic

This must be an easy one, but I promise I've searched for quite some time trying to find the solution. I'm using the basic GUI example to create a simple form. I am trying to ensure that one of two radio buttons is checked. I'm able to do so and display a message saying this needs to be fixed... how do I reset focus back to the GUI and restart the GUI State? The (;; need to go back to form here) portion.

Thanks!!

#include <INet.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>


GUICreate("Vendor Access Reporting Tool", 500, 500)
GUICtrlCreateLabel("ATTENTION!", 20, 10)
GUICtrlCreateLabel("This form must be filled out by vendors accessing this system both at login and", 30, 30)
GUICtrlCreateLabel("log off.  Failure to adequately completeform entries not matching access logs will ", 30, 45)
GUICtrlCreateLabel("be grounds for more active involvement by IT staff, and certainly more arduous ", 30, 60)
GUICtrlCreateLabel("procedures for our vendors.  Please comply. ", 30, 75)

GUICtrlCreateLabel("Please Enter Your Name:", 20, 110)
$name = GUICtrlCreateInput("", 20, 130, 300, 20)

$on = GUICtrlCreateRadio("Logging IN", 20, 160)
$off = GUICtrlCreateRadio("Logging OFF", 100, 160)

GUICtrlCreateLabel("Please describe the work that you are intending to complete (be specific):", 20, 190)
$text = GUICtrlCreateEdit("Required", 20, 210, 450, 200, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL)

$okbutton = GUICtrlCreateButton("Submit Report", 200, 450, 100)
GUISetState(@SW_SHOW)
$okclose = 1

While 1
  $msg = GUIGetMsg()

  Select
    Case $msg = $okbutton
      ;MsgBox(0, "GUI Event", "You pressed OK!" & GUICtrlRead($name))
      ;MsgBox(0, "Text", GuiCtrlRead($text))

        if (GuiCtrlRead($on) == 1) Then
          $logging = "ON"
        ElseIf (GuiCtrlRead($off) == 1) Then
          $logging = "OFF"
        Else
          MsgBox(0, "Logging ON/OFF", "You must indicate whether you are logging on or logging off.")
;; need to go back to form here
        EndIf
    
      msgBox(0, "Logging", $logging)
;; Will log entry and email here ;;
    Case $msg = $GUI_EVENT_CLOSE
      ExitLoop
  EndSelect

WEnd

Share this post


Link to post
Share on other sites



Kmurray ,

Your script was crashing because if no checkbox was selected, $logging was undefined and so the MsgBox did not know what to display. :)

Solution: Declare the $logging variable and if it has not been set, then do not try to show it in the MsgBox. :(

$logging = "" ; declare the variable as blank
if (GUICtrlRead($on) = 1) Then
    $logging = "ON"
ElseIf (GUICtrlRead($off) = 1) Then
    $logging = "OFF"
Else
    MsgBox(0, "Logging ON/OFF", "You must indicate whether you are logging on or logging off.")
    ;; need to go back to form here
EndIf

If $logging <> "" Then MsgBox(0, "Logging", $logging) ; Only show the MsgBox if there is something to show

Do you realise you can force one of the checkboxes to be pre-selected by using GUICtrlSetState(ControlID, $GUI_CHECKED)? Then you would not have to worry about any of the above. :)

M23

P.S. You do not need the == operator here - it is only used to make case-sensitive comparisons between strings.


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 reply.. the If-Then-Else logic actually was working fine. I did realize that I could force the button, but as this script is for vendors logging into a remote access point, I wanted them to actively have to say "I'm logging IN" or "I'm logging OUT." What I'm unclear about is when I get to the Else that gives them a message box saying "YOU MUST..." I don't know how to redisplay the form (in it's current state) so they can select one of the radios and re-submit.

Thanks!

Share this post


Link to post
Share on other sites

Kmurray,

Sorry, I thought that my hint would be enough. :( You need to put all the "Log entry and email" stuff inside the If...EndIf like this:

#include <INet.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

GUICreate("Vendor Access Reporting Tool", 500, 500)
GUICtrlCreateLabel("ATTENTION!", 20, 10)
GUICtrlCreateLabel("This form must be filled out by vendors accessing this system both at login and", 30, 30)
GUICtrlCreateLabel("log off.  Failure to adequately completeform entries not matching access logs will ", 30, 45)
GUICtrlCreateLabel("be grounds for more active involvement by IT staff, and certainly more arduous ", 30, 60)
GUICtrlCreateLabel("procedures for our vendors.  Please comply. ", 30, 75)

GUICtrlCreateLabel("Please Enter Your Name:", 20, 110)
$name = GUICtrlCreateInput("", 20, 130, 300, 20)

$on = GUICtrlCreateRadio("Logging IN", 20, 160)
$off = GUICtrlCreateRadio("Logging OFF", 100, 160)

GUICtrlCreateLabel("Please describe the work that you are intending to complete (be specific):", 20, 190)
$text = GUICtrlCreateEdit("Required", 20, 210, 450, 200, $ES_MULTILINE + $ES_WANTRETURN + $WS_VSCROLL)

$okbutton = GUICtrlCreateButton("Submit Report", 200, 450, 100)
GUISetState(@SW_SHOW)
$okclose = 1

While 1
    $msg = GUIGetMsg()

    Select
        Case $msg = $okbutton
            ;MsgBox(0, "GUI Event", "You pressed OK!" & GUICtrlRead($name))
            ;MsgBox(0, "Text", GuiCtrlRead($text))

            $logging = ""
            if (GUICtrlRead($on) == 1) Then
                $logging = "ON"
            ElseIf (GUICtrlRead($off) == 1) Then
                $logging = "OFF"
            Else
                MsgBox(0, "Logging ON/OFF", "You must indicate whether you are logging on or logging off.")
                ;; need to go back to form here - OH NO YOU DO NOT!!!!! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            EndIf
            ; BECAUSE YOU WILL SKIP THIS PART IF NO RADIO HAS BEEN CHECKED AND GO BACK TO THE FORM <<<<<<<<<<<<<<<<<<<<<<<<<<<<
            If $logging <> "" Then
                        MsgBox(0, "Logging", $logging)
                        ;; Will log entry and email here ;;
            EndIf

        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect

WEnd

Then it will only run if a Radio is checked. Is that clearer? :)

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

M23,

Thanks again for your time... I am a bit dense, so I appreciate the hand holding. Now I see how silly the question was in the first place. I guess I missed the fact that I just wanted to stay in the while loop... I had some misconception of thinking I had to reset the message state somehow. Anyhow, thanks for clearing it up.

Ken

Share this post


Link to post
Share on other sites

Kmurray,

No problem. We all started there sometime - even if for some of us it was a long time ago. :(

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

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