954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to use the keypress function is visual basic 6

hey need some help guys. for example i have a text box and i will have input in it. but only numeric ones are allowed to be inputted in the text box if a character for example "a" is pressed the text box will not change and type the "a" and if a numeric button for example is 1, the text box will have 1. how can i do this? thanks.

dc_24l
Newbie Poster
23 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

You need to handle the keyascii in the keypress event .

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

how can i handle the ascii? can anyone make a sample code? i would really appreciate it thanks.

dc_24l
Newbie Poster
23 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

tryb to use this sample code for reference.

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 97 And KeyAscii <= 122 Then
KeyAscii = 0
End If
End Sub
debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

hey hello debasisdas. Thanks so much for the help :)

dc_24l
Newbie Poster
23 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

You are most welcome .

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You