• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

Wha textbox event to use when reading a swipe card in VB.net 2005

I am using VB.net. I have a textbox on a form that is populated by a person swiping a card. A card is swiped and the info from the magnetic strip on the card is displayed in the textbox.

The card we are using is of a certain format, for example the length of the string is 29 characters and the 10th character is aways a '#', what I need is if someone tries to use a different card ( which will have a differnet format) ....I want to display a msgbox that says "Wrong Card"

 I have this on the textChanged event of the textbox...

       If Len(txtCustomerID.Text) = 29 Then
            If Mid(txtCustomerID.Text, 10, 1) = "X" Then
                lnCustomerNumber = Mid(txtCustomerID.Text, 4, 3)
                DisplayCustomerCount() ' function that does something
            End If
      Else
         Msgbox " Wrong Card"
        End If

The problem is how do I read the textbox only after all the charatcers have been entered in the textbox because with the above code the message box gets fired on every character that is read until it reaches a length of 29.

Any help or insight would be much appreciated.



0
nomar2
Asked:
nomar2
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
      If Len(txtCustomerID.Text) = 29 Then
            If Mid(txtCustomerID.Text, 10, 1) = "X" Then
                lnCustomerNumber = Mid(txtCustomerID.Text, 4, 3)
                DisplayCustomerCount() ' function that does something
            Else
                 Msgbox " Wrong Card"
             End If
        End If
0
 
nomar2Author Commented:
The format of the string is a length of 29 and the 10th character  is "X", if someone swipes a card that holds a string length of 10 or 15, etc...how would I generate the messagebox...right now it will only pop up if the string length is 29 and the 10th charater is not 'X'.




0
 
jpaulinoCommented:
The swipe car is read it with a scanner. So you can add a timer to your project and after text change event start you enable the timer

Timer1.Interval = 500
Timer1.Enable = True

Then on Timer.Tick you disable the time (Timer1.Enable = False) and add you comparation.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Add a Timer to your form that is initially DISABLED.  Set the Interval to something like 1000 milliseconds (one second) to start with (this may be lowered later...you'll have to experiment).  Then, whenever the TextChanged() event fires, RESTART the Timer:

    Timer1.Stop()
    Timer1.Start()

Finally, when keys stop getting entered from the Swipe, the Timer will eventually fire (becuase it is no longer being restarted) and then you check the contents of the TextBox from the Timers Tick() event.

*** Be sure to Disable the Timer in the Tick() event so it will be ready for the next swipe...
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hehe...didn't refresh.  ;)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now