For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic Syntax > February 2005 > detect swipe









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author detect swipe
LB

2005-02-02, 9:02 pm

Hello everybody
I'm creating a test app that will be able to read credit card from a
keyboard.

I just added a textbox on a form, and swipe the card. A long string is being
returned.
I was thinking about using the "onchange" event to detect the #, but this is
not working for me.
The lost focus is too late also since the user may see the entire string
that is being returned.

Anybody has a better solution than the "onchange" event ?

Regards
LB


Saga

2005-02-02, 9:02 pm


I have seen others suggest that you set the form's keypreview
property to true and capture the swipe in one of the key
events, such keypress.

I have not done it, so I can't really post example code for this.

Good dluck!
Saga

"LB" <1@nospam.com> wrote in message
news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> Hello everybody
> I'm creating a test app that will be able to read credit card from a
> keyboard.
>
> I just added a textbox on a form, and swipe the card. A long string is
> being returned.
> I was thinking about using the "onchange" event to detect the #, but
> this is not working for me.
> The lost focus is too late also since the user may see the entire
> string that is being returned.
>
> Anybody has a better solution than the "onchange" event ?
>
> Regards
> LB
>



Veign

2005-02-02, 9:02 pm

OnChange? Is this being handle through Visual Basic or through some sort of
VBA (Access perhaps)?

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"LB" <1@nospam.com> wrote in message
news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> Hello everybody
> I'm creating a test app that will be able to read credit card from a
> keyboard.
>
> I just added a textbox on a form, and swipe the card. A long string is

being
> returned.
> I was thinking about using the "onchange" event to detect the #, but this

is
> not working for me.
> The lost focus is too late also since the user may see the entire string
> that is being returned.
>
> Anybody has a better solution than the "onchange" event ?
>
> Regards
> LB
>
>



LB

2005-02-02, 9:02 pm

VB

if you prefer, the "mytextbox_Change()" event.


"Veign" <NOSPAMinveign@veign.com> wrote in message
news:OA4DYuXCFHA.3728@TK2MSFTNGP14.phx.gbl...
> OnChange? Is this being handle through Visual Basic or through some sort
> of
> VBA (Access perhaps)?
>
> --
> Chris Hanscom - Microsoft MVP (VB)
> Veign's Resource Center
> http://www.veign.com/vrc_main.asp
> --
>
> "LB" <1@nospam.com> wrote in message
> news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> being
> is
>
>



MikeD

2005-02-02, 9:02 pm


"LB" <1@nospam.com> wrote in message
news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> Hello everybody
> I'm creating a test app that will be able to read credit card from a
> keyboard.
>
> I just added a textbox on a form, and swipe the card. A long string is

being
> returned.
> I was thinking about using the "onchange" event to detect the #, but this

is
> not working for me.
> The lost focus is too late also since the user may see the entire string
> that is being returned.
>
> Anybody has a better solution than the "onchange" event ?



That you mention an "OnChange" event indicates that either you're not using
VB but rather VBA in some other application or that you're using FM20.DLL in
your VB app. If the former, you'd get better help posting in a newsgroup
for that app. If the latter, you're on your own. FM20.DLL is not intended,
nor supported, for VB, and it has many known problems when used in VB.

In any case, you haven't even clearly stated what "problem" you're having.
All you said was that it wasn't working for you. That doesn't tell us a
thing. What's not "working"? What behavior are you after? What is it that
you want to be able to do? Apparently, you want to "detect the number", but
what does that mean?

--
Mike
Microsoft MVP Visual Basic



Gerald Hernandez

2005-02-02, 9:02 pm


"LB" <1@nospam.com> wrote in message
news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> Hello everybody
> I'm creating a test app that will be able to read credit card from a
> keyboard.
>
> I just added a textbox on a form, and swipe the card. A long string is

being
> returned.
> I was thinking about using the "onchange" event to detect the #, but this

is
> not working for me.
> The lost focus is too late also since the user may see the entire string
> that is being returned.
>
> Anybody has a better solution than the "onchange" event ?
>
> Regards
> LB
>


Is it one of the card readers that plugs inline to or part of the keyboard?
Basically to emulate keyboard input? This could be difficult, as typically
these are designed to be transparent as to the source and always appears to
come from the keyboard. You might be stuck with trapping all keyboard input
(using Forms KeyPress Events) and only pass on what you believe is relevant.
Quite a headache.

Gerald


Veign

2005-02-02, 9:02 pm

Its not that I prefer but VBA textbox's contain 'On' events. VBA code is
not always the same as Visual Basic code - which is what this newsgroup is
for...

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"LB" <1@nospam.com> wrote in message
news:%23ZauK5XCFHA.1524@TK2MSFTNGP09.phx.gbl...
> VB
>
> if you prefer, the "mytextbox_Change()" event.
>
>
> "Veign" <NOSPAMinveign@veign.com> wrote in message
> news:OA4DYuXCFHA.3728@TK2MSFTNGP14.phx.gbl...
sort[color=darkred]
this[color=darkred]
string[color=darkred]
>
>



Veign

2005-02-02, 9:02 pm

Keyboard wedge types also have an escape code that's passed at the end of a
scan - This could be used to identify all characters of a single scan.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Gerald Hernandez" <Cablewizard@spam_remove@Yahoo.com> wrote in message
news:uUJUW%23XCFHA.208@TK2MSFTNGP12.phx.gbl...
>
> "LB" <1@nospam.com> wrote in message
> news:uUmUcRXCFHA.2540@TK2MSFTNGP09.phx.gbl...
> being
this[color=darkred]
> is
>
> Is it one of the card readers that plugs inline to or part of the

keyboard?
> Basically to emulate keyboard input? This could be difficult, as typically
> these are designed to be transparent as to the source and always appears

to
> come from the keyboard. You might be stuck with trapping all keyboard

input
> (using Forms KeyPress Events) and only pass on what you believe is

relevant.
> Quite a headache.
>
> Gerald
>
>



Dick Grier

2005-02-03, 4:02 pm

Hi,

You can do this in the KeyPress event. Simply accumulate all keys (data)
until the swipe is complete. MagStripes of this sort have a standard data
format -- you can use the InStr function to compare the accumulated data to
the pattern expected. I have a document in my book (see below) that
describes the standard data formats. If you send me email, I'll forward a
copy.

Caveat: A reader that uses a keyboard wedge (or USB HID reader that
emulates a keyboard) requires that focus be maintained in a textbox window.
This can be tricky... Users have the nasty habit of moving focus someplace
else, and then your code will fail. Personally, I prefer using a serial
magstripe reader (code for exactly your example is in my book that uses such
a reader), or a reader from MagTek that connects via the USB port, but for
which you can use the Windows HID APIs, so it does not require textbox
focus.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Dick Grier

2005-02-03, 4:02 pm

Hi Chris,
[color=darkred]
Keyboard wedge types also have an escape code that's passed at the end of a
scan - This could be used to identify all characters of a single scan.
<<

This depends on the manufacturer (and the data format of the card).
However, all standard formats can be decoded because the data will match a
well known pattern that allows straight forward parsing. Driver's license
data formats vary slightly from state to state -- but credit cards are
consistent.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Veign

2005-02-03, 4:02 pm

Very good information. I assumed that all manufacturers allowed you to
program an escape code or came with a default one set. Thanx for the heads
up..

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:%23HVvDqhCFHA.3592@TK2MSFTNGP09.phx.gbl...
> Hi Chris,
>
> Keyboard wedge types also have an escape code that's passed at the end of

a
> scan - This could be used to identify all characters of a single scan.
> <<
>
> This depends on the manufacturer (and the data format of the card).
> However, all standard formats can be decoded because the data will match a
> well known pattern that allows straight forward parsing. Driver's license
> data formats vary slightly from state to state -- but credit cards are
> consistent.
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>



LB

2005-02-03, 4:02 pm

Dick
How would I know that the swipe is complete ?

Regards


"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:eJENIohCFHA.208@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> You can do this in the KeyPress event. Simply accumulate all keys (data)
> until the swipe is complete. MagStripes of this sort have a standard data
> format -- you can use the InStr function to compare the accumulated data
> to the pattern expected. I have a document in my book (see below) that
> describes the standard data formats. If you send me email, I'll forward a
> copy.
>
> Caveat: A reader that uses a keyboard wedge (or USB HID reader that
> emulates a keyboard) requires that focus be maintained in a textbox
> window. This can be tricky... Users have the nasty habit of moving focus
> someplace else, and then your code will fail. Personally, I prefer using
> a serial magstripe reader (code for exactly your example is in my book
> that uses such a reader), or a reader from MagTek that connects via the
> USB port, but for which you can use the Windows HID APIs, so it does not
> require textbox focus.
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>



J French

2005-02-04, 9:06 am

On Thu, 3 Feb 2005 11:53:30 -0700, "LB" <1@nospam.com> wrote:

>Dick
>How would I know that the swipe is complete ?


It'll probably send you an end sentinel - say Chr$(13)

Another way is to just wait until it is not sending any more bytes
- on an RS232 once the bytes start coming in, they come in pretty fast

If you have not decided on the hardware then I recommend RS232

If you already have the hardware then stick it in and play with it
Dick Grier

2005-02-04, 4:01 pm

Hi Chris,
[color=darkred]
I assumed that all manufacturers allowed you to
program an escape code or came with a default one set.
<<

I haven't used ANY HID devices that allowed you to program them. I've only
seen that in serial readers.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Dick Grier

2005-02-04, 4:01 pm

Hi,

A swipe is complete when the data that have arrived match the required
pattern. This depends on the data type -- each different encoding method
will provide its own pattern. Thus (in general), you MUST know what kind of
data you are decoding. There are two or three ISO standards for magstripe
data -- and several proprietary methods.

At the end-of-the-day, the magstripe reader doesn't "know" when a swipe is
completed, except by using the same methods that you would (should) use.
That is, match the read data to a known pattern. Now, a more gross method
that some readers might use would be, "Timeout. That is, if no data have
been read for a 'while' then, perhaps we are finished."

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Veign

2005-02-04, 8:59 pm

I had one for a Keyboard wedge scanner application that allowed the
programming of an escape code. If memory is correct it let you choose from
a list by scanning special codes in the manual....

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:OJqam4tCFHA.2296@TK2MSFTNGP15.phx.gbl...
> Hi Chris,
>
> I assumed that all manufacturers allowed you to
> program an escape code or came with a default one set.
> <<
>
> I haven't used ANY HID devices that allowed you to program them. I've

only
> seen that in serial readers.
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>



Dick Grier

2005-02-05, 4:00 pm

Hi Chris,

How do you send the commands to the device? If it is installed as a
keyboard (HID) device, this seems tricky. Most keyboards don't accept
commands, so something interesting was added. I suspect that it was a
custom program that uses some API specific to that device. I'm sure this is
possible, I just haven't encountered it.

Realize, I dislike keyboard (wedge or similar USB-HID devices) because their
operation requires that the user be careful. It is impossible to make them
"monkey proof." So, I simply don't use them. MagTek makes a perfectly
good, inexpensive USB magstripe reader that is easy to use, and that
provides a completely reliable and extensive API. I recommend them to all
who ask. I also use serial readers, they are equally easy to use -- but
these days of computers, such as notebooks, being furnished without serial
ports make a USB device more desirable.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


Veign

2005-02-05, 4:00 pm

The choice of the scanner was not up to me - The company's purchasing
department was forced to use a certain vendor to get some sort of
kickback...

Basically the manual had a few pages of 'special codes' that would program
the wireless hand-held barcode scanner (keyboard wedge type)...

Yeah, I too did not like the limitation of the device. This was for a
project where the person making the scan would not have visibility of the
computer - basically go into a shipping area and scan all products. What I
had to do was make the application fail-safe where there was no way to take
focus away from the text-box when it was placed into a Scan mode..

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
--

"Dick Grier" <dick_grierNOSPAM@msn.com> wrote in message
news:OWZIaB7CFHA.3924@TK2MSFTNGP15.phx.gbl...
> Hi Chris,
>
> How do you send the commands to the device? If it is installed as a
> keyboard (HID) device, this seems tricky. Most keyboards don't accept
> commands, so something interesting was added. I suspect that it was a
> custom program that uses some API specific to that device. I'm sure this

is
> possible, I just haven't encountered it.
>
> Realize, I dislike keyboard (wedge or similar USB-HID devices) because

their
> operation requires that the user be careful. It is impossible to make

them
> "monkey proof." So, I simply don't use them. MagTek makes a perfectly
> good, inexpensive USB magstripe reader that is easy to use, and that
> provides a completely reliable and extensive API. I recommend them to all
> who ask. I also use serial readers, they are equally easy to use -- but
> these days of computers, such as notebooks, being furnished without serial
> ports make a USB device more desirable.
>
> Dick
>
> --
> Richard Grier (Microsoft Visual Basic MVP)
>
> See www.hardandsoftware.net for contact information.
>
> Author of Visual Basic Programmer's Guide to Serial Communications, 4th
> Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
> www.mabry.com/vbpgser4 to order.
>
>



Dick Grier

2005-02-07, 4:08 pm

Hi Chris,
[color=darkred]
What I
had to do was make the application fail-safe where there was no way to take
focus away from the text-box when it was placed into a Scan mode..
<<

Yeah, this is a pain. I've had to do this for some barcode scanners. I
have not (yet) found a barcode scanner manufacturer who publishes the HID
information to allow you to write an application for these that runs without
focus -- except for serial devices. So, I either use a serial converter if
it is USB, a straight serial reader (which is my preference because it is
less expensive and more reliable)... Or trickery to "act like a kiosk
application."

Fortunately, these days, USB is much more convenient than "keyboard wedge,"
so I've never had to deal with the readers that use a wedge. And, if you
are persistent enough, I think you can back your "customers" into a corner
where they will use what's best.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.


ctenos

2005-02-08, 9:05 am

When you swipe, the CC it produces a string bound at the start and end
by escape charaters (i.e. \~). You can perhaps use an OnKey to detect
the start and end of the input.... Just my two cents.

ctenos

2005-02-08, 9:05 am

When you swipe, the CC it produces a string bound at the start and end
by escape charaters (i.e. \~). You can perhaps use an OnKey to detect
the start and end of the input.... Just my two cents.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com