We have developed a vb 2005 program that runs on a handheld scanner, in the compact framework 2.0 environment. The user keys "Location C" into a text box and presses Enter, at which time the the program validates the data in the text box and saves it, etc. The general idea of what I'm doing is below:
==========================
==========
==========
==========
=
Private Sub txtLocC_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPr
essEventAr
gs) Handles txtLocC.KeyPress
If e.KeyChar = ChrW(13) Then e.Handled = True
If Not (Len(Me.txtLocC.Text) > 0 And Len(Me.txtLocC.Text) <= 4) Then
'set up the error text...
Call LocSub1(piCf1_LocC_Sz)
GoTo Err
End If
==========================
==========
==========
=========
....etc, etc. Actually, the sub has quite a few lines of validation code. But that all works fine, as long as the user presses the Enter key when they are finished keying in data.
The problem is that some users insist on touching the next text box with their finger or stylus when they are finished with this text box, rather than pressing Enter, so none of my validation code is ever being processed.
I'm wondering if the best solution would be for me to use the "LostFocus" concept, to handle cases where the user makes the mistake described above. From what I can tell--with my limited knowledge--it appears to me that I would essentially have to repeat my entire sub, using different syntax in the first line (where I say Private Sub txtLocC_KeyPress...) I would prefer to not have to repeat all the code for each of my subs that process the various text boxes, because all of them are quite wordy, and of course in the compact environment I've got to conserve.
So, my question is this: what IS the best way to handle this problem, knowing that the user may press Enter, or they may enter the data and then touch another text box without pressing Enter? I really need examples of the proper code to use as well. TIA
Start Free Trial