Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then MsgBox "是数字"
End Sub

解决方案 »

  1.   

    Public Function LKeyNum(ByRef KeyAscii As Integer)
        If Not ((KeyAscii > 47 And KeyAscii < 58) Or _
        KeyAscii = 8 ) Then KeyAscii = 0
    End Function
    ---------------
    Private Sub Text3_KeyPress(KeyAscii As Integer)
        LKeyNum KeyAscii
    End Sub
    用这个例子,你可以自动过滤,就不用判断是不是数字了
      

  2.   

    Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii >= 48 And KeyAscii <= 57 Then MsgBox "是数字"
    End Sub
      

  3.   

    Option ExplicitPrivate Sub Command1_Click()
    Dim Flag As Boolean
        If IsNumeric(Text1.Text) Then
            If Val(Text1.Text) > 0 Then
                If InStr(Text1.Text, ".") = 0 Then
                    Flag = True
                End If
            End If
        End If
        MsgBox Flag
    End Sub
      

  4.   

    Private Sub Command1_Click()
    Dim i As Long
    Dim strA As String
    If IsNumeric(Text1.Text) = True Then
        For i = 1 To Len(Text1.Text)
            strA = Mid(Text1.Text, i, 1)
            Select Case strA
            Case "+", "-", ".", ","
                MsgBox "Error"
                Exit For
            Case Else
            End Select
        Next
    Else
        MsgBox "Error"
    End IfEnd Sub
      

  5.   

    Private Sub Command1_Click()
    Dim i As Long
    Dim strA As String
    If IsNumeric(Text1.Text) = True Then
        For i = 1 To Len(Text1.Text)
            strA = Mid(Text1.Text, i, 1)
            Select Case strA
            Case "+", "-", ".", ","
                MsgBox "Error"
                Exit For
            Case Else
            End Select
        Next
    Else
        MsgBox "Error"
    End IfEnd Sub
      

  6.   

    if abs(int(val(text1))) & "" = text1 then
       msgbox "数字串"
    else
       msgbox "不是数字串"
    endif