Jump to content

How to detect if a GUICtrlCreateInput() is null


Go to solution Solved by MikeK6MKF,

Recommended Posts

I am the uber-newbie with AutoIt, but getting better slowly.

I have created a GUICtrlCreateInput(), and its valid value should be >= 0 And < 2400.   It's UTC time.  My difficulty is that I can't seem to figure out how to detect when it's null.   With my code, null returns '0000' so I can't determine if the User has entered '0000' or has left the input field null.

Global $UTCTime

...

$UTCTime = GUICtrlCreateInput("",10,50,40,20)

...

Func _GetUTC ()
...
$ReadUTC = GUICtrlRead($UTCTime)

; It's at this point I want to Exit the _GetUTCb function if $ReadUTC is null.   If $ReadUTC has had 0000 entered, 
; then I want to continue the function.

EndFunc   ;==>_GetUTC

I hope I have explained this properly.

Thanks for your help and advice.

Link to comment
Share on other sites

  • Moderators

MikeK6MKF,

I would do it like this: :)

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

$hGUI = GUICreate("Test", 500, 500)
$UTCTime = GUICtrlCreateInput("", 10, 50, 40, 20)
$cButton = GUICtrlCreateButton("Test", 10, 100, 80, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            _CheckUTC()
    EndSwitch
WEnd

Func _CheckUTC()
    $ReadUTC = GUICtrlRead($UTCTime)
    MsgBox($MB_SYSTEMMODAL, "Input", StringRegExp($ReadUTC, "^\d{4}$"))
EndFunc   ;==>_CheckUTC
The RegEx checks you have 4 (and only 4) digits in the return. ;)

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

  • Moderators

MikeK6MKF,

Delighted to hear it. :)

For future enhancements, you might also want to look at GUICtrlSetLimit to set a maximum number of characters to enter - and perhaps set the ES_NUMBER style to only allow digits. ;)

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

I barged into AutoIt knowing nothing about it and wanting to get this working for some hobby friends.  

Had some Basic years ago, but ancient history.   Some Perl after that, but still pretty old.

Need to start over at square one and do all the AutoIt tutorials now.  

This is a pretty neat.

Link to comment
Share on other sites

Additionally to the 2 last suggestions of Melba23, you can use this kind of regex to check the user input :

MsgBox($MB_SYSTEMMODAL, "Input", StringRegExp($ReadUTC, "^[0-1]\d{3}|2[0-3]\d{2}$"))
Link to comment
Share on other sites

  • Solution

Thank you to everyone who responded with suggestions.   I have this working now, and here is the code I used:

; Resolve UTC, either from system clock or from valid UTC input in GUI
; Valid User input of UTC time overrides system clock UTC
Func _GetUTC ()
    Local $utc = 0, $ReadUTC = 0

    ; Get current system time into $utc
    $utc = _Date_Time_GetSystemTime()

    ; Extract UTC hour and minute and concatentate them into $utc
    $utcHour = DllStructGetData($utc, "Hour")
    $utcMin  = DllStructGetData($utc, "Minute")
    $utc = StringFormat("%02d%02d", $utcHour, $utcMin)

    ; now get any value in the UTC input field
    $ReadUTC = GUICtrlRead($UTCTime)

    ; Test for null value, i.e. nothing was entered in UTC field
    If StringRegExp($ReadUTC, "^\d{4}$") = 0 Then
        Return $utc  ; return $utc as value read from system clock
        Exit         ; exit the function
    EndIf

    ; The UTC input is not null and is 4 digits, so the function continues
    ; The input string is formatted into the 4 digits
    $ReadUTC = StringFormat("%04d", GUICtrlRead($UTCTime))

    ; If the GUI input is a number equal to or greater than 0 and less than 2400, the it's a valid UTC input, and it becomes the value of $utc
    ; Otherwise, $utc remains the value obtained from the system clock

    If $ReadUTC >= 0 And $ReadUTC < 2400 Then
    $utc = $ReadUTC ; $utc becomes the entered 4 digit value
    Return $utc     ; $utc is returned to caller
    Exit            ; exit the function
    Else
    EndIf

EndFunc   ;==>_GetUTC
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...