|
-
Nov 9th, 2000, 02:57 PM
#1
Thread Starter
Lively Member
i have one textbox how would i make that textbox that user can't type other then number not word's also spacebar and backspace work but user can't type just alphabatic word. does any one know how to do this
-
Nov 9th, 2000, 03:02 PM
#2
Hyperactive Member
Don't use a text box. Used a MaskedEdit Box. You can then put in the mask property something like this... ##### and it will only allow the user to enter numbers. The maskededit control is in your components list.
-
Nov 9th, 2000, 03:09 PM
#3
Thread Starter
Lively Member
thank you
thank you but i knew about makededit but i don't want that i want to lurn with textbox becaue i am beganner, but thanks
-
Nov 9th, 2000, 03:14 PM
#4
Hyperactive Member
Use the keydown event to check what they have typed and then put in code to block it. Their is a parameter in the keydown event that tells you what key is being pressed and then a value to let you cancel the key. Ill put up some code if you want.
-
Nov 9th, 2000, 03:39 PM
#5
Fanatic Member
You have funny names, are you Japanese?
Just kidding, here's a shorter way, using 2 API functions:
Code:
'This project needs a TextBox
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
Const GWL_STYLE = (-16)
Const ES_NUMBER = &H2000&
Public Sub SetNumber(NumberText As TextBox, Flag As Boolean)
Dim curstyle As Long, newstyle As Long
'retrieve the window style
curstyle = GetWindowLong(NumberText.hwnd, GWL_STYLE)
If (Flag) Then
curstyle = curstyle Or ES_NUMBER
Else
curstyle = curstyle And (Not ES_NUMBER)
End If
'Set the new style
newstyle = SetWindowLong(NumberText.hwnd, GWL_STYLE, curstyle)
'refresh
NumberText.Refresh
End Sub
Private Sub Form_Load()
SetNumber Text1, True
Me.Caption = "Now, try typing some letters into the textbox"
End Sub
-
Nov 9th, 2000, 03:41 PM
#6
Insert the following code in your TextBox. It will filter out A-z.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) Like "[A-z]" Then KeyAscii = 0
End Sub
-
Nov 9th, 2000, 04:18 PM
#7
Fanatic Member
Code:
'Check for a Numeric Character, Excluding Backspace and Space. Verified with VB6.
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not(IsNumeric(Chr(KeyAscii))) And KeyAscii <> 32 And KeyAscii <> 8 Then KeyAscii = 0
End Sub
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
|