Reading a Magnetic Stripe Card Swipe - Detecting Last Character

I’m working with magnetic stripe card readers and am a little stuck–I can read magnetic stripe cards with my usb magnetic stripe card reader–I’m using text boxes in Xojo to read the character strings. For the loyalty card I have 6 numbers encoded on Track 2 of the loyalty card.

The card string appears as ;123456?

I’d like for my event to trigger the moment I’ve finished swiping the card and I can’t figure out how to get the event to trigger once the card is swiped–I tried using the change text option but the event is triggered once the first number or character is detected.

When I add a Push Button this works out really because it sends the whole string–I’m wondering if there’s any way to “buffer” all of the strings before the event triggers. Or is there a way to read the text box for the ? character then tell it action to trigger once it detects that the ? is done reading or is there a way to set the reading to be done once the ? is read?

The following code is on a Pushbutton and triggers on a MouseDown Action. Here’s my code so far:

Dim cardSwipe As String
Dim TMP As String
Dim Access As String

Access = “;123456?”

cardSwipe =TextField1.Text

TextField1.Text =""

if (cardSwipe = Access) then
msgbox “Access Granted”
end if

if (cardSwipe <> Access) then
msgbox “Sorry Dave I cannot open the pod bay doors.”
end if

if len(textbox.text)=8 and right(textbox.text,1)="?" then trigger_event

I assume 8 is the required length (leading semicolon and trailing “?”)

  • Add a 500ms timer to your window, mode Off
  • In the TextChanged event of your TextField, put :

Timer1.ModeOff Timer1.ModeSingle

The timer Action event will happen half a second after the last character has been input in the TextField.