Thanks, you are correct as I am sure you know. I was getting my information
from the Keys Enumeration member help topic in .NET 2003. Evedently a few
things in this table do not match the Ascii codes. Pretty close though.
Thanks for picking up on my error.
Chuck
"Claes Bergefall" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Can't seem to find the start of this thread?!
> Well, ayway
>
> There is nothing wrong with your keyboard
> You have your ASCII codes mixed up
> n = 110
> N = 78
> Backspace = 8
> / = 47
>
> ASCII for Del is irrelevant since it doesn't generate a KeyPress event
> Never heard of the HELP key. Do you mean F1?
> You should support ',' aswell (ASCII 44)
>
> /claes
>
> "hansolo" <(E-Mail Removed)> wrote in message
> news:vYytc.201$eP.39@lakeread01...
> > > Ok folks. Had some code in VB6 that worked fine within a TextBox
> KeyPress
> > > events KeyAscii parameter for limiting the text in a text box to only
> > > numbers, backspace and decimal characters. I understand the whole
> VB.Net
> > > situation about not being able to assign anything other than zero (no
> key
> > > stroke) to the eventArgs.KeyChar parm in the VB.Net TextBox KeyPress
> event
> > > so I have rolled my own function as suggested by Microsoft to handle
> > > limiting key strokes in a TextBox.
> > >
> > > The Function:
> > >
> > > Function RestrictTxt(ByVal keyz As Integer) As Boolean
> > > If keyz >= 46 And keyz <= 57 Or keyz = 8 Or keyz = 110 Then
> > > RestrictTxt = False
> > > Else
> > > RestrictTxt = True
> > > End If
> > > End Function
> > >
> > > The TextBox KeyPress Event using the function:
> > >
> > > Private Sub Text2_KeyPress(ByVal eventSender As System.Object, ByVal
> > > eventArgs As_ System.Windows.Forms.KeyPressEventArgs) Handles
> > Text2.KeyPress
> > > Dim KeyAscii As Integer = Asc(eventArgs.KeyChar)
> > > eventArgs.Handled = RestrictTxt(KeyAscii)
> > > End Sub
> > >
> > > The Problem:
> > >
> > > It basically does what its supposed to except for two strange errors.
> > > 1) When I press the "n" key which should have a key code value of 78,
> the
> > > function is getting passed the value 110 which should be the Del
> (decimal)
> > > key. As my function above allows the value 110, it passes False to
> > > eventArgs.Handled and somehow the letter "n" is allowed in the
textbox.
> > >
> > > 2) The only other key I am having trouble with is the "/". When I
press
> > the
> > > "/" key (keypad or main keys) which should have a key code value of
111,
> > the
> > > function is getting passed the value 47 which should be the HELP key.
> As
> > my
> > > function above allows values 46 thru 57, it passes False to
> > > eventArgs.Handled and somehow the character "/" is allowed in the
> textbox.
> > >
> > > If you know how these keys "n" and "/" are evaluating to the incorrect
> key
> > > code values in my code but resulting in the correct character (which I
> > don't
> > > want) in the text box please let me know. If possible please try on
> your
> > > system as I am thinking something is wrong with my keyboard :-). In
the
> > > second case, I can easily edit the function to exclude value 47. It
was
> > > included to make the code simpler by using a range but in the first
> case,
> > I
> > > cannot exclude value 110 because I need the decimal character.
> > >
> > > Thanks,
> > >
> > > Chuck
> > >
> > >
> > >
> >
> >
>
>
|