Jump to content

controll format hours?


faustf
 Share

Recommended Posts

Example.

#include <Date.au3>

;Local $sDate = @YEAR & "/" & @MON & "/" & @MDAY & " " & "56" & ":" & @MIN
;Local $sDate = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN

If _DateIsValid($sDate) Then
    MsgBox(4096, "Valid Date", "The specified date is valid.")
Else
    MsgBox(4096, "Valid Date", "The specified date is invalid.")
EndIf

Uncomment one of the above to see valid or invalid.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

faustf,

A quick and dirty attempt - I am sure there are better ways out there: ;)

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

$hGUI = GUICreate("Test", 500, 500)

$cInput = GUICtrlCreateInput("", 10, 110, 200, 40)
GUICtrlSetLimit(-1, 5)
GUICtrlSetFont(-1, 24)

GUISetState()

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

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

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    If BitAND($wParam, 0xFFFF) = $cInput And BitShift($wParam, 16) = 0x300 Then ; $EN_CHANGE
        Local $sInput = GUICtrlRead($cInput)
        If $sInput Then
            $aInput = StringSplit($sInput, "")
            If Not StringRegExp($aInput[1], "[0-2]") Then
                $aInput[1] = ""
            ElseIf $aInput[0] = 2 Then
                If $aInput[1] = 2 Then
                    If Not StringRegExp($aInput[2], "[0-4]") Then
                        $aInput[2] = ""
                    Else
                        ReDim $aInput[4]
                        $aInput[0] = 3
                        $aInput[3] = ":"
                    EndIf
                Else
                    If (Not StringRegExp($aInput[2], "[0-9]")) Then
                        $aInput[2] = ""
                    Else
                        ReDim $aInput[4]
                        $aInput[0] = 3
                        $aInput[3] = ":"
                    EndIf
                EndIf
            ElseIf $aInput[0] = 3 And Not $aInput[3] = ":" Then
                $aInput[3] = ""
            ElseIf $aInput[0] = 4 And Not StringRegExp($aInput[4], "[0-5]") Then
                $aInput[4] = ""
            ElseIf $aInput[0] = 5 And Not StringRegExp($aInput[5], "[0-9]") Then
                $aInput[5] = ""
            EndIf
            $sInput = ""
            For $i = 1 To $aInput[0]
                $sInput &= $aInput[$i]
            Next
            GUICtrlSetData($cInput, $sInput)
        EndIf
    EndIf

EndFunc   ;==>_WM_COMMAND

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

faustf,

I did say it was "quick and dirty" - I am sure there are all sorts of problems with it if you try hard to break it. :)

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

faustf,

My final attempt: ;)

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

$hGUI = GUICreate("Test", 500, 500)
GUISetFont(24)

$cInput_1 = GUICtrlCreateInput("", 10, 10, 25, 40)
GUICtrlSetLimit(-1, 1)

$cInput_2 = GUICtrlCreateInput("", 35, 10, 25, 40)
GUICtrlSetLimit(-1, 1)

GUICtrlCreateLabel(":", 60, 10, 10, 40)

$cInput_3 = GUICtrlCreateInput("", 70, 10, 25, 40)
GUICtrlSetLimit(-1, 1)

$cInput_4 = GUICtrlCreateInput("", 95, 10, 25, 40)
GUICtrlSetLimit(-1, 1)

GUISetState()

GUICtrlSetState($cInput_1, $GUI_FOCUS)

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $lParam

    If BitShift($wParam, 16) = 0x300 Then ; $EN_CHANGE

        Switch BitAND($wParam, 0xFFFF) ; ControlID
            Case $cInput_1
                $sInput = GUICtrlRead($cInput_1)
                If StringRegExp($sInput, "[0-2]") Then
                    If $sInput == "2" Then
                        If Number(GUICtrlRead($cInput_2)) > 4 Then
                            GUICtrlSetData($cInput_2, "")
                        EndIf
                    EndIf
                    GUICtrlSetState($cInput_2, $GUI_FOCUS)
                Else
                    GUICtrlSetData($cInput_1, "")
                    GUICtrlSetState($cInput_1, $GUI_FOCUS)
                EndIf
            Case $cInput_2
                $sInput = GUICtrlRead($cInput_2)
                Switch GUICtrlRead($cInput_1)
                    Case 2
                        If StringRegExp($sInput, "[0-3]") Then
                            GUICtrlSetState($cInput_3, $GUI_FOCUS)
                        Else
                            GUICtrlSetData($cInput_2, "")
                            GUICtrlSetState($cInput_2, $GUI_FOCUS)
                        EndIf
                    Case Else
                        If StringRegExp($sInput, "[0-9]") Then
                            GUICtrlSetState($cInput_3, $GUI_FOCUS)
                        Else
                            GUICtrlSetData($cInput_2, "")
                            GUICtrlSetState($cInput_2, $GUI_FOCUS)
                        EndIf
                EndSwitch
            Case $cInput_3
                $sInput = GUICtrlRead($cInput_3)
                If StringRegExp($sInput, "[0-5]") Then
                    GUICtrlSetState($cInput_4, $GUI_FOCUS)
                Else
                    GUICtrlSetData($cInput_3, "")
                    GUICtrlSetState($cInput_3, $GUI_FOCUS)
                EndIf
            Case $cInput_4
                $sInput = GUICtrlRead($cInput_4)
                If Not StringRegExp($sInput, "[0-9]") Then
                    GUICtrlSetData($cInput_4, "")
                    GUICtrlSetState($cInput_4, $GUI_FOCUS)
                EndIf
        EndSwitch

    EndIf
EndFunc

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

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...