Click to See Complete Forum and Search --> : Textbox only with Numbers
MC Killer
January 11th, 2000, 11:47 AM
i make a makro for Word 2000. I have an Dialog with TextBoxes. In these Textboxes i will only have an Integer value. How can i check that the value in the Textbox is a Number or a text ?
ICQ : 41418974
January 11th, 2000, 11:52 AM
just check the contents' ASCII value(s)
Chris Eastwood
January 11th, 2000, 02:23 PM
In Visual Basic, you'd use the following code to set a textbox to be numeric input only (and only for integer values) :
option Explicit
'
' WinAPI Declarations
'
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 as Long = &H2000
'
'
private Sub Form_Load()
'
Dim lStyle as Long
Dim lRet as Long
'
lStyle = GetWindowLong(Text1.hwnd, GWL_STYLE)
lStyle = lStyle Or ES_NUMBER
lRet = SetWindowLong(Text1.hwnd, GWL_STYLE, lStyle)
'
End Sub
Not too sure about from a macro though ...
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
AndyK
January 12th, 2000, 02:31 PM
here is the simplest code:
If Not IsNumeric(Text1.Text) then
MsgBox "Numbers Only!!!"
End If
AndyK
January 12th, 2000, 02:35 PM
Forgot to add something....code goes into textbox_change and change Text1.text in the code to whatever your textboxes name is.
January 13th, 2000, 05:20 AM
There is a function ISNumeric in VB which returns to to true or flase. the syntax is
Dim strtmp as String
strtmp = 'ss3'
strtmp = '123'
IsNumeric(strtmp)
The first string will return you false
and the second one will return you true
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.