Using DTP:IsNone
Using DTP:IsNone
Hi, how do I SET the IsNone value on a TIME DateTimePicker please? I've set the IsNone property in the IDE, and can determine whether or not it is set, but how can I set it? For example:
IF self:oDCDateTimePicker1:IsNone == .t.
self:oDCDateTimePicker1:Value := null_date
else
self:oDCDateTimePicker1:Value := self:server:FIELDGET(#JOBTIME)
endif
Basically I want the code to detect a null_date, and if found set IsNone to TRUE, otherwise FALSE. I can see no obvious way to do it. I've searched the old NG, and here, and of course the VO help files, and IsNone doesn't return anything anywhere that I can see.
Thanks again.
IF self:oDCDateTimePicker1:IsNone == .t.
self:oDCDateTimePicker1:Value := null_date
else
self:oDCDateTimePicker1:Value := self:server:FIELDGET(#JOBTIME)
endif
Basically I want the code to detect a null_date, and if found set IsNone to TRUE, otherwise FALSE. I can see no obvious way to do it. I've searched the old NG, and here, and of course the VO help files, and IsNone doesn't return anything anywhere that I can see.
Thanks again.
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
Using DTP:IsNone
Jeff,
Maybe somebody with more experience with the VO DTP should jump in if I am off-track on this one.
Ok, long time ago that I worked with VO, but from a .NET perspective, which I believe is similar. There is no such thing as a NULL_DATE in Windows/.NET, the way you do it is to set the Is None style on a DTP, which then have a CheckBox next to it, so by default it will populate the "NowTime", but you need then to check if the CheckBox is ticked to determine if you want to use the DT value or store a NULL/NIL. IsNone is a "ACCESS" property so you cannot assign it.BiggyRat wrote:Hi, how do I SET the IsNone value on a TIME DateTimePicker please? I've set the IsNone property in the IDE, and can determine whether or not it is set, but how can I set it? For example:Basically I want the code to detect a null_date, and if found set IsNone to TRUE, otherwise FALSE. I can see no obvious way to do it. I've searched the old NG, and here, and of course the VO help files, and IsNone doesn't return anything anywhere that I can see.Code: Select all
if self:oDCDateTimePicker1:IsNone == .t. self:oDCDateTimePicker1:Value := null_date else self:oDCDateTimePicker1:Value := self:server:FIELDGET(#JOBTIME) endif
Maybe somebody with more experience with the VO DTP should jump in if I am off-track on this one.
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
Using DTP:IsNone
Gotcha Wolfgang. thank you, but I can't seem to access any "checkbox like" methods in the DTP... The null_date idea actually came from the old NG... It seems once the user clicks on the "checkbox" it stays true for all records, even if a time has been assigned.. that's what I'm trying to fix.I need to have IsNone true if a null date, or False if there is a value in the JOBTIME field.
- lumberjack
- Posts: 727
- Joined: Fri Sep 25, 2015 3:11 pm
- Location: South Africa
Using DTP:IsNone
Hi Jeff,
IsNone indicates if you have have set the CheckBox to show.
Try retrieving SelectedDate and SelectedTime with the CheckBox Checked/Unchecked. So if it returns a NIL from my reasoning it means the CheckBox is not ticked, otherwise it will always return a value.
I think you confusing IsNone with "IsEmptyDate". IsNone is to control the visibility of the CheckBox and nothing else. If IsNone is true the CheckBox is shown.
From the MicroSoft Win32 docs...BiggyRat wrote:Gotcha Wolfgang. thank you, but I can't seem to access any "checkbox like" methods in the DTP... The null_date idea actually came from the old NG... It seems once the user clicks on the "checkbox" it stays true for all records, even if a time has been assigned.. that's what I'm trying to fix.I need to have IsNone true if a null date, or False if there is a value in the JOBTIME field.
Code: Select all
DTS_SHOWNONE
It is possible to have no date currently selected in the control. With this style, the control displays a check box that is automatically selected whenever a date is picked or entered. If the check box is subsequently deselected, the application cannot retrieve the date from the control because, in essence, the control has no date. The state of the check box can be set with the DTM_SETSYSTEMTIME message or queried with the DTM_GETSYSTEMTIME message.
Try retrieving SelectedDate and SelectedTime with the CheckBox Checked/Unchecked. So if it returns a NIL from my reasoning it means the CheckBox is not ticked, otherwise it will always return a value.
I think you confusing IsNone with "IsEmptyDate". IsNone is to control the visibility of the CheckBox and nothing else. If IsNone is true the CheckBox is shown.
______________________
Johan Nel
Boshof, South Africa
Johan Nel
Boshof, South Africa
Using DTP:IsNone
I am not sure what you want to achieve, is this on initial form (window) load? If so, why not set the DTP to whatever date value you want in the DataWindow PostInit() or Show() method.
Anyway, even though the following does not make sense in a real application, you can use the data window CommonControl Events properties window, then click the DateTimeSelChanged event which is triggered when the checkbox is clicked.
The DTP becomes grayed out but its value is still visible when unchecked. The oDateTimeSelectionEvent:SelectedDate:SelectedDate will be NULL_DATE.
Jamal
Anyway, even though the following does not make sense in a real application, you can use the data window CommonControl Events properties window, then click the DateTimeSelChanged event which is triggered when the checkbox is clicked.
The DTP becomes grayed out but its value is still visible when unchecked. The oDateTimeSelectionEvent:SelectedDate:SelectedDate will be NULL_DATE.
Code: Select all
method DateTimeSelectionChanged(oDateTimeSelectionEvent) class YourDataWindow
super:DateTimeSelectionChanged(oDateTimeSelectionEvent)
//Put your changes here
if oDateTimeSelectionEvent:SelectedDate = null_date
InfoBox{, "NULL_DATE", "Date: " + DToC(oDateTimeSelectionEvent:SelectedDate) }:show()
ELSE
self:oDCDateTimePicker1:Value := self:server:FIELDGET(#JOBTIME)
ENDIF
return NIL
Jamal
Using DTP:IsNone
Hi Jamal, the exact scenario is this:
I have a dtp on my form. When I use SKIP(1) or SKIP(-1) to move through the records, the DTP stays at whatever it was set to previously. So, what I mean by that is say I set the DTP to "None" i.e. checkbox is UNCHECKED and I skip to the next record, the unchecked status doesn't change with the next record even if there is a time in that field. The time changes with the record, but the "checked" status does not.
The purpose is not all jobs have times. Those that do, great show the time, but those that don't need to show NONE.
I have a dtp on my form. When I use SKIP(1) or SKIP(-1) to move through the records, the DTP stays at whatever it was set to previously. So, what I mean by that is say I set the DTP to "None" i.e. checkbox is UNCHECKED and I skip to the next record, the unchecked status doesn't change with the next record even if there is a time in that field. The time changes with the record, but the "checked" status does not.
The purpose is not all jobs have times. Those that do, great show the time, but those that don't need to show NONE.
Using DTP:IsNone
I was expecting this thread to drag on like the other threads! But you are in luck! I found a post at
https://groups.google.com/forum/?nomobi ... mVZzJRKSMJ.
I adjusted the class to avoid WORD conversion issues. Don't change the class if you are not comfortable with win32 stuff.
Just let your datetimepicker control inherit from MyDatePicker class and set the SelectedDate based on your condition and the checkbox will change automatically. Sample at bottom.
Sample call:
https://groups.google.com/forum/?nomobi ... mVZzJRKSMJ.
I adjusted the class to avoid WORD conversion issues. Don't change the class if you are not comfortable with win32 stuff.
Just let your datetimepicker control inherit from MyDatePicker class and set the SelectedDate based on your condition and the checkbox will change automatically. Sample at bottom.
Code: Select all
CLASS MyDatePicker INHERIT DateTimePicker
ACCESS SelectedDate CLASS MyDatePicker
LOCAL lpSysTime is _WINSYSTEMTIME
LOCAL dResult as date
MemClear( @lpSysTime , _sizeof( _WINSYSTEMTIME ) )
IF DateTime_GetSystemTime( self:handle() , @lpSysTime ) == GDT_VALID
dResult := ConDate( lpSysTime.wYear, lpSysTime.wMonth, lpSysTime.wDay )
ELSE
dResult := null_date
ENDIF
RETURN dResult
ASSIGN SelectedDate( dNewDate ) CLASS MyDatePicker
LOCAL lpSysTime is _WINSYSTEMTIME
LOCAL dwFlag as DWORD
MemClear( @lpSysTime , _sizeof( _WINSYSTEMTIME ) )
IF dNewDate = null_date
dwFlag := GDT_NONE
ELSE
lpSysTime.wYear := word(Year( dNewDate ))
lpSysTime.wMonth := word(Month( dNewDate ))
lpSysTime.wDay := word(Day( dNewDate ))
dwFlag := GDT_VALID
ENDIF
DateTime_SetSystemTime( self:Handle() , dwFlag , @lpSysTime )
RETURN dNewDate
FUNCTION DateTime_GetSystemtime( hdp as ptr , pst as _WINSYSTEMTIME ) as DWORD PASCAL
RETURN DWORD( _cast , SendMessage( hdp , DTM_GETSYSTEMTIME , 0 , LONG( _cast , pst ) ) )
FUNCTION DateTime_SetSystemtime( hdp as ptr , gd as DWORD , pst as _WINSYSTEMTIME ) as LOGIC PASCAL
RETURN LOGIC( _cast , SendMessage( hdp , DTM_SETSYSTEMTIME , DWORD( _cast , gd ) , LONG( _cast , pst ) ) )
Code: Select all
// SAMPLE calls
METHOD BlankDateButton( ) CLASS MyForm
// the checkbox will be unchecked and control is dimmed.
self:oDCDateTimePicker2:SelectedDate := null_date
RETURN NIL
METHOD SetDatesButton( ) CLASS MyForm
// the DTP checkbox will be enabled and DTP will be active
self:oDCDateTimePicker2:SelectedDate := Today() + 1
RETURN NIL
Using DTP:IsNone
I found that code before I posted here Jamal, and it didn't work, just as it doesn't work now. I may be wrong (I usually am it seems) but the above code seems to be fixing DATE problems, not TIME, which is my problem. This seems to be borne out by the debugger where the assigning of null_date returns an error (it's wanting a null_STRING)
- Attachments
-
- DTP Crash.JPG (44.21 KiB) Viewed 679 times
Using DTP:IsNone
Here the modified class to handle TIME. Just inherit from MyTimePicker. See attached video.
Code: Select all
CLASS MyTimePicker INHERIT DateTimePicker
ASSIGN SelectedTime( cNewTime ) CLASS MyTimePicker
LOCAL lpSysTime is _WINSYSTEMTIME
LOCAL dwFlag as DWORD
local dToday := Today() as date
MemClear( @lpSysTime , _sizeof( _WINSYSTEMTIME ) )
IF cNewTime == null_string
dwFlag := GDT_NONE
ELSE
lpSysTime.wYear := word(Year( dToday ))
lpSysTime.wMonth := word(Month( dToday))
lpSysTime.wDay := word(Day( dToday ))
// the following assumes a time format hh:mm:ss for example: 05:20:00 in 24 hour format
// assign example:
// self:oDCDateTimePicker3:SelectedTime := "23:20:00"
lpSysTime.wHour := word(Val(Left(cNewTime,2))) // adjust your parsing code here
lpSysTime.wMinute := word(Val(SubStr(cNewTime, 4,2))) // adjust your parsing code here
lpSysTime.wSecond := 0
lpSysTime.wMilliseconds := 0
dwFlag := GDT_VALID
ENDIF
DateTime_SetSystemtime( self:Handle() , dwFlag , @lpSysTime )
RETURN cNewTime
ACCESS SelectedTime CLASS MyTimePicker
LOCAL lpSysTime is _WINSYSTEMTIME
LOCAL cResult as string
MemClear( @lpSysTime , _sizeof( _WINSYSTEMTIME ) )
// must pad 0 to time portions to proper 24 hour time format. Jamal
IF DateTime_GetSystemtime( self:handle() , @lpSysTime ) == GDT_VALID
cResult := PadL(NTrim(lpSysTime.wHour),2,"0") + ":" + PadL(NTrim(lpSysTime.wMinute),2,"0") + ":" + PadR(NTrim(lpSysTime.wSecond),2, "0")
ELSE
cResult := null_string
ENDIF
RETURN cResult
FUNCTION DateTime_GetSystemtime( hdp as ptr , pst as _WINSYSTEMTIME ) as DWORD PASCAL
RETURN DWORD( _cast , SendMessage( hdp , DTM_GETSYSTEMTIME, 0, LONG( _cast , pst ) ) )
FUNCTION DateTime_SetSystemtime( hdp as ptr , gd as DWORD , pst as _WINSYSTEMTIME ) as LOGIC PASCAL
RETURN LOGIC( _cast , SendMessage( hdp , DTM_SETSYSTEMTIME, DWORD( _cast , gd ), LONG( _cast , pst ) ) ) [attachment=0]datetimepicker.gif[/attachment]
- Attachments
-
- datetimepicker.gif (382.19 KiB) Viewed 679 times
Using DTP:IsNone
Thanks Jamal, I can get it to work as you've shown, but that's not really my problem. Here's a link to a video:
https://cl.ly/2283012461df
https://cl.ly/2283012461df