Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type checking in VB

Status
Not open for further replies.

Jevakil

Mechanical
Mar 19, 2003
41
0
0
US
How do you type check in VB?

Suppose I have a Textbox which I want to accept only integers, and give error otherwise. Is there a built in function that lets you set the textbox data type?

Thanks.

jevakil@mapdi.com

One nuclear bomb can ruin your whole day.
 
Replies continue below

Recommended for you

You can use the isnumeric function similar to the following example

If isnumeric(textbox.text) then

'action if numeric

Else

msgbox "Must enter a numeric value"
textbox.setfocus

End If

I hope this helps you out
 
I normally use something like:

Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8, 46, 48 To 57 'backspace, dec point & numbers only
Exit Sub
Case Else
KeyAscii = 0
Beep
End Select
End Sub

You still need to stop cut&paste though


Good Luck
johnwm
 
Status
Not open for further replies.
Back
Top