Jump to content

GUICtrlCreateInput type HH:MM:SS - (Moved)

Recommended Posts

  • Moderators

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:


General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.

Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites

Search the forum for "input validation" and you will find a lot of UDFs to assist you. Example:


My UDFs and Tutorials:


Active Directory (NEW 2021-06-05 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version - Download
Outlook Tools (2019-07-22 - Version - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version - Download - General Help & Support - Wiki

ADO - Wiki, WebDriver - Wiki


Link to post
Share on other sites

Or simply :

If StringRegExp ($sTime, "^\d{2}:\d{2}:\d{2}$") Then
    $aTime = StringSplit ($sTime, ":", $STR_NOCOUNT)
    If $aTime[0] < 24 And $aTime[1] < 60 And $aTime[2] < 60 Then ... ; it is ok now


Link to post
Share on other sites

But don't forget to check that the result is not something like  85:86:87 ... :)

For the fun  :>

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

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 200, 70)
$Label = GUICtrlCreateLabel("Enter  HH:MM:SS  (24 h format)", 22, 8, 160, 17)
$input = GUICtrlCreateInput("", 50, 30, 100, 24)
GUICtrlSetLimit(-1, 8)
GUICtrlSetFont(-1, 12)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

While 1

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
 Local $id = BitAND($wParam, 0x0000FFFF)
 Local $code = BitShift($wParam, 16)
   If $id = $input AND $code = $EN_UPDATE Then
       Local $content = GUICtrlRead($input)
       $n = StringLen($content)
       If ($n = 1 or $n = 2 or $n = 4 or $n = 5 or $n = 7 or $n = 8) _ 
            and not StringIsDigit(StringRight($content, 1)) Then _ 
            GUICtrlSetData($input, StringTrimRight($content, 1))
       If ($n = 3 or $n = 6) and not (StringRight($content, 1) == ":") Then _ 
            GUICtrlSetData($input, StringTrimRight($content, 1))
       If $n = 2 and Number($content) > 23 Then GUICtrlSetData($input, "")
       If ($n = 5 or $n = 8) and Number(StringRight($content, 2)) > 59 Then _ 
            GUICtrlSetData($input, StringTrimRight($content, 2))

Func _Exit()


Edited by mikell
Link to post
Share on other sites

I'd use 3 (or 4) input controls, an updown control on each, and set the limit for the controls. Use the parameter $ES_NUMBER  so that only numbers can be used. Easy and done.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...