CalendarTimeChooser get the Selected Date

I am starting to understand the options in the CalendarTimeChooser and making progress.

But something I can’t understand, and hope someone can educate me on this.

Steps …

I used the sample in the docs to create a button class QS_PushButton

Next added an instance of the button class to my window and named it QS_PushButton1 ( super = QS_PushButton )

I wanted to be able to set specific options for each instance of the button, so did the following :

  1. moved the line :
CalTimeChooser = New DateTimeWindow

to the start of the Method : mSetOptions in the class

  1. deleted the Action event from the QS_PushButton events in the class

  2. dragged button class QS_PushButton to the window, created QS_PushButton1 ( Super = QS_PushButton )

  3. added an Action event to the instance of the class ( QS_PushButton1 ) :

Sub Action()

  QS_PushButton1.mSetOptions  // use the default options from the QS_PushButton class

  // now modify only the options that I want to change
  QS_PushButton1.CalTimeChooser.Cancel_Button.caption = "zz"
  QS_PushButton1.CalTimeChooser.VisiblePickers = Date_Time_Container.PickerElements_CalendarOnly
  QS_PushButton1.CalTimeChooser.Date_Time_Container1.Calendar_Container1.RecurringCanvas1.visible = false

End Sub

At this point, everything is working perfectly.
I can change options in mSetOptions to affect all instances of the button, and change options in QS_PushButton1 Action Event to change options in the specific button’s chooser only.

Next I want to get the selected date from the Chooser.

So here’s what I did :
In the CLASS, changed the following :
in the Cancel_Button event, changed the code to :

me.window.close

Added a Public Property to the DateTimeWindow in the class :

GoDate As Date

In the Finished_Button event, changed the code to :

GoDate = SelectedDate
me.window.Close

On my window, next to the QS_PushButton1, added a standard push button :

Sub Action()

  // this line will work and displays the Date stored in the GoDate property of the instance
  msgbox str(QS_PushButton1.CalTimeChooser.GoDate)
  
  // the following lines do not work - NilExceptionError
  msgbox str(QS_PushButton1.CalTimeChooser.SelectedDate)
  msgbox str(QS_PushButton1.CalTimeChooser.Date_Time_Container1.SelectedDate)

End Sub

So on my window, Click on QS_PushButton1 causes the Action Event, sets the options, and displays the Chooser.
On the Chooser window, Click on the required Date, then Click on ‘Select’ to close the Chooser window.

When I then Click on PushButton1, the first MsgBox displays ( using the GoDate property of the class instance ) but the other lines ( using the SelectedDate property ) fail with NilExceptionError.

Why ?

Dave is this a new issue or the one you solved and told me about over email yesterday?

Thanks!

Hi Mike

This is a bit of an ‘extension’ from the problem that we discussed on e-mail.

I didn’t want to hassle you on e-mail unnecessarily when we have this great forum available.

Yesterday I managed to get the class button modified so that I could use the class to set all of the common options for different Choosers, but be able to change other options with the Action event of the instance of the button on the window.

That is still working.

My next step was to try and get the return selected date from the properties of the instance.

As you’ll see in this code, I could not see how to read the SelectedDate, unless I first copied the date to the property GoDate.

Sub Action()

  // this line will work and displays the Date stored in the GoDate property of the instance
  msgbox str(QS_PushButton1.CalTimeChooser.GoDate)
  
  // the following lines do not work - NilExceptionError
  msgbox str(QS_PushButton1.CalTimeChooser.SelectedDate)
  msgbox str(QS_PushButton1.CalTimeChooser.Date_Time_Container1.SelectedDate)

End Sub

Another odd thing happened as well, and it may be something in the code, possibly related to the local PC date / time settings ?

The line in mSetOptions :

CalTimeChooser.Date_Time_Container1.Time_Container1.TimeMode =24

was adding exactly 12 hours to the SelectedDate.

The time on the clock shown in the Chooser window was correct to the PC system time, but the result was +12 hours which causes the date to increase 1 day.

The code that displays the message is in the Finish_Button Action Event :

  msgbox SelectedDate.LongDate + " -- " + SelectedDate.LongTime
  GoDate = SelectedDate
  GoActive = False
  me.window.Close

OK. I have some progress on this.

I had set code in the Finished_Button Action event to :

me.window.Close

When I changed the .Close to .Hide, then the code :

msgbox str(QS_PushButton1.CalTimeChooser.SelectedDate.LongDate)

works, and displays the date.

So it looks like the cause of the ‘error’ was that I had closed the window created by the instance of the button ( QS_PushButton1 ), and that must have closed the SelectedDate property.

But at the same time, the GoDate was still working. The only difference that I can see between SelectedDate and GoDate is that SelectedDate contains ‘Get’ and ‘Set’ code, so the code in the ‘Get’ must be inaccessible when the instance window is closed.

a-ha. I think that the ‘penny has dropped’ for me on this.

Can anyone please confirm if my thinking on this sounds correct ?

Up until this point wit my very limited and very short exposure to Xojo, I have worked with basic instances of classes which are loaded / created at runtime, with code like ;

dim QS_PushButton1 as New QS_PushButton
QS_PushButton1.show

// and later closed with :
me.window.Close

// and again created if I needed another instance of the button.

But now we are getting fancy, and the Chooser button is created in the class, and then dragged to the Window in the IDE.

If my thinking is correct, this means that the instance of the button ( QS_PushButton1 ) is created as soon as the window is opened / loaded, and will be unloaded / destroyed when the window closes, same as all the other controls on the window.

Therefore, I should never close that IDE created instance in the code during normal code execution, as I may need to use it again on the window, and still want to access its properties.

So while the ‘New’ instance created at runtime is a : Load / UnLoad, Open / Close, create / destroy type of instance, the instance dragged to the window in the IDE is a case of : this instance was created with the window, don’t open / New / close, but instead just hide / show the window for the class.

If this is correct, then it explains why I could not read the :

QS_PushButton1.CalTimeChooser.SelectedDate.LongDate

from the main window after I had .closed the Chooser instance window. By using .close I have destroyed the instance, and it’s properties. Using .hide keeps the instance alive, just not visible, so the code in the window can still read the properties of the instance.

Great work Dave! It looks like you are on the right path to your custom interface for the Calendar/Time chooser! :slight_smile:

Thanks Mike

Took me a long time to understand this in my limited / basic terms.

Did you have any time to look at the 12 / 24 hour problem mentioned earlier in this post that was adding a day to the SelectedDate and 12 hours to the SelectedTime ? Am hoping that you can easily reproduce this and isolate the cause.

Dave I haven’t yet I apologize and I am confident I can reproduce it. I had a podcast with Paul this morning and customer stuff since then. I will this weekend for sure.

Thank you for the support Dave!
Mike

[quote=190675:@Mike Cotrone]Dave I haven’t yet I apologize. I had a podcast with Paul this morning and customer stuff since then. I will this weekend for sure.

Thank you for the support Dave!
Mike[/quote]

Thanks Mike. And please never apologize - you are helping us here. I fully understand. No rush and shouldn’t affect what I am using the chooser for.

I think as coders we all appreciate to get any feedback of any potential bugs, and at the same time hate the task of having to track it down, with 95% of the cases being user error in the first place.

Reminds me of the time I spent 3 days trying to find the cause of some graphs not printing in a VB app, with only the vertical and horizontal axis lines and labels printing. They were in black, the rest in color, the customer was color blind ( told me this after 3 days ) and his kids had used the printer for a school project and not reset it back to greyscale.

14 years later and it is still burned in my memory like it was yesterday.