|
-
January 11th, 2000, 12:47 PM
#1
Textbox only with Numbers
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, 12:52 PM
#2
Re: Textbox only with Numbers
just check the contents' ASCII value(s)
-
January 11th, 2000, 03:23 PM
#3
Re: Textbox only with Numbers
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
-
January 12th, 2000, 03:31 PM
#4
Re: Textbox only with Numbers
here is the simplest code:
If Not IsNumeric(Text1.Text) then
MsgBox "Numbers Only!!!"
End If
-
January 12th, 2000, 03:35 PM
#5
Re: Textbox only with Numbers
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, 06:20 AM
#6
Re: Textbox only with Numbers
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
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
|