Sign in to follow this  
Followers 0
Necromorph

interval steps _GUIDateTimePicker

6 posts in this topic

#1 ·  Posted (edited)

i have an idea of some functionality i want, but i think that this one may be a bit out of my grasp, it may not even be possible....

i want to have a datetimepicker that the is in the format of 'hh:mm tt' and have the arrow controls make it step in 15 minute intervals

ie:

04:00 pm, 04:15 pm, 04:30 pm and so on,

just looking for some ideas, or if this even possible. thanks.

Edited by redLabel

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

redLabel,

Does this help: :)

#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>

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

$hDate = GUICtrlCreateDate("", 10, 10, 200, 20, $DTS_TIMEFORMAT)

GUISetState()

$DTM_SETFORMAT_ = 0x1032    ; $DTM_SETFORMATW
$sStyle = "HH:mm tt"
GUICtrlSendMsg($hDate, $DTM_SETFORMAT_, 0, $sStyle)

$sTime = GUICtrlRead($hDate)
$iCurrMins = Number(StringMid($sTime, 4, 2))

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $sTime = GUICtrlRead($hDate)
    $sHour = StringMid($sTime, 1, 2)
    $iMins = Number(StringMid($sTime, 4, 2))
    Switch $iMins
        Case 1 To 14
            If $iMins > $iCurrMins Then
                $iMins = 15
            Else
                $iMins = 0
            EndIf
            GUICtrlSetData($hDate, "2010/04/07 " & $sHour & ":" & StringFormat("%02i", $iMins) & ":00")
        Case 16 To 29
            If $iMins > $iCurrMins Then
                $iMins = 30
            Else
                $iMins = 15
            EndIf
            GUICtrlSetData($hDate, "2010/04/07 " & $sHour & ":" & StringFormat("%02i", $iMins) & ":00")
        Case 31 To 44
            If $iMins > $iCurrMins Then
                $iMins = 45
            Else
                $iMins = 30
            EndIf
            GUICtrlSetData($hDate, "2010/04/07 " & $sHour & ":" & StringFormat("%02i", $iMins) & ":00")
        Case 46 To 59
            If $iCurrMins = 0 Then $iCurrMins = 60
            If $iMins > $iCurrMins Then
                $iMins = 0
            Else
                $iMins = 45
            EndIf
            GUICtrlSetData($hDate, "2010/04/07 " & $sHour & ":" & StringFormat("%02i", $iMins) & ":00")
    EndSwitch
    $iCurrMins = $iMins

WEnd

At the moment, only the "up" arrow of the up/down works (because of the way I have constructed the Switch) - I am still trying to solve that. :(

All fixed - at the expense of a more complicated Switch!

M23

Edit: New code.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

thanks much, you rock! it will take some implementing into my script, but i will make it work!!! thanks again.!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

i know this is old, and it has been on the back burner for me for some time now, but i got it resolve, and very easily as well, the issue with the above solution was that it didn't handle the the am/pm switch very well, ie: from 11:56 am should round up to 12:00 pm, but it didnt work like that, and it always rounded down. ie: 11:56 am would round down to 11:45 am. anyway, now that it doesn't work, but just not how i wanted it to work. so here is how i did it, which i think all the bugs are worked out of.

#include <GUIConstantsEx.au3>
#include <GUIDateTimePicker.au3>
#include <DateTimeConstants.au3>
#include <Date.au3>

$mainForm = GUICreate("15min step test", 200, 200)
GUISetState()

$time = GUICtrlCreateDate('', 25, 25, 150, -1, $dts_timeformat)
$timeHandle = GUICtrlGetHandle($time)
_GUICtrlDTP_SetFormat($timeHandle, 'hh:mm tt')

$buttonTest = GUICtrlCreateButton("test", 25, 75, 75)

While 1


    $msg = GUIGetMsg()
    Switch $msg
        Case $gui_event_close
            Exit
        Case $buttonTest
            $testTime = GUICtrlRead($time)
            GUICtrlSetData($time, _NowCalcDate() & ' ' & _15minStep())
    EndSwitch
WEnd

Func _15minStep()


    $hour = Number(StringLeft(GUICtrlRead($time), 2))
    $min = Number(StringTrimLeft(StringTrimRight(GUICtrlRead($time), 3), 3))
    $am_pm = StringRight(GUICtrlRead($time), 2)

    Select
        Case $min < 07.5
            $min = 0
            If $am_pm = "PM" and $hour <> 12 Then
                $hour = $hour + 12
            EndIf
        Case $min < 22.5
            $min = 15
            If $am_pm = "PM" and $hour <> 12 Then
                $hour = $hour + 12
            EndIf
        Case $min < 37.5
            $min = 30
            If $am_pm = "PM" and $hour <> 12 Then
                $hour = $hour + 12
            EndIf
        Case $min < 52.5
            $min = 45
            If $am_pm = "PM" and $hour <> 12 Then
                $hour = $hour + 12
            EndIf
        Case $min > 52.5
            $min = 0
            If $hour = 11 and $am_pm = "PM" Then
                $hour = 00
                $am_pm = "AM"
            ElseIf $hour = 12 and $am_pm = "AM" Then
                $hour = 01
                $am_pm = "AM"
            Else
                Switch $am_pm
                    Case "AM"
                        $hour = $hour + 1
                    Case "PM"
                        $hour = $hour + 13
                EndSwitch
            EndIf
        EndSelect

    Return $hour & ":" & $min & ' ' & $am_pm

EndFunc

but again, thanks for all the help.

Edited by redLabel

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Does this do the same thing as your last example?

Func _15minStep()
    Local $worktime = GUICtrlRead($time)
    $hour = StringLeft($worktime, 2)
    $min = StringMid($worktime, 4, 2)
    $am_pm = StringRight($worktime, 2)

    If $hour = 12 then $hour = "00"
    If $am_pm = "PM" Then $hour += 12
    $min = Int(($min + 7.5) / 15) * 15
    If $min = 60 Then
        $min = 0
        $hour += 1
        If $hour = 24 Then $hour = "00"
    EndIf
    Return $hour & ":" & $min & " "
EndFunc

Edit: Actually, it didn't, but should now.

Edited by Spiff59

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

it is very close, and much simpler then mine, one bug i found was set the time to 01:56 AM and clikc the test, it goes to 02:30 AM, so its close. good work, im going to work with it. thanks

okay i made a two changes that seem to fix it all (well, all of what i have tested, and i havn't found any more bugs, yet) all i did was make change the line

if $min = 60 Then

to

if $min >= 60 Then

and the line

Return $hour & ":" & $min & " "

to

Return $hour & ":" & $min & $am_pm

that seemed to fix everything.

Edited by redLabel

Share this post


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
Sign in to follow this  
Followers 0