Jump to content

_GUICtrlDTP_GetSystemTime() seems not to be compatible with _GUICtrlDTP_SetSystemTime()


Recommended Posts

Hi!

I'm having problems when, after getting a datetimepicker control's data, I try to restore it later.

It seems that _GUICtrlDTP_GetSystemTime() gerenates a 0-based index array (C-like), while _GUICtrlDTP_SetSystemTime() expects a 1-based index array (pascal-like).

I made this simple example:

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiDateTimePicker.au3>
#include <Array.au3>


GUICreate("sample", 288, 105)

$picker = GUICtrlCreateDate("2015/06/24 14:22:35", 8, 8, 274, 21)
$getsystemtime = GUICtrlCreateButton("GetSystemTime", 8, 40, 273, 25)
$setsystemtime = GUICtrlCreateButton("SetSystemTime (after clicking above)", 8, 72, 275, 25)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $getsystemtime
            $aSystemtime = _GUICtrlDTP_GetSystemTime(GUICtrlGetHandle($picker))
            _ArrayDisplay($aSystemtime)

        Case $setsystemtime
            If Not IsDeclared('aSystemtime') Then
                MsgBox(0, '', 'click getsystemtime first')
            Else
                _ArrayDisplay($aSystemtime)
                _GUICtrlDTP_SetSystemTime(GUICtrlGetHandle($picker), $aSystemtime)
            EndIf

    EndSwitch
WEnd

When I run it and press GetSystemTime, I see this array:

screenshot_75.png

And when I put this same array into the picker again, using _GUICtrlDTP_SetSystemTime(), it breaks the script and the SciTe console shows:

"C:\Program Files (x86)\AutoIt3\Include\GuiDateTimePicker.au3" (286) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:
DllStructSetData($tDate, "Second", $aDate[6])
DllStructSetData($tDate, "Second", ^ ERROR

I could fix it just with a few modifications on the _GUICtrlDTP_GetSystemTime() function on %PROGRAMFILES%\AutoIt3\Include\GuiDateTimePicker.au3, which starts on line 159:

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......: Jefrey
; ===============================================================================================================================
Func _GUICtrlDTP_GetSystemTime($hWnd)
    Local $aDate[7]
 ; modified the array range, from 6 to 7

    Local $tDate = _GUICtrlDTP_GetSystemTimeEx($hWnd)
    $aDate[0] = False ; pushed the item 0 (if true, the input will be 'no date') and re-set the following indexes:
    $aDate[1] = DllStructGetData($tDate, "Year")
    $aDate[2] = DllStructGetData($tDate, "Month")
    $aDate[3] = DllStructGetData($tDate, "Day")
    $aDate[4] = DllStructGetData($tDate, "Hour")
    $aDate[5] = DllStructGetData($tDate, "Minute")
    $aDate[6] = DllStructGetData($tDate, "Second")
    Return $aDate
EndFunc   ;==>_GUICtrlDTP_GetSystemTime

I'm using AutoIt version 3.3.12.0. Has someone also faced this issue?

Edited by Jefrey

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

You could use something like this to add the first parameter to the array returned by _GUICtrlDTP_GetSystemTime

Local $aDate = StringSplit(True & "|" & _ArrayToString($aSystemTime), "|", $STR_NOCOUNT )

 

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 comment
Share on other sites

@BrewManNH thanks for your reply!
That's another solution. Can it be considered a bug on the GuiDateTimePicker.au3 lib?

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

I wouldn't call it a bug, more like a design decision that wasn't well thought out. A bug is something that doesn't work as intended in the code, this works exactly like it is designed to do.

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