|
-
Sep 12th, 2002, 07:05 PM
#1
Thread Starter
Hyperactive Member
make textbox only input number
I have this example:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And KeyAscii <> Asc("-") Then KeyAscii = 0
End Sub
I know this KeyAscii represents the recently inputted character. But i don't get where it comes from.
Hmm... i'm not making any sense. Where does this keyascii come from and how does it work? All i'm asking about is the keyascii variable which i don't understand where it comes from and what it is.
-
Sep 12th, 2002, 07:10 PM
#2
Hyperactive Member
The keycodes for numbers are 48-57. With "0" = Chr$(48) and "9" = Chr$(57)
-
Sep 12th, 2002, 07:11 PM
#3
Hyperactive Member
ASCII is American Standard Code for Information Interchange. Its what you type on the keyboard. Each key has its own value.
-
Sep 12th, 2002, 07:58 PM
#4
Frenzied Member
When a user presses a key on the textbox, textbox's keypress event is generated.. Operating system.. generates the message and post it to the Textbox with the ascii code of key pressed.. keyascii is the information argument..it shows which key has been pressed.. this comes from the Windows..
-
Sep 12th, 2002, 08:49 PM
#5
Thread Starter
Hyperactive Member
Hmm... Q_Me... i know what it is and i know about ascii.
Moinkhan... i liked your explanation but i wasn't exactly trying to explain that.
Ok... let me try to rephrase the question.
keyascii is kind of like a constant in visual basics? It always has the last key that was pressed?
All i really want to know is what goes into the ascii variable. Is it always the last key pressed?
I will look into examples of it being used @ planetsourcecode later, i have no time now since i have a BIG math test tomorrow!! and a few more quizzes.
-
Sep 12th, 2002, 09:55 PM
#6
Fanatic Member
I got this code from this forum also. Hope the owner doesn't mind for me to post it again here... 
Code:
'put this in module
Public Function ValidateNumeric(strText As String) As Boolean
ValidateNumeric = CBool(strText = "" Or strText = "-" Or strText = "-." _
Or strText = "." Or IsNumeric(strText))
End Function
in your form (suppose the object is txtNumeric) :
Code:
Private Sub txtNumeric_Change()
If Not ValidateNumeric(txtNumeric.Text) Then
txtNumeric.Text = ""
'or u can put other statement u want to execute....
End If
End Sub
Hope will help u....
__________________
Wille
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|