Using a CalendarTimeChooser class button, with an instance on my window.
I can read the class instance property with a Button Action Event :
msgbox str(QS_PushButton1.CalTimeChooser.GoDate)
Is it possible to have the text in a label ( label is on the window, not part of the class ) update with the GoDate property when the property in the instance of the class changes, or can it only be done using a timer on the window that reads the GoDate property ( much like the PushButon action above ) ?
After an entire day trying to solve this, I would appreciate the ‘idiots instructions’ if it is possible.
There is an event called SelectedDate (and one called SelectedTime). Put your code which updates the label in there. A notification center is an overkill in this case IMHO.
in the class, created a Property called GoActive, Boolean, Default False
in the Window, added a timer, interval = 500, status = Off.
Sub Action()
self.label3.text = str(QS_PushButton1.CalTimeChooser.GoDate)
if QS_PushButton1.CalTimeChooser.GoActive = false then
timer2.enabled = false
end if
Tcounter = Tcounter + 1
label4.text = str(Tcounter)
End Sub
In the QS_PushButton1 Action Event, set the Timer mode to multiple.
So the QS_PushButton1 Action displays the chooser ( which I changed to a Modal window ) and starts the timer. The timer then checks if the GoActive property is True ( indicates the Chooser window is still open ) and when it changes to False, gets the GoDate value from the instance, and updates the label.text, and then disables the timer.
Hope this helps someone else, although I am sure there is likely a better solution for the experienced coders.
[quote=190600:@Eli Ott]Put this line in the SelectedDate event of CalTimeChooser:
Self.Label3.Text = Str(Me.GoDate)
Hi Eli
I have looked through the Cal-Time folders and find the following with SelectedDate. I do not know which to add it to. Could you please guide me ?
Cal-Time Chooser Window
DateTimeWindow
Properties
SelectedDate As Date
Get
return Date_Time_Container1.SelectedDate
End Get
Set
Date_Time_Container1.SelectedDate=value
End Set
Cal-Time Chooser Custom Classes
CalendarButtonClass
Properties
SelectedDate As Date
Cal-Time Chooser Container Controls
Calendar_Container
Event Definitions
Event SelectedDate(inSelectedDate as Date) // this does not allow editing
Cal-Time Chooser Container Controls
Date_Time_Container
Properties
SelectedDate As Date
Get
dim d as new date(Calendar_Container1.Calendar1.SelectedDate)
if Time_Container1.Time_AMPM="AM" then
if Time_Container1.Time_Hour="12" then
d.Hour=0
else
d.Hour=val(Time_Container1.Time_Hour)
end if
else
if Time_Container1.Time_Hour="12" Then
d.Hour=val(Time_Container1.Time_Hour)
else
d.Hour=val(Time_Container1.Time_Hour)+12
end if
end if
d.Minute=val(Time_Container1.Time_Minute)
Return d
End Get
Set
Calendar_Container1.Calendar1.SelectedDate=value
if value.Hour<12 then
Time_Container1.Time_AMPM="AM"
else
Time_Container1.Time_AMPM="PM"
end if
Time_Container1.Time_Minute=format(value.Minute,"00")
if value.Hour=0 then
Time_Container1.Time_Hour="12"
elseif value.Hour>12 then
Time_Container1.Time_Hour=str(value.Hour-12)
else
Time_Container1.Time_Hour=str(value.Hour)
end if
End Set
Cal-Time Chooser Container Controls
Date_Time_Container
Controls
Calendar_Container1
Sub SelectedDate(inSelectedDate as Date)
// THIS EVENT IS PASSED THE SELECTED DATE AS A DATE OBJECT
// EXAMPLE RESULTS USAGE:
//MsgBox "The selected date is: " + inSelectedDate.SQLDateTime
//MsgBox "The selected date is: " + inSelectedDate.AbbreviatedDate
End Sub
[quote=190600:@Eli Ott]Put this line in the SelectedDate event of CalTimeChooser:
Self.Label3.Text = Str(Me.GoDate)
Doesn’t ‘self’ refer to the window that the property is linked to ?
In the case of the Chooser, it would be the window that contains the calendar and / or clock.
So we can not refer to Label3 being located on ‘self’ because Label3 is on the initial window where the Chooser Button Instance was created in the IDE.
Then I would create a constructor in the chooser window like that:
Class ChooserWindow
Private Property mOwnerWindow As Window
Sub Constructor(ownerWindow As Window)
mOwnerWindow = ownerWindow
End
...
and call it in the ‘owner’ window as follows:
Dim chooser As New ChooserWindow(Self)
Then you will have access to the caller and you can do:
[quote=190687:@Eli Ott]Then I would create a constructor in the chooser window like that:
[/quote]
Thank Eli
So if I understand correctly, that code is going to :
the Constructor is like a Class Instance Initialization / Creation event, that fires up when the instance is created.
This Constructor will receive a handle of the window that created the instance, and save that in the property ownerWindow
the ‘parent’ window creates a New instance of the class, and passes it’s own handle to the instance, to be received by the Constructor.
the class instance uses that handle mOwnerWindow like an AbsolutePath to the window that created the instance ( and by extension is able to access the Label3.Text )