Storing/retrieving dates in TextBoxes

OK, something I thought would be straight forward is giving me the run-around.


So, one part of my application stores the current date+time in a textbox like this:

DIM d as New Date TextBox1.Text = d.SQLDateTime
And another part of my application needs to read in that information (at a later stage) and compare it with another date+time stored in the same way, in a different text box:

DIM CurrentDate as Date DIM converted as Boolean converted = ParseDate(TextBox1.Text, CurrentDate) Label1.Text = Str(CurrentDate)
The moment I run this bit of code, the debugger kicks in and tells me that CurrentDate is “nil” and that converted is “False”.

I could be doing something really stupid here, but I kinda thought that if I stored a SQLDateTime in a textbox that I would be able to retrieve this information from the text box and convert it back into a date with relative ease. I would prefer to use dates (and SQLDates so there’s always a consistent formatting) instead of messing around manually parsing the text to figure out which bit is the year, month, day, hour, minute & second.

What am I doing wrong?

Dim  CurrentDate as new Date

is what you want.

For the next step consider saving your original date in a property which then can be accessed directly. And the step afterward should consider either saving the data to a central location or broadcasting it from the first location to the second one. Just mentioning this when your app is growing.

AFAIK, parseDate does not work with SQLDate(Time). Rather than using parseDate, you could instantiate a new date object and assign the value:

Dim CurrentDate as new Date CurrentDate.SQLDateTime=TextBox1.Text
However, I’d strongly second Beatrix’s suggestion to store the value in a window property instead of (or in addition to) the control:

[code]self.mTheDate= new Date
TextBox1.Text = mTheDate.SQLDateTime

Dim CurrentDate as new Date

I posted a control that I created here:

It might work for you. It’s not crazy complicated…