|
-
Dec 5th, 1999, 11:07 AM
#1
Thread Starter
Addicted Member
How can i only let #'s in a textbox?
-
Dec 5th, 1999, 11:48 AM
#2
Member
Private Sub Text1_KeyPress(KeyAscii As Integer)
If ((KeyAscii >= vbKey0) And (KeyAscii <= vbKey9)) Or KeyAscii = vbKeyBack Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
Ruchi
-
Dec 5th, 1999, 12:20 PM
#3
Fanatic Member
or try this:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
End If
End Sub
or if you want to have Backspace enabled then use this:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> vbKeyBack Then
KeyAscii = 0
End If
End Sub
It should do the job
------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 12-06-1999).]
-
Dec 5th, 1999, 10:57 PM
#4
Junior Member
Or for lots of fun, try using the API to do it:
Private Const GWL_STYLE = (-16)
Private Const ES_NUMBER = &H2000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
' Put this code in your [Form_Load] Event
Dim Old_Style As Long
Dim New_Style As Long
'
Old_Style = GetWindowLong(Text1.hwnd, GWL_STYLE)
New_Style = SetWindowLong(Text1.hwnd, GWL_STYLE, Old_Style Or ES_NUMBER)
-
Dec 6th, 1999, 02:20 AM
#5
Lively Member
Try using the password char option in the textbox properties
-
Dec 6th, 1999, 05:54 AM
#6
Fanatic Member
PasswordChar wouldn't work, because it changes only appearance of the TextBox, it doesn't change its contest.
------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.
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
|