MikeK6MKF Posted March 5, 2015 Share Posted March 5, 2015 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 More sharing options...
Moderators Melba23 Posted March 5, 2015 Moderators Share Posted March 5, 2015 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 ;==>_CheckUTCThe RegEx checks you have 4 (and only 4) digits in the return. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 5, 2015 Author Share Posted March 5, 2015 Thank you, Melba23. This is very helpful and much appreciated. I've run your code and now understand what StringRegExp($ReadUTC, "^d{4}$") is returning. Now maybe I can get this last function to work in my script! Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 5, 2015 Author Share Posted March 5, 2015 Thanks to your help, my AutoIt script #1 works as I imagined it to work! And I learned a lot in the process! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 5, 2015 Moderators Share Posted March 5, 2015 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
MikeK6MKF Posted March 5, 2015 Author Share Posted March 5, 2015 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 More sharing options...
jguinch Posted March 5, 2015 Share Posted March 5, 2015 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}$")) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Solution MikeK6MKF Posted March 6, 2015 Author Solution Share Posted March 6, 2015 Thank you to everyone who responded with suggestions. I have this working now, and here is the code I used: expandcollapse popup; 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now