|
-
January 26th, 2000, 02:43 PM
#1
Using textbox for numeric data
I am using a Textbox for data input. I would like the textbox to accept only numeric data, is there some parameter/attribute that I can set for this?
-
January 26th, 2000, 03:16 PM
#2
Re: Using textbox for numeric data
Set the Tag Property of any Textbox you want to be Numeric Only to N and use this:
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
private Const GWL_STYLE = (-16)
private Const ES_NUMBER = &H2000
private Sub Form_Load()
Dim oCTRL as Control
for Each oCTRL In me
If TypeOf oCTRL is TextBox then
If UCase(oCTRL.Tag) = "N" then
'Make the Textbox Numeric Only
Call SetWindowLong(oCTRL.hwnd, GWL_STYLE, _
GetWindowLong(oCTRL.hwnd, GWL_STYLE) _
Or ES_NUMBER)
End If
End If
next
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
January 26th, 2000, 05:46 PM
#3
Re: Using textbox for numeric data
Or you can use this much simpler code
1) Make a textbox (text1) and set it's TEXT property to "" (nothing) so you can see the result
private Sub Text1_Change()
If Not IsNumeric(Text1) then MsgBox "Not a number"
End Sub
Good luck!
-
January 26th, 2000, 06:59 PM
#4
Re: Using textbox for numeric data
Private Sub Text2_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57:
' Allow digits
'enter code for what should
'be done if numeric
Case Else
KeyAscii = 0
Beep
End Select
End Sub
refer ascii chart for the equivalent codes
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
|