Results 1 to 6 of 6

Thread: Keyascii

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344
    Ok I have it set that only numbers will work in the text box using the code

    If keyascii < 48 or keyascii > 57 then
    keyascii = 0
    Beep
    End if


    That works fine, however I want them to be able to use the "Backspace", how can I do that while still having this code or a code that prevents All those keyascii's listed, except the backspace.


    -RaY
    VB .Net 2010 (Ultimate)

  2. #2
    Guest
    Try this.

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
        'If the Key is not Backspace then
        If Not KeyAscii = 8 Then
            If KeyAscii < 48 Or KeyAscii > 57 Then
                KeyAscii = 0
                Beep
            End If
        End If
                          
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Nope

    Thats what i thought, and had....but doesn't work for some reason...weird, huh?
    -RaY
    VB .Net 2010 (Ultimate)

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    how about this

    If KeyAscii < 48 Or KeyAscii > 7 and keyascii < 9 then KeyAscii = 0
    Beep
    End If

    what do you think about that megatron?
    -RaY
    VB .Net 2010 (Ultimate)

  5. #5
    Guest
    Strange..See if this works. I've changed 8 to vbKeyBack which is exactly the same except this is a consant.

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    
        'If the Key is not Backspace then
        If Not KeyAscii = vbKeyBack Then
            If KeyAscii < 48 Or KeyAscii > 57 Then
                KeyAscii = 0
                Beep
            End If
        End If
                          
    End Sub

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Weird

    I don't get y that worked and the 8 didnt if it means the same...... Maybe I have code somewhere else defining 8, since im working a lot with numbers....Thanks!
    -RaY
    VB .Net 2010 (Ultimate)

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