PlanetSquires Forums

Support Forums => General Board => Topic started by: Martin Francom on November 18, 2010, 02:33:23 PM

Title: DateTime Picker Control
Post by: Martin Francom on November 18, 2010, 02:33:23 PM
I need a little help with the DateTime Picker control.   I am a bit confused about how to programmatically input a starting date and how to retrieve a data.

I looked in the Functions Library but didn't find information about that control.   Is there a sample program that demonstrates how to use that control?

Your help will be appreciated.  thanks
Title: Re: DateTime Picker Control
Post by: Paul Squires on November 18, 2010, 03:39:40 PM
hi Marty,

Try this code:

http://www.planetsquires.com/protect/forum/index.php?topic=2229.msg17535#msg17535
Title: Re: DateTime Picker Control
Post by: Martin Francom on November 18, 2010, 03:55:34 PM
Quote from: TechSupport on November 18, 2010, 03:39:40 PM
hi Marty,

Try this code:

http://www.planetsquires.com/protect/forum/index.php?topic=2229.msg17535#msg17535


Paul,  Thanks I see how to set the dates.   How do I retrieve the date?   


Dim   DateRange(1)     As SYSTEMTIME    DateRange(0).wYear      = 2000   
DateRange(0).wMonth     = 1   
DateRange(0).wDayOfWeek = 0   
DateRange(0).wDay       = 1   
DateRange(0).wHour      = 0   
DateRange(0).wMinute    = 0   
DateRange(0).wSecond    = 0   
DateRange(1).wYear      = 2005   
DateRange(1).wMonth     = 1   
DateRange(1).wDayOfWeek = 0   
DateRange(1).wDay       = 1   
DateRange(1).wHour      = 23   
DateRange(1).wMinute    = 59   
DateRange(1).wSecond    = 59   
SendMessage hWndControl, %DTM_SETRANGE, %GDTR_MIN Or %GDTR_MAX, ByVal VarPtr
(DateRange(0))   
DateRange(0).wYear      = 2001   
DateRange(0).wMonth     = 1   
DateRange(0).wDayOfWeek = 0   
DateRange(0).wDay       = 1   
DateRange(0).wHour      = 0   
DateRange(0).wMinute    = 0   
DateRange(0).wSecond    = 0   
SendMessage hWndControl, %DTM_SETSYSTEMTIME, %GDT_VALID, ByVal VarPtr(DateRange(0))
Title: Re: DateTime Picker Control
Post by: Jean-pierre Leroy on November 18, 2010, 05:49:27 PM
Hi Marty,

I just one sub and one function for that; a sub to setup the starting date:


Sub DateFileToDateTimePicker(ByVal hWndControl As Dword, ByVal pDateFile As String)
    Local lSysTime As SYSTEMTIME
    lSysTime.wYear  = Val( Left$(pDateFile,4  ))
    lSysTime.wMonth = Val(  Mid$(pDateFile,5,2))
    lSysTime.wDay   = Val(Right$(pDateFile,2  ))
    SendMessage(hWndControl, %DTM_SETSYSTEMTIME, %GDT_VALID, VarPtr(lSysTime))
End Sub


A function to retrieve the date :


Function DateTimePickerToDateFile(ByVal hWndControl As Dword) As String
    Local lSysTime As SYSTEMTIME
    Local lDate    As String
    SendMessage(hWndControl, %DTM_GETSYSTEMTIME, 0, VarPtr(lSysTime))
    lDate = Using$("####",lSysTime.wYear)+Using$("##",lSysTime.wMonth)+Using$("##",lSysTime.wDay)
    Replace Any " " With "0" In lDate
    DateTimePickerToDateFile = lDate
End Function


PS: the DateFile format is YYYYMMDD

Hope that helps.
Jean-Pierre

PS to Paul: you can add these two functions to the Functions Library if needed.
Title: Re: DateTime Picker Control
Post by: Martin Francom on November 18, 2010, 06:37:26 PM
Jean-Pierre,   Thank you.  Yes, that is very helpful.  Thanks

For those interested, I use Paul's and Jead-Pierre's suggestion and build a sample program that demonstrates the use of the  DatePicker Control.   Here attached
Title: Re: DateTime Picker Control
Post by: Richard Kelly on November 30, 2010, 04:58:39 AM
This is what I came up with. The common function is:



%FALSE = 0
%TRUE = 1

Function SelectDate (ByVal hWnd As Long, _
                     ByVal StartingDate As SYSTEMTIME Ptr, _
                     ByRef SelectedDate As SYSTEMTIME) As Long
                     
Local nReturn        As Long

   nReturn = Calendar_Show (hWnd, %TRUE, StartingDate)
   
   Select Case nReturn
   
      Case <> %FALSE
     
         SelectedDate.wYear = Hi(Word, nReturn)
   
         SelectedDate.wMonth = Hi(Byte,Lo(Word,nReturn))
   
         SelectedDate.wDay = Lo(Byte,Lo(Word,nReturn))
         
         nReturn = %TRUE
     
   End Select
   
   Function = nReturn
   
End Function

FF form attached.