Results 1 to 4 of 4

Thread: Confusion..

  1. #1

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Here's my dilema. I find myself always running into problems when using the KeyPress, KeyDown, KeyCode, KeyUp..Can anyone tell me when to use one over the other?? Little confused on this subject. Thanks

  2. #2
    Hyperactive Member
    Join Date
    Oct 2000
    Posts
    400
    Try and do everything in the Validate instead of the Key... events. If you must use the Key... events, use KeyPress if you don't care about modifier keys (alt, shift, ctrl) - otherwise, use the KeyDown.

    Some people use the change event instead. If you do, be careful about modifying the text in the textbox, because that will fire off another change event.

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    One thing for sure, if you want to Cancel a users input, you should use KeyPress, because you can set the KeyAScii to 0:

    Code:
    Sub Text1_Keypress(KeyAscii As Integer)
    If Keyascii = vbKeyA then KeyAscii = 0 'if the user types a, eat it and don't let it to the textbox :)
    end Sub
    You can use the KeyDown & KeyUp to notice if someone's holding the keys.

    Code:
    Private holding As Boolean
    
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
    holding = True
    End Sub
    
    Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    If holding Then MsgBox "you held the button for and released it :)"
    holding = False
    End Sub
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4

    Thread Starter
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496

    Talking .

    Thank you for setting me straight

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