Jump to content
TheDcoder

GUICtrlSetData fails to set time in a "Date" control

Recommended Posts

Hi everyone,

I am bit stumped as to why I am not able to set the time in the Date control :wacko:

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

Example()

Func Example()
    GUICreate("My GUI get date", 200, 200, 800, 200)
    Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT)

    ; to select a specific default format
    Local $sStyle = "HH:mm:ss"
    GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle)

    ; Set time
    Local $iRet = GUICtrlSetData($idDate, '13:33:37')
    ConsoleWrite('GUICtrlSetData returned ' & ($iRet = 1 ? 'success' : 'failure') & @CRLF)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    WEnd

    MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate))
EndFunc   ;==>Example

The documentation for GUICtrlSetData clearly mentions that it uses the same format as GUICtrlRead:

Quote

For Date controls:
The date and time is in the format defined by the regional settings. GUICtrlRead() use the same default format.

But I get failure :(

What gives?

Thanks for the help in advance!


EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Share this post


Link to post
Share on other sites

I know I gave you this in HexChat, but I should add here in this topic.

What one of my programs uses.

$Group_from = GuiCtrlCreateGroup("Update From", 10, 10, 190, 55)
    $Date_from = GuiCtrlCreateDate($now, 20, 30, 90, 20)
    $Date_fromtime = GuiCtrlCreateDate($time, 120, 30, 70, 20, $DTS_TIMEFORMAT)
    $DTM_SETFORMAT_ = 0x1032
    $style = "yyyy/MM/dd"
    GUICtrlSendMsg($Date_from, $DTM_SETFORMAT_, 0, $style)
    $style = "HH:mm:ss"
    GUICtrlSendMsg($Date_fromtime, $DTM_SETFORMAT_, 0, $style)

Hope it helps.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

At the risk of going overboard, here is a related function.

Func DatesGUI($combo, $now)
    Local $Button_apply, $Button_x3, $Date_from, $Date_fromtime, $Date_to, $Date_totime, $Group_from, $Group_to
    ;
    Local $d1, $d2, $DatesGUI, $time
    ;
    $now = StringSplit($now, " ", 1)
    If $now[0] = 2 Then
        $time = $now[2]
        $now = $now[1]
    Else
        $time = ""
        $now = ""
    EndIf
    ;MsgBox(262192, "$now $time", $now & @LF & $time, 0, $DatesGUI)
    ; Script generated by AutoBuilder 0.9 Prototype
    $DatesGUI = GuiCreate("Dates", 280, 150, $left, -1, $WS_OVERLAPPED + $WS_CAPTION + $WS_SYSMENU _
                        + $WS_VISIBLE + $WS_CLIPSIBLINGS + $WS_MINIMIZEBOX, $WS_EX_TOPMOST, $SBSgetGUI)
    ; CONTROLS
    $Group_from = GuiCtrlCreateGroup("Date From", 10, 10, 190, 55)
    If $combo = $Combo_from Then
        $Date_from = GuiCtrlCreateDate($now, 20, 30, 90, 20)
        $Date_fromtime = GuiCtrlCreateDate($time, 120, 30, 70, 20, $DTS_TIMEFORMAT)
    Else
        If $period = "...select..." Then
            $d1 = IniRead($inifle, "Date From", "select", "")
            $d1 = StringSplit($d1, " ", 1)
            If $d1[0] = 2 Then
                $d2 = $d1[2]
                $d1 = $d1[1]
            Else
                $d1 = "2000/01/01"
                $d2 = "00:00:00"
            EndIf
        Else
            $d1 = "2000/01/01"
            $d2 = "00:00:00"
        EndIf
        $Date_from = GuiCtrlCreateDate($d1, 20, 30, 90, 20)
        $Date_fromtime = GuiCtrlCreateDate($d2, 120, 30, 70, 20, $DTS_TIMEFORMAT)
    EndIf
    $DTM_SETFORMAT_ = 0x1032
    $style = "yyyy/MM/dd"
    GUICtrlSendMsg($Date_from, $DTM_SETFORMAT_, 0, $style)
    $style = "HH:mm:ss"
    GUICtrlSendMsg($Date_fromtime, $DTM_SETFORMAT_, 0, $style)
    ;
    $Group_to = GuiCtrlCreateGroup("Date To", 10, 75, 190, 55)
    If $combo = $Combo_to Then
        $Date_to = GuiCtrlCreateDate($now, 20, 95, 90, 20)
        $Date_totime = GuiCtrlCreateDate($time, 120, 95, 70, 20, $DTS_TIMEFORMAT)
    Else
        If $perend = "...select..." Then
            $d1 = IniRead($inifle, "Date To", "select", "")
            $d1 = StringSplit($d1, " ", 1)
            If $d1[0] = 2 Then
                $d2 = $d1[2]
                $d1 = $d1[1]
            Else
                $d1 = "2000/01/01"
                $d2 = "00:00:00"
            EndIf
        Else
            $d1 = "2000/01/01"
            $d2 = "00:00:00"
        EndIf
        $Date_to = GuiCtrlCreateDate($d1, 20, 95, 90, 20)
        $Date_totime = GuiCtrlCreateDate($d2, 120, 95, 70, 20, $DTS_TIMEFORMAT)
    EndIf
    $style = "yyyy/MM/dd"
    GUICtrlSendMsg($Date_to, $DTM_SETFORMAT_, 0, $style)
    $style = "HH:mm:ss"
    GUICtrlSendMsg($Date_totime, $DTM_SETFORMAT_, 0, $style)
    ;
    $Button_apply = GuiCtrlCreateButton("Apply", 210, 15, 60, 50)
    GUICtrlSetFont($Button_apply, 9, 600)
    GUICtrlSetTip($Button_apply, "Apply the currently set date & time!")
    ;
    $Button_x3 = GuiCtrlCreateButton("EXIT", 210, 80, 60, 50, $BS_ICON)
    GUICtrlSetTip($Button_x3, "Exit / Close / Quit the window!")
    ;
    ; SETTINGS
    GUICtrlSetImage($Button_x3, $explorer, $icoX, 1)
    ;
    If $combo = $Combo_from Then
        GUICtrlSetState($Date_to, $GUI_DISABLE)
        GUICtrlSetState($Date_totime, $GUI_DISABLE)
    ElseIf $combo = $Combo_to Then
        GUICtrlSetState($Date_from, $GUI_DISABLE)
        GUICtrlSetState($Date_fromtime, $GUI_DISABLE)
        GUICtrlSetData($Date_to, $now)
        GUICtrlSetData($Date_totime, $time)
    EndIf
    

    GuiSetState()
    While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Button_x3
            ; Exit / Close / Quit the window
            GUIDelete($DatesGUI)
            ExitLoop
        Case $msg = $Button_apply
            ; Apply the currently set date & time
            If $combo = $Combo_from Then
                $date = GUICtrlRead($Date_from) & " " & GUICtrlRead($Date_fromtime)
            ElseIf $combo = $Combo_to Then
                $date = GUICtrlRead($Date_to) & " " & GUICtrlRead($Date_totime)
            EndIf
            MsgBox(262192, "Date Check", $date, 0, $DatesGUI)
            GUIDelete($DatesGUI)
            ExitLoop
        Case Else
            ;;;
        EndSelect
    WEnd
EndFunc ;=> DatesGUI

I will let you nut it out with my code. I am suffering from brain drain and tiredness right now.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Well the clue is in the first line of the following.

$now = StringSplit($now, " ", 1)
    If $now[0] = 2 Then
        $time = $now[2]
        $now = $now[1]
    Else
        $time = ""
        $now = ""
    EndIf

That space is the divider between DATE and TIME, probably as returned by the _Now() function.

So have a try with $now = _Now() before that line ... or replace $now with _Now()

$now = StringSplit(_Now(), " ", 1)

Don't ask me why I am using $now instead of $date, but I imagine $date is in use as a variable elsewhere in my script.


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@TheSaint Thanks, that clears about what $now is, but unfortunately the string returned by _Now is locale-specific, meaning it changes across different regions :(

Quote

Returns Current Date and Time in PC's format.

But I want to set the time in my format, not the PC's format...


EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Share this post


Link to post
Share on other sites

Well isn't it as simple as converting?

If the Date control requires the date or time to be in a specific format, then you are limited to that.

That means you have to sanitize what you send by CtrlSetData

 


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
12 minutes ago, TheSaint said:

Well isn't it as simple as converting?

It is as simple as converting, but conversion is the hard part, and there is no standard reference that can be used, nor is there any Windows API that I can use to convert time and date between different locales... so practically impossible unless I limit myself to a specific version of Windows in specific regional settings.

--

I did find a promising alternative function (_GUICtrlDTP_SetSystemTime) that I could use to set the time, but that too didn't work:

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

Example()

Func Example()
    GUICreate("My GUI get date", 200, 200, 800, 200)
    Local $idDate = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20, $DTS_TIMEFORMAT)

    ; to select a specific default format
    Local $sStyle = "HH:mm:ss"
    GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle)

    ; Set time
    Local $aDate[7] = [True, 0, 0, 0, 13, 33, 37]
    Local $hDate = GUICtrlGetHandle($idDate)
    Local $bRet = _GUICtrlDTP_SetSystemTime($hDate, $aDate)
    ConsoleWrite('_GUICtrlDTP_SetSystemTime returned ' & ($bRet ? 'success' : 'failure') & @CRLF)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    WEnd

    MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate))
EndFunc   ;==>Example

 

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Share this post


Link to post
Share on other sites

Yep, you can set the full date, time or just date.

But that is not his issue.

His issue is to do with locales ... though it seems to me he is making it more complex than it needs to be.


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@Danp2 You are right about having to include date along with the time, but like TheSaint has said, the format of date + time depends on the locale of the machine and I need my script to work in various locales, not only English-like ones.

At this point I am pretty sure GUICtrlSetData only takes the region-specific string as valid input, but what stumps me is why _GUICtrlDTP_SetSystemTime also doesn't seem to work?

@TheSaint Thanks for clarifying on my behalf.

2 hours ago, TheSaint said:

... though it seems to me he is making it more complex than it needs to be.

Depends on how you see it, if I compromise with not properly supporting all locales, I can definitely just hardcode the English string an use a fake date to set the time. But I'd rather not do that.


EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Share this post


Link to post
Share on other sites
1 hour ago, TheDcoder said:

but what stumps me is why _GUICtrlDTP_SetSystemTime also doesn't seem to work?

Like I expected, I overlooked something simple, I had the date in the wrong order in my example, I was using DMY instead of YMD.

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

Example()

Func Example()
    GUICreate("My GUI get date", 200, 200, 800, 200)
    Local $idDate = GUICtrlCreateDate("", 10, 10, 185, 20, $DTS_TIMEFORMAT)
    Local $hDate = GUICtrlGetHandle($idDate)

    ; to select a specific default format
    Local $sStyle = "HH:mm:ss"
    GUICtrlSendMsg($idDate, $DTM_SETFORMATW, 0, $sStyle)

    ; Set time
    Local $aDate[7] = [False, 2020, 1, 1, 13, 33, 37]
    Local $bRet = _GUICtrlDTP_SetSystemTime($hDate, $aDate)
    ConsoleWrite('_GUICtrlDTP_SetSystemTime returned ' & ($bRet ? 'success' : 'failure') & @CRLF)

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    WEnd

    MsgBox($MB_SYSTEMMODAL, "Time", GUICtrlRead($idDate))
EndFunc   ;==>Example

This works perfectly and it doesn't even depend on strings, let alone have regional issues! I am happy :D

Edit: Just noticed another helpful tidbit, remember to set the first element of the time/date array to False, otherwise it won't work! At-least it did not for me.

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation

DcodingTheWeb Forum - Follow for updates and Join for discussion

Share this post


Link to post
Share on other sites
1 hour ago, Danp2 said:

Hmmm... are you sure? His code runs correctly for me by making that one change. I can't find an example where GUICtrlSetData works when supplying time only.

I didn't run his code, and I was very tired last night, and probably shouldn't have bothered replying, but he asked me in HexChat and I remembered I had some code from years ago that probably did close to what he wanted ... it was very specific though and didn't need to cater for regions.

In my code in the 4th post (my second reply) you can see I use the following.

GUICtrlSetData($Date_to, $now)
        GUICtrlSetData($Date_totime, $time)

And you can see from earlier in the code, where I set the controls up.

$style = "yyyy/MM/dd"
    GUICtrlSendMsg($Date_to, $DTM_SETFORMAT_, 0, $style)
    $style = "HH:mm:ss"
    GUICtrlSendMsg($Date_totime, $DTM_SETFORMAT_, 0, $style)

Be aware though, that I did this a few years ago with an older version of AutoIt.

 


Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By kcvinu
      Hi all,
      I am creating a GUI library in Nim with win32 API functions. Even though the syntax is similar to Python, coding is almost similar to C in Nim. 
      I can change the back color of the button in NM_CUSTOMDRAW. But I can't change the button text color. here is my pseudo code.  
      proc setBtnBackColor*(me : Button, lp: LPNMCUSTOMDRAW ) = if lp.uItemState and CDIS_SELECTED : #------------------ btn clicked # Here i am changing the button color with SelectObject & FillRect. elif lp.uItemState and CDIS_HOT : # ----------------Mouse over # Here i am changing the button's mouse hover color with SelectObject & FillRect. else: # -------------------------Default color set # Here i am changing the button's default color with SelectObject & FillRect. # Here i tried---> SetTextColor(lp.hdc, RGB(102, 255, 51) ) #------- But no luck. #------------------------------------------------------------------------- Please guide me. What i am doing wrong here ?  I am returning "CDRF_SKIPDEFAULT" after calling this function.
      Note : I am using subclassed button. So when the parent window receives WM_NOTIFY message, it sends that to my button's WndProc. There i am handling the message.
    • By paw
      I use SetSoundDevice to control my audio devices but the UI was either
       
      blurry like this:
      or unusable like this:

      so I made this horrible thing to add scaling to the GUI:
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Change2CUI=y #AutoIt3Wrapper_Res_HiDpi=y #AutoIt3Wrapper_AU3Check_Parameters=-w 3 -w 4 -w 5 #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/sf /sv /rm #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <File.au3> ;~ _convertGUI("") If $CmdLine[0] <> 0 Then _convertGUI($CmdLine[1]) Func _convertGUI($sFilePath) If $sFilePath <> "" Then Local $aArray = FileReadToArray($sFilePath) Else ;TEST DATA Local $aArray[6] = ['$H_Res_Language = GUICtrlCreateProgress(5, 120, 210 + 25, 480, 20, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) ; $CBS_DROPDOWNLIST)', _ 'Local $h_Ok = GUICtrlCreateButton("Ok", 72, 224, 81, 33, 0)', _ 'GUICreate($Warning_TiTle, 700, 310, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MINIMIZEBOX)', _ 'GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)', _ '$H_FieldNameEdit = GUICtrlCreateEdit($INP_FieldNameEdit, 100,260+25, 500, 150 - 25) ;comment', 'Local $H_CANCEL = GUICtrlCreateGraphic("Cancel", 224, 224, 97, 33, 0)'] EndIf Local $hTimer = TimerInit(), $iGUIElementCount = 0, $sResult = "", $sFileName = "", $sDrive = "", $sDir = "", $sExtension = "" If @Compiled Then _PathSplit($sFilePath, $sDrive, $sDir, $sFileName, $sExtension) $sFileName = StringRegExpReplace($sFilePath, "^.*\\", "") EndIf For $i = 0 To (UBound($aArray) - 1) If StringRegExp($aArray[$i], "GUICtrlCreate|GUICreate") Then $sResult = _splitComma($aArray[$i]) If Not @error Then $aArray[$i] = $sResult $iGUIElementCount += 1 EndIf Next ConsoleWrite("t = " & TimerDiff($hTimer) & " GUI elements = " & $iGUIElementCount & " lines = " & (UBound($aArray) - 1) & @CRLF) If $sFileName <> "" Then Local $hFile = FileOpen("edited." & $sFileName, 2) _FileWriteFromArray("edited." & $sFileName, $aArray) FileClose($hFile) EndIf Exit EndFunc ;==>_convertGUI Func _splitComma($sString) Local $sSplitResult = "", $sTrimmedR = "", $sTrimmedL = "" Local $aSplit = StringSplit($sString, ',') If Not @error Then $sTrimmedR = "" $sTrimmedL = "" For $j = 1 To $aSplit[0] If StringRegExp($aSplit[1], "(?:.GUICtrlCreateGraphic|GUICtrlCreateProgress|GUICtrlCreateSlider|GUICtrlCreateTab|GUICtrlCreateTreeView)") Then If $j = 1 Then While StringLeft($aSplit[$j], 1) <> '(' $sTrimmedL &= StringLeft($aSplit[$j], 1) $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimLeft($aSplit[$j], 1) EndIf EndIf If $j = $aSplit[0] Then While StringRight($aSplit[$j], 1) <> ')' $sTrimmedR &= StringRight($aSplit[$j], 1) $aSplit[$j] = StringTrimRight($aSplit[$j], 1) WEnd $aSplit[$j] = StringTrimRight($aSplit[$j], 1) EndIf If StringRegExp($aSplit[$j], "[0-9]") And $aSplit[$j] <> -1 And $aSplit[$j] <> 0 And $aSplit[$j] <> 1 And Not StringInStr($aSplit[$j], ')') Then If StringRegExp($aSplit[$j], "\-|\+") Then ;put parenthesis around + or - $aSplit[$j] = '(' & $aSplit[$j] & ")*$g_DPI" Else $aSplit[$j] = $aSplit[$j] & "*$g_DPI" EndIf EndIf If $j < $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ',' ElseIf $j = $aSplit[0] Then $sSplitResult &= $aSplit[$j] & ')' Else $sSplitResult &= $aSplit[$j] EndIf Next If $sTrimmedR <> "" Then $sSplitResult &= StringReverse($sTrimmedR) If $sTrimmedL <> "" Then $sSplitResult = $sTrimmedL & '(' & $sSplitResult Else SetError(1) Return EndIf ConsoleWrite($sSplitResult & @CRLF) Return $sSplitResult EndFunc ;==>_splitComma
      And now it looks good: 
      but it doesn't work on everything, for example the "GUICtrlCreateLabel("Output type: ", 30, 130, 65, 20) ;, $SS_RIGHT)" (from the autoit3wrapper gui)
      because the comment contains a parenthesis and it would break completely if there were variables as parameters..
      Is there some kind of parser around that I could use instead or maybe someone who has already done something like this?
    • By nacerbaaziz
      it recomended to use the builten function
      _DateDiff
       
       
       
      hello autoit team
      i made a simple function to help me get the difference between to date
      i liked to share it with you
      the paramatrs of this function
      is firstdate and lastedate
      the two params is as the following
      year/month/day hours:minuts:seconds
      here is the function
       
      #include <date.au3> func _dateBetween($s_firstDate, $s_lastDate = default) if not (StringRegExp($s_firstDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(1, 0, 0) if $s_lastDate = default then $s_lastDate = @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec if not (StringRegExp($s_lastDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(2, 0, 0) local $a_FirstSplitDate = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_FirstSplitTime = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$3"), ":", 2) local $a_lastSplitDate = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_LastSplitTime = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$3"), ":", 2) local $i_firstDateValue = _DateToDayValue($a_FirstSplitDate[0], $a_FirstSplitDate[1], $a_FirstSplitDate[2]) local $i_LastDateValue = _DateToDayValue($a_LastSplitDate[0], $a_LastSplitDate[1], $a_LastSplitDate[2]) if $i_firstDateValue > $i_LastDateValue then Return SetError(3, 0, 0) local $i_totalDays = $i_LastDateValue-$i_firstDateValue if not ($i_totalDays = 0) then if $a_FirstSplitTime[0] <= $a_lastSplitTime[0] then $i_totalDays += 1 $a_lastSplitTime[0] -= $a_FirstSplitTime[0] elseIf $a_FirstSplitTime[0] > $a_lastSplitTime[0] then if $i_totalDays > 0 then $i_totalDays -= 1 $a_FirstSplitTime[0] -= $a_lastSplitTime[0] endIf endIf endIf local $i_totalYears = 0 if $i_totalDays >= 365 then While $i_totalDays >= 365 $i_totalYears += 1 $i_totalDays -= 365 Wend endIf local $i_TotalMonths = 0 if $i_totalDays >= 30 then While $i_totalDays >= 30 $i_totalMonths += 1 $i_totalDays -= 30 Wend endIf local $i_totalWeeks = 0 if $i_totalDays >= 7 then While $i_totalDays >= 7 $i_totalWeeks += 1 $i_totalDays -= 7 Wend endIf $i_totalSeconds = ((($a_FirstSplitTime[0]*60)*60)+($a_FirstSplitTime[1]*60)+($a_FirstSplitTime[2]))-((($a_lastSplitTime[0]*60)*60)+($a_lastSplitTime[1]*60)+($a_LastSplitTime[2])) local $minus = "" if $i_totalSeconds < 0 then $minus = "-" $i_totalSeconds = StringReplace($i_totalSeconds, "-", "") endIf local $i_totalHours = 0 if $i_totalSeconds >= 3600 then While $i_totalSeconds >= 3600 $i_totalHours += 1 $i_totalSeconds -= 3600 Wend endIf local $i_totalminuts = 0 if $i_totalSeconds >= 60 then While $i_totalSeconds >= 60 $i_totalminuts += 1 $i_totalSeconds -= 60 Wend endIf local $a_arrayReturn[7] $a_arrayReturn[0] = $i_totalYears $a_arrayReturn[1] = $i_totalMonths $a_arrayReturn[2] = $i_totalWeeks $a_arrayReturn[3] = $i_totalDays $a_arrayReturn[4] = $minus & $i_totalHours $a_arrayReturn[5] = $minus & $i_totalminuts $a_arrayReturn[6] = $minus & $i_totalSeconds return $a_arrayReturn endFunc  
      here is an example
       
       
      $a_calc = _dateBetween("2015/02/12 23:00:05", "2030/02/12 23:25:50") msgBox(64, "result", StringFormat("the difference is : %i years and %i months and %i weeks and %i days and %i hours and %i minuts and %i seconds", $a_calc[0], $a_calc[1], $a_calc[2], $a_calc[3], $a_calc[4], $a_calc[5], $a_calc[6]))  
      am waiting for your comments
      with my greetings
    • By TXTechie
      Hello Everyone,
      I've developed my own GUI using AutoIt and I'm allowing users to minimize the GUI, but I also want to include some kind of timer so that it will automatically restore the GUI after something like 30 minutes or an hour. However, I also want them to be able to manually restore the GUI by clicking the application's icon in the taskbar.
      I've searched through the forums, but I'm not sure how to get started.
      Any ideas or functions to research are appreciated!
      Regards,
      TX Techie
    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
×
×
  • Create New...