Page 1 of 1

How can I set DateGadget to 19.11.1967 and let it editable

Posted: Fri Oct 28, 2005 12:35 am
by guruk
Really, I do not understand this DateGadget... only from 1971.. but inside I can scroll through much deeper. So I only like to set a Date.
for eg. 19.11.1967 Save it as String to my database and then fill the Gadget again later... but so that I can still update it only the Way the DateGadget is for.

When I tried with SetGadgetText.. it putted the Text, but was not more editable.. and when I do with SetGadgetState.. than no year under 1970 possible?!?!

Please help

Posted: Fri Oct 28, 2005 1:24 am
by Sparkie
The native PB date library can only handle dates from 1970 to 2034. For Windows apps, you can use the API to accomplish your task.

Code: Select all

#DTM_GETSYSTEMTIME = $1001 
#DTM_SETSYSTEMTIME = $1002 
#GDT_VALID = 0

Procedure.l SetDate(gadget, year, month, day, hour, minute, second) 
  sTime.SYSTEMTIME\wYear = year 
  sTime\wMonth = month 
  sTime\wDay = day 
  sTime\wHour = hour 
  sTime\wMinute = minute 
  sTime\wSecond = second 
  SystemTimeToFileTime_(sTime, @fTime.FILETIME) 
  FileTimeToSystemTime_(fTime, @sTime) 
  SendMessage_(GadgetID(gadget), #DTM_SETSYSTEMTIME, #GDT_VALID, sTime)
EndProcedure 

If OpenWindow(0, 0, 0, 220, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered,"DateGadget < 1970") And CreateGadgetList(WindowID()) 
  DateGadget(0, 10, 10, 200, 20, "%dd.%mm.%yyyy",Date())
  ; --> Use SetDate procedure for setting dates < 1970
  SetDate(0, 1967, 11, 17, 0, 0, 0) 
  MessageRequester("Date as string is:", GetGadgetText(0))
  Repeat 
    event = WaitWindowEvent() 
  Until event = #PB_Event_CloseWindow 
EndIf 
End

Posted: Thu Feb 21, 2008 6:11 pm
by DoubleDutch
Here is the compliment to that (very handy) routine...

Code: Select all

Procedure GetDate(gadget,part=#PB_Date_Year)
	sTime.SYSTEMTIME
	SendMessage_(GadgetID(gadget),#DTM_GETSYSTEMTIME,#GDT_VALID,sTime)
	SystemTimeToFileTime_(sTime,@fTime.FILETIME) 
	FileTimeToSystemTime_(fTime,@sTime)
	Select part
		Case	#PB_Date_Day
			result=sTime\wDay
		Case	#PB_Date_Month
			result=sTime\wMonth
		Default
			result=sTime\wYear
	EndSelect
	ProcedureReturn result
EndProcedure
:)