I have created a program in Visual Basic using Microsoft Visual Studio 2010 Professional. There is a textbox that I use in the program that when the focus is placed on it will take the data encoded on a magnetic striped card such as a driver’s license or any card that has this kind of data encoded magnetically. Very simple to get the data as the program takes all of it upon the swipe without having to do really anything, however, the problem is that I don’t know which declaration to use when the swipe has stopped – or the last character has been entered. Currently I am using TextBox1_textChanged as my declaration, but that is called every time each character is put into the text box. When you are swiping, this is an ongoing process until the last character is put in. So if I have a magentic card with 10 characters in it, this method will be called 10 times. Is there a declaration that I can use that only fires off whent he swipe has loaded all of the characters or some kind of loop that I can incorporate?
Thanks!
I have created a program in Visual Basic using Microsoft Visual Studio 2010 Professional.
Share
In short, the answer is no – All the card reader does is present itself to the computer as a special keyboard – when you swipe the card, it “types”.
Because of this, you don’t usually get any additional information about the state (failed swipe, swipe complete, etc.)
Some card readers will perform a carriage return at the end of the data. Depending on your circumstance, you may know the data will always be the same length.
In either case, you’ll still need to hook the
TextBox.TextChangedevent – just have a little bit of logic which checks if the key press is enter/the textbox text is the correct length.(NB: If checking for an
Enteror another key, it will probably be easier to use theTextBox.KeyDownevent. Have a look at theevariable which contains information about the key being “pressed”)As mentioned in the comments on the OP by @Reafidy, the last alternative which is guaranteed to work but a bit messier to implement is to use a timer which will fire your method after n milliseconds without a change to the text.
Incidentally, I’m assuming you mean VB.Net not VBA (VB for Applications – eg Excel Macros). I’ve edited the tags accordingly.