Using VB.Net 2010 (Pro)
I have a form that contains various textboxes, comboboxes and a couple of maskedtextboxes. These last ones are giving me fits.
The value in the maskedtextboxes are all formatted as shortdate. It's possible for them to be empty (no date). Occassionally there will be a date that the user must remove (make it blank).
I'd like to show if a form is "dirty", that is if the user has changed the data from the last time it was loaded or saved. To that end, I have a structure where I keep all the values from the various controls on the form. Everything works fine except for those darned maskedtextboxes, when they are empty. During the checkForDirty() routine, I get to a line such as:
bDirty = bDirty Or CDate(txtRegExpiry.Text) <> IIf(IsNothing(.Reg_Expr), "", .Reg_Expr)
which, if the maskedtextbox is empty will throw the error:
Conversion from string " / /" to type 'Date' is not valid.
Note: It is the control (CDate(txtRegExpiry.Text))
that is specfically throwing the error.
I tried removing the CDate() but that didn't help.
So, the question is, how do I compare a maskedtextbox to a variable that can either be a date or nothing without throwing an error?