How do I make a TextBox field only receive integer values in VB6?

2

How can I make a field of a textbox only receive integer values?

    
asked by anonymous 09.05.2014 / 14:19

2 answers

2

In the event of the TextBox% , check that the value you typed is a number, otherwise 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
    
09.05.2014 / 14:49
0

In 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
    
05.08.2014 / 04:03