How to make a Textbox field only receive integer values on VB6?

Asked

Viewed 502 times

2

It has how to make a field of one textbox only receive integer values?

2 answers

2

At the event Change of Textbox, check if the entered value is number, if it is not then assign the old value.

Dim textval As String
Dim numval As String

Private Sub TextBox1_Change()
  textval = TextBox1.Text
  If IsNumeric(textval) Then
    numval = textval
  Else
    TextBox1.Text = CStr(numval)
  End If
End Sub

0

At the event KeyPress of your Textbox add the following check:

Private Sub TextBox1_KeyPress(KeyAscii As Integer)
     if not IsNumeric(Chr$(KeyAscii)) then 
           KeyAscii= 0
           exit sub
     end if
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.