How to program the Clear hardware button on a Motorola Symbol handheld scanner?

For a few text boxes, I currently have code that only takes into account key presses from the user if it's either 0 through 9 or Backspace.  I would like to also take into account if the user presses the "Clear" button on the scanner.  How can I do this?

I've tried several variations similar to the vbBack button such as vbClear, vbClr, cbCl but none of them seem to work.  Here is a code snippet if you can help.

Private Sub txtPrice_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPrice.KeyPress
        'Run KeyPress thru validation to make sure 0 thru 9 or "Clear" or "Backspace" is used
        'Always move cursor to the right side during keypad entry
 
        If Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = vbBack Then
            e.Handled = True
        End If
 
        'TEMPORARY FIX USING BACKSPACE VS CLEAR KEY TO EMPTY PRICE FIELD
        If e.KeyChar = vbBack Then
            txtPrice.Text = ""
        End If
    End Sub

Open in new window

63CookAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

alexey_gusevCommented:
in Windows Mobile SDK (for C++) "Clear" button virtual key code is defined as

#define VK_CLEAR          0x0C

so try to compare the code with 0xC
0
63CookAuthor Commented:
alexey_gusev-
Can you be more clear?   I don't understand.  I'm also using VB, not C# or C++.

I tried the following but it doesn't seem to be working.   "e.KeyChar = VK_CLEAR" is underlined in blue and not acceptable and says "Operator = is not defined".   I'm sure I'm using it improperly but I need assistance.  Thanks.

 In defintions area.....................
Const VK_CLEAR = &H0C

In my text field sub for KeyPress I tried ...............
        If Not Char.IsDigit(e.KeyChar) And Not e.KeyChar = vbBack  And Not e.KeyChar = VK_CLEAR Then
            e.Handled = True
        End If



0
alexey_gusevCommented:
I had to be clearer :)


what I meant is that you need to convert the virtual code (&HC) to its Char representation or vice versa (e.KeyChar to Byte) to be able to compare them
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

63CookAuthor Commented:
alexey_gusev-

From your advice... the following should work in the KEYPRESS Event correct???  Forgive me for my ignorance.  

       Const VK_CLEAR as Byte  = &HC

        If Convert.ToByte(e.KeyChar) = VK_CLEAR Then
            MsgBox("FINALLY DETECTED CLEAR BUTTON")
            e.Handled = True
        End If
0
63CookAuthor Commented:
Alexey_:

Also if this is helpful... I can get my Compact Framework app to detect that the Clear button was pressed if I use the "IsControl" comparison.  For example, the MsgBox does pop up with the following code in the KeyPress event and I hit the "Clear" button on my device.   It's a step in the right direction but I really need to be able to detect the Clear button specifically for my app because "Clear" makes the most sense for what I want to do.  

        If e.KeyChar.IsControl(e.KeyChar) Then
            MsgBox("Is Control! " + Convert.ToString(e.KeyChar))
        End If



0
alexey_gusevCommented:
I reckon it should be something like that:

        If e.KeyChar.IsControl(e.KeyChar) And Convert.ToByte(ev.KeyChar) = VK_CLEAR Then
            MsgBox("FINALLY DETECTED CLEAR BUTTON")
            ev.Handled = True
        End If

I don't have any device with CLEAR button unfortunately, but if I were you, I'd check under debugger what you receive  when you press CLEAR.
0
63CookAuthor Commented:
alexey_gusev-
how should I use debugger to get the proper code when I press CLEAR.  Maybe this CLEAR button is specific to the hardware and it's an unusual case?

Do you know of any online links or documentation so I can learn how to debug or trap the hardware keys?
0
alexey_gusevCommented:
put the breakpoint in KeyPress handler, then run the app under debugger (on PDA as a target, of course)

when you click on CLEAR button, it should arrive to your handler, so you can verify what is the KeyChar it delivers and validate if above code indeeed works
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
63CookAuthor Commented:
Thanks for your patience during this question...  I will try.
0
63CookAuthor Commented:
alexey_gusev-
I think I'm going to have to admit defeat on this CLEAR button. I've tried your suggestion before on my own and retried again just now.  

I put a breakpoint in the first line of the KeyPress event. My debug window will show e.KeyChar correctly with ("1"c) for pressing 1, ("2"c) for pressing 2, etc.  Other keys such as BACKSP, CLEAR all show up with ("").  A non-printable character.   I enabled HEX view for Debug and only Short or Integer values show in Hex.  Others such as char remain the same ("").  

I then continued with a 2nd and 3rd breakpoint for KeyUp and KeyDown but similar results.  :-(

Any last thoughts before I give up?
0
alexey_gusevCommented:
so does the code hit the breakpoint for CLEAR? I remember I've used similar buttons on Fijutsu device (from C++ app), so I see no reason why it shouldn't work for you.

Besides, what is the code (not char) you see if you stop on that breakpoint?
0
63CookAuthor Commented:
Got the Clear button to only work once, immediate after data is scanned and put to the text box.  If I use the keypad to begin keying in new price, Clear doesn't work in this situation.  Partial solution. Old hardware without support is the real issue I think.  Thanks for your patience.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.