Sign in to follow this  
Followers 0
Marcvde

Add buttons to navigate date picker

9 posts in this topic

#1 ·  Posted (edited)

Hello everyone,

I have made a tool for daily registration for my internship. But i want to give a function to the datepicker go back or forward a day from the current day.

What code do i need?

The code i have so far is(no go next or back picture included):

#include <ButtonConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>
#include <GUIEdit.au3>

Global $DDatePicker, $IWerkDag, $IBeginTijd, $IEindTijd, $IEdit, $LWerkDag, $hInput_Handle

Opt("GUIOnEventMode", 1)

Main()
Func Main()
$Main = GUICreate("Uren registratie Marc van den Elshout", 491, 356, 192, 124)
$Group1 = GUICtrlCreateGroup("", 5, 35, 481, 316)
$BSave = GUICtrlCreateButton("Save", 405, 110, 75, 25)
GUICtrlSetOnEvent($BSave, "Save")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\Data\"&"right.jpg", 448, 8, 25, 25)
$Pic2 = GUICtrlCreatePic(@ScriptDir & "\Data\"&"left.jpg", 414, 7, 25, 25)
GUICtrlSetOnEvent ($Pic1, "_next")
GUICtrlSetOnEvent ($pic2, "_previous")
$LWerkDag = GUICtrlCreateLabel("Werkdag:", 20, 60, 51, 17)
$LBeginTijd = GUICtrlCreateLabel("Begin tijd:", 20, 87, 50, 17)
$LEindTijd = GUICtrlCreateLabel("Eind tijd:", 20, 115, 44, 17)
$IWerkDag = GUICtrlCreateInput("", 75, 58, 121, 21)
$IBeginTijd = GUICtrlCreateInput("8:00", 75, 85, 121, 21)
$IEindTijd = GUICtrlCreateInput("", 75, 113, 121, 21)
$IEdit = GUICtrlCreateEdit("", 15, 140, 466, 206)
$cSelAll = GUICtrlCreateDummy()
GUICtrlSetOnEvent ($cSelAll,"_SelAll")
Dim $aAccelKeys[1][2]=[["^a", $cSelAll]]
$hInput_Handle = GUICtrlGetHandle($IEdit)
GUISetAccelerators($aAccelKeys)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BLookUp = GUICtrlCreateButton("Check", 195, 5, 91, 21)
GUICtrlSetOnEvent($BLookUp, "LookUp")
$DDatePicker = GUICtrlCreateDate("", 5, 5, 186, 21)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
EndFunc

Func LookUp() ;GUICtrlRead($DDatePicker)
$WerkDag = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "werkdag", "")
$BeginTijd = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "begintijd", "")
$EindTijd = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "eindtijd", "")
$Edit = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "edit", "")
GUICtrlSetData($IWerkDag, $WerkDag )
GUICtrlSetData($IBeginTijd, $BeginTijd )
GUICtrlSetData($IEindTijd, $EindTijd )
GUICtrlSetData($IEdit, StringReplace(IniRead(@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "edit", @error), "{ENTER}", @CRLF))
EndFunc

Func _next()

EndFunc

Func _previous()

EndFunc


Func Save()
$WerkDag = GUICtrlRead($IWerkDag)
$BeginTijd = GUICtrlRead($IBeginTijd)
$EindTijd = GUICtrlRead($IEindTijd)
$Edit = GUICtrlRead($IEdit)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "werkdag", $WerkDag)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "begintijd", $BeginTijd)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "eindtijd", $EindTijd)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "edit", StringReplace(GUICtrlRead($IEdit), @CRLF, "{ENTER}"))
EndFunc

Func _Exit()
Save()
Exit
EndFunc

While 1
                Sleep(50)
WEnd

Func _SelAll()
_GUICtrlEdit_SetSel($hInput_Handle, 0, -1)
EndFunc

Func _selectall()
     _SendMessage(ControlGetHandle("", "", ""), $EM_SETSEL, 0, -1)
EndFunc  ;==>_selectall

 

Thanks in advance

 

Edited by Marcvde

Share this post


Link to post
Share on other sites



Can anybody tell me pls? and who is viewing this topic so much? 

Share this post


Link to post
Share on other sites

Please don't bump your own posts for at least 24 hours.

You could do it this way, just click the part of the date you want to change and click the up/down control.

$DDatePicker = GUICtrlCreateDate("", 5, 5, 186, 21, BitOR($DTS_UPDOWN, $DTS_LONGDATEFORMAT)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<

 


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Okay I understand the rule, Thank you for helping me but it is not exactly what i want. I have uploaded a picture and there you can see what i want. The arrows in the right corner. They need the function.

Thanks in advance

Capture.PNG

Edited by Marcvde

Share this post


Link to post
Share on other sites

Hey Marcvde,

One approach would be to have the date value set in a variable, and manipulate that outside of the control, then apply the new value.... Something like this:

#include<date.au3>
#include<GUIConstants.au3>
$sDate = "2015/09/10"
$hGui = GUIcreate("test date",250,30)
$DDatePicker = GUICtrlCreateDate($sDate, 5, 5, 186, 21,$DTS_LONGDATEFORMAT)
$hbutton_down = GUIctrlCreateButton("<",200,5,20,20)
$hbutton_up = GUIctrlCreateButton(">",225,5,20,20)
GUIsetState(@SW_SHOW)
while 1
    switch GUIgetMsg()
        case $hbutton_down
            $sDate = _DateAdd("D",-1,$sDate)
            GUIctrlSetData($DDatePicker,$sDate)
        case $hbutton_up
            $sDate = _DateAdd("D",1,$sDate)
            GUIctrlSetData($DDatePicker,$sDate)
        case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Cheers

Javi


give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites

Hey javiwhite,

I tried this code but i didn't worked. But thanks for trying to help me.

Does anybody else have a solution for this?

Thanks in advance

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

What do you mean you tried the code and it didn't work? What error messages did you receive?

Running that code exactly as I have posted will work, It's a working reproducer of how to solve your problems, It was never intended to be injected into your code.

EDIT: Seems I need to pay more attention to the thread, Give me 5 minutes.

Cheers 

Javi

 

EDIT: Previous solution implemented into your code, I suggest looking at the example I posted initially so you have a better understanding of how this is working (The main difference however is that your code is OnEvent whereas the example I posted is not)

#include <ButtonConstants.au3>
#include<Date.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>
#include <GUIEdit.au3>

Global $DDatePicker, $IWerkDag, $IBeginTijd, $IEindTijd, $IEdit, $LWerkDag, $hInput_Handle, $sDateVal

Opt("GUIOnEventMode", 1)

$sDateVal = @YEAR & "/" & @MON & "/" & @MDAY
Main()
Func Main()
$Main = GUICreate("Uren registratie Marc van den Elshout", 491, 356, 192, 124)
$Group1 = GUICtrlCreateGroup("", 5, 35, 481, 316)
$BSave = GUICtrlCreateButton("Save", 405, 110, 75, 25)
GUICtrlSetOnEvent($BSave, "Save")
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\Data\"&"right.jpg", 448, 8, 25, 25)
$Pic2 = GUICtrlCreatePic(@ScriptDir & "\Data\"&"left.jpg", 414, 7, 25, 25)
GUICtrlSetOnEvent ($Pic1, "_next")
GUICtrlSetOnEvent ($pic2, "_previous")
$LWerkDag = GUICtrlCreateLabel("Werkdag:", 20, 60, 51, 17)
$LBeginTijd = GUICtrlCreateLabel("Begin tijd:", 20, 87, 50, 17)
$LEindTijd = GUICtrlCreateLabel("Eind tijd:", 20, 115, 44, 17)
$IWerkDag = GUICtrlCreateInput("", 75, 58, 121, 21)
$IBeginTijd = GUICtrlCreateInput("8:00", 75, 85, 121, 21)
$IEindTijd = GUICtrlCreateInput("", 75, 113, 121, 21)
$IEdit = GUICtrlCreateEdit("", 15, 140, 466, 206)
$cSelAll = GUICtrlCreateDummy()
GUICtrlSetOnEvent ($cSelAll,"_SelAll")
Dim $aAccelKeys[1][2]=[["^a", $cSelAll]]
$hInput_Handle = GUICtrlGetHandle($IEdit)
GUISetAccelerators($aAccelKeys)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$BLookUp = GUICtrlCreateButton("Check", 195, 5, 91, 21)
GUICtrlSetOnEvent($BLookUp, "LookUp")
$DDatePicker = GUICtrlCreateDate($sDateVal, 5, 5, 186, 21,$DTS_LONGDATEFORMAT)
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
EndFunc

Func LookUp() ;GUICtrlRead($DDatePicker)
$WerkDag = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "werkdag", "")
$BeginTijd = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "begintijd", "")
$EindTijd = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "eindtijd", "")
$Edit = IniRead (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini", "Uren", "edit", "")
GUICtrlSetData($IWerkDag, $WerkDag )
GUICtrlSetData($IBeginTijd, $BeginTijd )
GUICtrlSetData($IEindTijd, $EindTijd )
GUICtrlSetData($IEdit, StringReplace(IniRead(@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "edit", @error), "{ENTER}", @CRLF))
EndFunc

Func _next()
    $sDateVal = _DateAdd("D",1,$sDateVal)
    GUIctrlSetData($DDatePicker,$sDateVal)
EndFunc

Func _previous()
    $sDateVal = _DateAdd("D",-1,$sDateVal)
    GUIctrlSetData($DDatePicker,$sDateVal)
EndFunc


Func Save()
$WerkDag = GUICtrlRead($IWerkDag)
$BeginTijd = GUICtrlRead($IBeginTijd)
$EindTijd = GUICtrlRead($IEindTijd)
$Edit = GUICtrlRead($IEdit)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "werkdag", $WerkDag)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "begintijd", $BeginTijd)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "eindtijd", $EindTijd)
IniWrite (@ScriptDir & "\Logs\" & GUICtrlRead($DDatePicker) & ".ini" , "Uren", "edit", StringReplace(GUICtrlRead($IEdit), @CRLF, "{ENTER}"))
EndFunc

Func _Exit()
Save()
Exit
EndFunc

While 1
                Sleep(50)
WEnd

Func _SelAll()
_GUICtrlEdit_SetSel($hInput_Handle, 0, -1)
EndFunc

Func _selectall()
     _SendMessage(ControlGetHandle("", "", ""), $EM_SETSEL, 0, -1)
EndFunc  ;==>_selectall

 

Edited by javiwhite
1 person likes this

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Hey Javi,

Thanks for a replie again, I didn't get a error. It just didn't work...

but okay, I will see your new message in a few minutes

Thanks 

Edited by Marcvde

Share this post


Link to post
Share on other sites

hey Javi,

Thank you very much. This is exactly what i wanted. And I know now why it didn't work before .

Thank you,

marcvde

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