Date validation routine problems
I have not found MessageBox to be very well behaved in regards to working
well with other controls' events (this in VB3). Specifically, I recall
that after a MessageBox call, correct events were not firing on my TrueGrid
control; I actually wrote my own MessageBox equivalent to get around this
problem (it was very intractable).
Have you thought about waiting until the user completes the form, then just
beeping and setting focus to the offending text box (maybe with a red
status bar text on the bottom of the form)? I know this seems like
cheating, but, in actuality, I think most users would rather not have their
typing flow interrupted until they complete an input form. What's
important for quick data entry is uninterrupted flow and a predictable
sequence of events (this is why it's usually not a good idea to have fields
that automatically advance to the next field when they are full, not
requiring a tab).
Quote:
> As part of a Visual Basic 4.0 Pro project, I created a form with several
textboxes and lables. One of the textboxes
Quote:
> (txtBirthDate) will be used to enter a date. I have written the
following code to check the validity of the date upon
Quote:
> the control loss of focus.
> Private Sub txtBirthDate_LostFocus()
> Dim Response As Byte
> 'Check for validity of entered date and convert to appropriate format
> If txtBirthDate.Text = "" Or IsDate(txtBirthDate.Text) = True Then
> txtBirthDate.Text = Format(txtBirthDate.Text, "m/d/yy")
> Else
> Response = MsgBox("You have entered an invalid date.", vbOKOnly +
vbExclamation, "MicroServices Fitness Tracker")
Quote:
> txtBirthDate.SetFocus
> End If
> End Sub
> If the date is valid it will be converted to the specified format. If it
is invalid, a message box will appear. After
Quote:
> clicking the OK button in the message box, control will return to the
date control, thus forcing the entry of a valid
Quote:
> date before proceeding.
> Unfortunately I have run into several strange problems with this routine.
If an invalid date is entered, the message box
Quote:
> does appear. After clicking the OK button, control does return to
txtBirthDate, however the arrow keys are not functional.
Quote:
> If a second invalid date is entered, the message box does not appear and
the cursor vanishes.
Quote:
> I have had similar problems with a integer checking routine for the same
application. Interestingly the problem goes away
Quote:
> if I delete the message box line (Response = MsgBox("You...).
> Am I doing something wrong? If so how can I correct it? If not, how can
I work around the bug? Thanks for your help.
Quote: