CalendarControl default date?

just a quick question:

Does anyone here have the CalendarControl from piDog, and know if it is possible to have the default start date populated from a textfield or variable string in the main window?

My boss is nagging me and needs an answer by the morning - so although I have emailed Jim from piDog, I dont expect an answer from him until tomorrow afternoon. Therefore, I thought I would try on here in the meantime, and see if anyone knew the answer (and if so, how).

Thanks guys.

It should work.

Control Open Event

dim d As New Date
d.year = d.year + 1

me.selectedDate = d


Just set the selectedDate wherever it makes sense in your startup process.

Thank you.
I am however, still having trouble getting the default date populated from other sources.

My listbox has a column which has the value 25/12/2014, and I would like my calendarcontrol’s start date to be that value?

[code]Dim s() As String

s=Split(Listbox1.cell(r,c),"/") // seperator between day, month and year = “/”

Dim d As New date( val(s(2)) , val(s(1)) , val(s(0)) ) //s(2) = year; s(1) = mont; s(0) = day

me.selectedDate = d[/code]

Thank you very much Andre.
What about if I wanted to do the opposite and convert the Date to a String?

I have tried the following line of code:


But I get an error “Expected String but got Date”

I then tried:

fldDate.text=myCalendarClass.SelectedDate as String


Also tried:

Dim myCurrentDate as String = myCalendarClass.SelectedDate fldDate.Text = myCurrentDate

The date object is returning the value 25/12/2014 and I need to convert that into a string?

Thank you for all your help - it is very much appreciated!

Although the date object is already in the ShortDate format - if I convert the code to:


it works fine?

You should really read the documentation on date first:

Not to offend you, but you are stumbling around just like I used to do, and the reason seems to be that you don’t even know what type something is.

Of course it fails when you try to stuff a date object into a string. So look at the documentation and pay particular attention to what type each propert is.

It reminds me of physics in school where some people got “units” (you can’t stuff inches into ounces) and some don’t.


Seems I’m becoming more like Charles :wink:

In case you don’t know whom I’m referring to: he is one of the Xojo demigods, his answers are like the oracle of Delphi, but you better listen to him because he KNOWS. But what he mostly knows is that simply giving you the solution isn’t really helping you become a better programmer. It is better to tell you where to find the solution and let you work it out for yourself. THAT’S what helps you become a better programmer :wink:

No, it isn’t. Don’t confuse the date object with one of its properties.

The date object has a string property called ShortDate which contains the date in a certain formar as specified by the operating system.

I am not trying to stuff anything into anything? I was trying to convert a Date into a String.

If I got an error stating “expected String but got a Date”, then I am being told that the 2 formats are different.
therefore the code examples I tried, were trying to convert that Date value into a string value, and then display it in a TextField.

All 3 of my attempts made perfect sense to me, as they were different ways of saying "Take the date object, make the contents (properties) a Text only string, and then put it into a TextField.

Yes - I am only a VERY part-time user of Xojo, and DO NOT understand a lot of concepts, BUT I do always attempt to find the solution myself - hence my attempts above. In fact I often spend days trying different solutions before I ask for help.

If you know where to look in the Language Reference, it is much easier - BUT, If you have no idea what you need to be looking for, then it is impossible :frowning:

I totally agree with you - just giving someone the solution doesn’t really help the person, as they still won’t really understand the concept.

I did read the Language Reference on Dates - but there was nothing there on converting from one type to another, so I was stuck.

Anyway - no offence was taken - I just wanted to clarify that I did try to solve the problem myself.

Thank you for your guidance, and I appreciate all comments. :slight_smile:

[quote=70227:@Richard Summers]Markus
I am not trying to stuff anything into anything? I was trying to convert a Date into a String.

If I got an error stating “expected String but got a Date”, then I am being told that the 2 formats are different.[/quote]
Actually that error tells you that you were indeed trying to “stuff” a round peg (a date object) into a square hole (a string).

An object has properties that you can access. Some are read-only, others you can read and set. That is what you need to do here.

In other cases there are functions which convert from one SCALAR type to another, like VAL to convert from string to integer.

If you read the documentation on date then you need to pay particular attention to what type the date properties are, which ones you can only read, which ones you can set.

Thanks Markus.

I think this is also a case of you speaking in technical terms and me speaking in layman’s terms :slight_smile:

I understand that the Date object is like a container. This container holds Integer values for the properties such as seconds, minutes, hours etc. etc.

Where I went wrong, is I thought that the following code:


would take the combined values stored in “SelectedDate”, and then display them as a String in the TextField.
I did not realise that I needed to specifically set those values to the “.ShortDate” String format, at the end of the code, before I could do this.

I presumed that as “SelectedDate” contained the values 25 12 2014, I could therefore simply display them as a String.

Hope that made more sense to you, and you can understand where I was coming from.

Once again, thank you for all your help - the problem is now solved.

Schoene tag noch ! :slight_smile: :slight_smile:

But it doesn’t. SelectedDate contains a date object. That date object has integer properties like day, month, year which contain the values you are after.

Conceptual problems arise when users mix up an object with the properties they contain (or even worse the property values). An example of that is when users try to compare two dates like this

If currentDate = todaysDate then

When in reality they want to know if both date objects have the same values.

What the above code is doing is ask if the two objects are identical to each other, not whether they contain the same date values.

Arggggghhhhhhhh :frowning:

Ok, as an example - lets say todays date is christmas day.

If I typed:

Dim CurrentDate as New Date

I would expect a Date object called CurrentDate to be created, with the value 25 for the day property, 12 for the month property, and 2014 for the year property.

Are you saying then, that CurrentDate would NOT contain these values for those properties, BUT INSTEAD, CurrentDate would contain a date object that contains those values for the properties?

I personally, would expect CurrentDate to be the Date object - but If I have understood you correctly: CurrentDate is at the top of the hierarchy, then a date object, then the values for the properties.

So basically:

Dim CurrentDate as New Date

Is saying - Create a top level hierarchy object called CurrentDate, and place inside that, a Date object containing those values.

If I am correct so far, then:

Dim CurrentDate as New Date

seems to be a bit of a misnomer due to the word AS. The word AS implies that CurrentDate will be the date object, as opposed to an object above it.

Just when I think I understand something - it seems I don’t :frowning:

CurrentDate is the name of a variable of type date.

In that sense CurrentDate IS the date object in the same way that Richard Summers is you. [Note that Richard Summers is also the value of the name property of the Richard Summers person. You might change the name property but it is still the same Richard Summers person].

However the date object doesn’t contain VALUES, it contains PROPERTIES which have certain values.

I was objecting to “I presumed that as “SelectedDate” contained the values 25 12 2014” as this is not correct.

In your last post you said:

so this line of text from my previous post is correct then?

Yes, that is correct.

The mixup of object properties and values is the reason you originally expected


to work. Spoken language lets you get away with a lot of things as we know what the other person means, but the computer doesn’t.

Danke Sehr Markus!
Sie waren sehr hilfreich und dafur bin Ich mich sehr dankbar!