Wednesday, August 15, 2012

Visual Basic 6.0 Part 8 - Not Isnumeric

This is one of the best code for input fields that only require numbers. The textbox only accept numbers and ignore string or characters.

1.) In this sample we use only one textbox so add textbox to your form.


2.)Lets code. In order for us to get the right one we will use the KEYPRESS event

******paste this********
Private Sub Text1_KeyPress(KeyAscii As Integer)

Dim KeyChar As String
If KeyAscii > 31 Then 'ignore all string or characters except backspace
KeyChar = Chr(KeyAscii)
If Not IsNumeric(KeyChar) Then
KeyAscii = 0 'disable keys except numbers
End If
End If
End Sub
**********************************



3.)Run the project. I hope this is helpful



Enjoy :)


No comments:

Post a Comment