Results 1 to 6 of 6

Thread: why wont vbKeyDelete doesnt work?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    Unhappy

    when i press backspace, the code fires up
    but how come when i press DELETE nothing happens?

    Code:
    Private Sub lstRange_KeyPress(KeyAscii As Integer)
    If KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Then
        MsgBox "hi"
        lstRange.RemoveItem lstRange.ListIndex
    End If
    End Sub

  2. #2
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    You need to do this
    Code:
    Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyDelete Then
            MsgBox "hi"
        End If
    End Sub
    
    Private Sub lstRange_KeyPress(KeyAscii As Integer)
        If KeyAscii = vbKeyBack Then
            MsgBox "hi"
        End If
    End Sub

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539

    just curios

    isn't vbKeyDelete fired on keypress? seems not to be
    do you know why thou?
    since vbKeyBack is fired...

    thanks for the help anyways
    i will test what ya just gave me

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    Well, actually, you can do this, too.
    Code:
    Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyDelete Or KeyCode = vbKeyBack Then
            MsgBox "hi"
        End If
    End Sub
    I guess the reason why it doesn't work in the Keypress sub because the VB doesn't count the delete key as an ascii key like alphabets or numeric letters.

  5. #5
    Guest
    KeyAscii can be used as well.

    Code:
    Private Sub lstRange_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case 8 Or 46
        MsgBox KeyAscii
    End Select
    End Sub
    Or KeyCode can be used:

    Code:
    Private Sub lstRange_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyBack Or vbKeyDelete
        MsgBox KeyCode
    End Select
    End Sub

  6. #6
    Lively Member
    Join Date
    Aug 2000
    Location
    Texas
    Posts
    88
    Hi Matthew,

    Are you sure that your code in the KeyPress sub work? I tried it and it didn't work as I expected because it is the same thing as Kovan code. Moreover, constant keycode, such as vbKeyDelete or vbKeyReturn, etc., give you an integer value. Therefore, I don't think it will make different between pure numeric type like you did and enum type, such as vbKeyBack.

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