Jump to content

Recommended Posts

Posted (edited)

This is a label control I have (all #includes are ok, and omitted here in the code):

Global $DataIniziale="2010/01/01"
Global $DataFormattata=StringRight($DataIniziale,2) & '/' & StringMid($DataIniziale,6,2) & '/' & StringLeft($DataIniziale,4)
Global $LabelData = GUICtrlCreateLabel($DataFormattata, 16, 64, 170, 18, $SS_CENTER)

Ok, then when the date changes, i need to make it change too in the label. I made a function that changes the date, then when i have done with the function, i put this line:

GUICtrlSetData($LabelData,$DataFormattata)

But the label doesn't update.

PS: i need $Dataformattata because it puts the date in the format of my country)

Only solution i found is putting Guictrlsetdata like this:

GUICtrlSetData($LabelData,StringRight($DataIniziale,2) & '/' & StringMid($DataIniziale,6,2) & '/' & StringLeft($DataIniziale,4))

But putting it as a variable just won't work... Why?

Nothing bad to have it like this. But putting it as variable would make the code shorter and smoother

Edited by niubbone
Posted (edited)

#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <StaticConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 215, 86, -1, -1)
$DataIniziale="2010/01/01"
$Date1 = GUICtrlCreateDate($DataIniziale, 16, 8, 186, 21)
_GUICtrlDTP_SetFormat(GUICtrlGetHandle($Date1), "yyyy/MM/dd")
$LabelData = GUICtrlCreateLabel(_FormatDate($DataIniziale), 16, 64, 170, 18, $SS_CENTER)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Date1
            $DataIniziale = GUICtrlRead($Date1)
            MsgBox(0, "New Value of $DataIniziale", $DataIniziale)
            GUICtrlSetData($LabelData, _FormatDate($DataIniziale))
    EndSwitch
WEnd

Func _FormatDate($sDate)
    Return StringRight($sDate,2) & '/' & StringMid($sDate,6,2) & '/' & StringLeft($sDate,4)
EndFunc

edit: added the two / to line _GUICtrlDTP_SetFormat(GUICtrlGetHandle($Date1), "yyyy/MM/dd")

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Posted

took me some minutes to figure what the hell was that lol

By the way it doesn't work.

If i got it well, that guictrldtp_setdata set all the dates a control receives in a predefined format.

So i did:

#include <GuiDateTimePicker.au3>
Global $LabelData = GUICtrlCreateLabel($DataIniziale, 16, 64, 170, 18, $SS_CENTER)
_GUICtrlDTP_SetFormat(GUICtrlGetHandle($LabelData), "dd/MM/yyyy")
PassADay($Date);Function to make a day pass, not specified here, just put it to give the idea
GUICtrlSetData($LabelData,$DataIniziale)

Nothing changed. I solved it in another longer way. That thing doesnt work properly and doesn't format the date.

Posted (edited)

It works fine , did you change the date on the date picker, _GUICtrlDTP_SetFormat is only there to format the GUICtrlCreateDate , i made a date picker so it created a new date to reformat, it then shows a msgbox of the date picked formated like your original date 2010/01/01 it then uses function _FormatDate to return the passed unformated date and updates the label with GUICtrlSetData.

Edit: i see why it wouldnt run for you , when i copyNpasted i did not get the #includes at the top, modified the post above.

Edited by Yoriz
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

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