在文本框录入时怎样判断是否为整数?

解决方案 »

  1.   

    Private Sub Text1_Change()
        If IsNumeric(Text1.Text) Then
            If Val(Text1.Text) = CInt(Text1.Text) Then
                MsgBox "整数"
            End If
        End If
    End Sub
      

  2.   

    如果你要求正整数,可以如下:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        KeyAscii = PlusIntegerOnly(KeyAscii)
    End Sub'函数可以放在模块中
    Public Function PlusIntegerOnly(Byval KeyAscii As Integer) As Integer
        Select Case KeyAscii
            Case 8, 9, 13, &H30 To &H 39
                PlusIntegerOnly = KeyAscii
        End Select
    End Function