Results 1 to 16 of 16

Thread: KeyAscii

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    KeyAscii

    Hello, hello. It's me again. I need to know what event in a text box has the KeyAscii thingy built into it. In 6.0 I know it's the KeyPress event, but in .NET?...

    Thankyou for your time.


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    I think I should rephrase this. How do you get the ASCII code for the key the user presses in a text box?

    Thanks,
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  3. #3
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    Thumbs up resolved

    in the keypress even of the textbox add the following code :

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress


    Dim KeyAscii As Integer
    KeyAscii = Asc(e.KeyChar)
    MsgBox(KeyAscii)

    End Sub

    have fun
    Last edited by Pirate; Oct 17th, 2002 at 05:48 PM.

  4. #4

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Thanks for your reply. The code you gave me worked like a charm.

    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    u r funny

  6. #6

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Good. Maybe you'll find this amusing, then. I need to ask one more thing of you. How do you convert KeyAscii back into a format that e understands - like from integer to whatever e is?

    Thanks,
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    here you go :

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    Dim KeyAscii As Integer
    KeyAscii = Asc(e.KeyChar) '(e.KeyChar)
    MsgBox(Chr(KeyAscii))

    End Sub

    nightmares . oh **** , I mean night lol

  8. #8

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    OH!!! I see!!! e is a string! That solves ALL my problems! What I've been trying to do here is disable all non-numeric keys...
    nightmares . oh **** , I mean night lol
    lol


    Thanks!
    Furry

    P.S.
    How do you like my avatar??
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  9. #9

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Oh, wait! I can't tell it to disable the keys! AARGH! Here's the code I was using back in the day of 6.0:

    VB Code:
    1. Private Sub CheckInput(ByVal KeyAscii as Integer)
    2.  
    3.     Dim strValid As String
    4.     strValid = "0123456789"
    5.    
    6.     If KeyAscii > 26 Then
    7.         If InStr(strValid, Chr$(KeyAscii)) = 0 Then
    8.             KeyAscii = 0
    9.         End If
    10.     End If
    11.  
    12. End Sub
    13.  
    14. --------------------------------------------------------------------------
    15.  
    16. Private Sub TextBox1_KeyPress(ByVal KeyAscii as Integer)
    17.  
    18.     CheckInput KeyAscii
    19.  
    20. End Sub

    How would I do this in .NET?
    Last edited by Fat_N_Furry; Oct 17th, 2002 at 06:30 PM.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    (well, I really like handling keyascii problems)

    take this :

    Dim KeyAscii As Integer
    KeyAscii = Asc(e.KeyChar)
    'only allow numbers, a single decimal point, backspace or enter

    Select Case KeyAscii
    Case Asc("0") To Asc("9"), Asc(ControlChars.Back)
    'acceptable keys
    e.Handled = False

    Case Asc(ControlChars.Cr)
    'enter key - move to next box
    txtInterest.Focus()
    e.Handled = False

    Case Asc(".")
    'check for existance of decimal point
    If InStr(txtDeposit.Text, ".") = 0 Then
    e.Handled = False
    Else
    e.Handled = True
    End If
    Case Else
    e.Handled = True
    End Select

    I know you will face problems ,
    cheers

  11. #11
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    This allows only numbers and backspace to work in a textbox.
    Code:
        Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
            Dim I As Integer = Convert.ToInt32(e.KeyChar)
            If Not (System.Char.IsNumber(e.KeyChar)) Then
                If I <> 8 Then
                    e.Handled = True
                End If
            End If
        End Sub

  12. #12

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    *In a piratish voice*

    Arr!! Thankye, pirate! The code worked swell, with no bugs, unlike ye thought. About ye color-coding with text, ye only use the vbcode tags. Yeargh. It's the least aye can do for ye's, considering ye have helped me greatly in my quest for knowledge. Yeargh.

    Thankye!
    Arrgh and piraty stuff...


    [edit]
    Just saw ye post, hellswraith. Thankye kindly also!
    [/edit]


    Furry
    Last edited by Fat_N_Furry; Oct 17th, 2002 at 06:41 PM.
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Code:
    Dim KeyAscii As Integer
    KeyAscii = Asc(e.KeyChar)
    'only allow numbers, a single decimal point, backspace or enter 
    
    Select Case KeyAscii
    Case Asc("0") To Asc("9"), Asc(ControlChars.Back)
    'acceptable keys 
    e.Handled = False
    
    Case Asc(ControlChars.Cr)
    'enter key - move to next box
    txtInterest.Focus()
    e.Handled = False
    
    Case Asc(".")
    'check for existance of decimal point
    If InStr(txtDeposit.Text, ".") = 0 Then
    e.Handled = False
    Else
    e.Handled = True
    End If
    Case Else
    e.Handled = True
    End Select

  14. #14

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Ahh! Thanks again!


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  15. #15
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    then it must be written at the top & the end
    thanx anyway for this help

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    try thinkin about hotkeys for your app.night

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width