IsNumeric(expression)必要的 expression 参数是一个 Variant,包含数值表达式或字符串表达式。说明如果整个 expression 的运算结果为数字,则 IsNumeric 返回 True;否则返回 False。

解决方案 »

  1.   

    不过这个东西好像不能识别逗号
    最好限制textbox的输入
    Private Sub txtID_KeyPress(KeyAscii As Integer)
    If KeyAscii = 46 Or (KeyAscii >= 48 And KeyAscii <= 57) Or KeyAscii = 8 Then
    Else
        KeyAscii = 0
    End IfEnd Sub
      

  2.   

    if IsNumeric(text1.text) then  '为数字时else  '其他字符endif
      

  3.   

    如果textbox不需要字符或数字,加判断内容大致同上。
      

  4.   


    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
    Private Const ES_NUMBER = &H2000&
    Private Const GWL_STYLE = (-16)Private Sub ControlEdit(TheControl As Control)
        Dim x As Long
        Dim Estyle As Long
        Estyle = GetWindowLong(TheControl.hwnd, GWL_STYLE)
        Estyle = Estyle Or ES_NUMBER
        x = SetWindowLong(TheControl.hwnd, GWL_STYLE, Estyle)
    End SubPrivate Sub Form_Load()
       Call ControlEdit(Text1) 'text1为文本框
    End Sub
      

  5.   

    isnumeric(str)函数判断str是否位数字;是返回true否则返回false
      

  6.   

    可以用别的办法

    if text1=cstr(val(text1)) then 是数字
      

  7.   

    这样也可以:
    private sub text1__KeyPress(KeyAscii As Integer)If InStr("0123456789" + vbBack, Chr(KeyAscii)) = 0 Then
      msgbox "输入框中输入的是字符"
    else
      msgbox "输入框中输入的是数字"End IfEnd Sub
      

  8.   

    IsNumeric函数或KeyAscii >= 48 And KeyAscii <= 57(除10个数字就是字符了)语句
    当然最好先把TEXTBOX
      

  9.   

    如果用来控制文本的输入不如用MaskEdBox控件,设置掩码格式就可以只输入数字或只输入文本.