Jump to content

Make input box required


Recommended Posts

I have an input box. i would like to make that field required...is there a special way to do this? The only way that I could think of, is in the while loop, adding a If $inputfield == '' then blah....here is my code...

$Main = GUICreate('System ID', 300, 100) 

    Opt("GUICoordMode",1)
    $CollectSystemID = GUICtrlCreateInput('',100,20,100)
    $SystemIDLabel = GUICtrlCreateLabel('System ID',30,23)
    $CollectModality = GUICtrlCreateCombo('CR',100,40,50)
    GUICtrlSetData(-1,"CT|DR|DX|MG|MR|NM|OT|PT|RF|RG|US|XA")
    $ModalityLabel = GUICtrlCreateLabel('Modality',30,43)
    GLOBAL $SystemID = ''
    $Button_1 = GUICtrlCreateButton ("OK",  225, 60, 0)

    GUISetState ()
    ; Run the GUI until the dialog is closed
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                GLOBAL $SystemID = GUICtrlRead($CollectSystemID)
                GLOBAL $Modality = GUICtrlRead($CollectModality)
                If $SystemID == '' Then
                    MsgBox(0,'System ID','The System ID is a require field')
                    ExitLoop
                EndIf
                WinSetState('PacsScan System ID','',@SW_HIDE)
                ExitLoop
        EndSelect
    Wend

The problem is, i don't want to close the GUI if the field is empty, if they click ok and the field is empty, I want it to open a message box saying that the field is required. and then still have the GUI there. If they click the close button. I would like it to just close.

-- On a side note, after entering text into the input box, how do I make it so when pressing enter with the gui active, it will press ok. You know what I mean? Instead of having to click the ok button every time?

Link to comment
Share on other sites

...

If $SystemID == '' Then

MsgBox(0,'System ID','The System ID is a require field')

EndIf

WinSetState('PacsScan System ID','',@SW_HIDE)

ExitLoop

EndSelect

...

Just checking your code. If these lines are the false part, just change to:

If $SystemID == '' Then
      MsgBox(0,'System ID','The System ID is a require field')
   Else
      WinSetState('PacsScan System ID','',@SW_HIDE)
      ExitLoop
   EndIf
Link to comment
Share on other sites

is this what you mean?

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 187, 115, 193, 115)
$Label1 = GUICtrlCreateLabel("Name*", 8, 48, 36, 17)
$Input1 = GUICtrlCreateInput("", 56, 40, 121, 21)
$Button1 = GUICtrlCreateButton("OK", 56, 72, 75, 25, 0)
$Label2 = GUICtrlCreateLabel("", 48, 8, 140, 17)
GUICtrlSetColor(-1, 0xFF0000)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $name = GUICtrlRead($Input1)
            If $name = "" Then
                GUICtrlSetData($Label2, "You have to enter your name")
            Else
                MsgBox(0,"Test",$name)
            EndIf
            
    EndSwitch
WEnd

some of my scripts check them out and give feedback so i can learn from them :)autoclicker a autoclickernote taker a script to take notes with

Link to comment
Share on other sites

yeh, that works. Thanks guys.

About the enter key though. Should I just add another Case statement? If So Case $msg = ??? not sure how to eval that enter key there.

Set $BS_DEFPUSHBUTTON as the style of your OK button ...?
"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110
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...