哈哟,朋友们,怎样来判断text1.text输入的字符串为阿拉伯数字串,哪位有自己编的函数,给我一份好吗

解决方案 »

  1.   

    if isnumeric(text1.text)=true then
        msgbox "我是数字!"
    else
        msgbox "我不是数字"
    end if
      

  2.   

    if not isnumeric(text1.text) then
        msgbox "不是数值"
    else
        ...
    end if
      

  3.   

    你还可以在text1.keypress里面获得ascii值来判断。这是手动的
      

  4.   

    第一次发言,送你两个函数,忘了曾经参考那位大虾的资料(对不起),我一直使用这两个函数。
    '----------------------------------------------------------------------
    '*   名称:ValiText()
    '*   功能:输入限制确认函数,过虑掉不希望的字符
    '*   用法:在需要限制输入的控件的 KeyPress加入以下代码:
    '*        KeyAscii = ValiText(KeyAscii, "0123456789/-", True)
    '*   参数:KeyIn:输入的字符ASCII值
    '*        ValidateString:过滤字符
    '*        Editable:能否使用 [Backspace] 键
    '----------------------------------------------------------------------
    Public Function ValiText(KeyIn As Integer, ValidateString As String, Editable As Boolean) As Integer
        Dim ValidateList As String
        Dim KeyOut As Integer
        If Editable = True Then
            ValidateList = UCase(ValidateString) & Chr(8)
        Else
            ValidateList = UCase(ValidateString)
        End If
        If InStr(1, ValidateList, UCase(Chr(KeyIn)), 1) > 0 Then
            KeyOut = KeyIn
        Else
            KeyOut = 0
            Beep
        End If
        ValiText = KeyOut
    End Function
    Public Function CheckNumeric(ByVal text As String, ByVal DecValue As Boolean) As Boolean
        Dim i As Integer
        
        For i = 1 To Len(text)
            Select Case Mid$(text, i, 1)
                Case "0" To "9"
                Case "-", "+":
                    '正负号只允许为第一个字符
                    If i > 1 Then Exit Function
                Case ".":
                    '如果不允许小数点,则退出
                    If Not DecValue Then Exit Function
                    '如果出现多个小数点,退出
                    If InStr(text, ".") < i Then Exit Function
                Case Else:
                    Exit Function
            End Select
        Next i
        CheckNumeric = True
    End Function
      

  5.   

    Public Function sffunLimitNumber(ByVal IntVal As Integer) As Integer
    '-------------------1-------------------
    '目    的:只允许在文本框内输入数字、退格、删除及回车键
    '输    入:ByVal IntVal As Integer,任意的键值
    '被传递值:无
    '返 回 值:过滤后的键值
    '输    出:无
    '注    解:
    '用    法:在文本框的KeyPress事件中输入KeyAscii = sffunLimitNumber(KeyAscii)即可
    '修 订 版:
    '-------------------1-------------------
    If (IntVal <> vbKeyDelete) _
    And (IntVal <> vbKeyBack) _
    And (IntVal <> 13) _
    And (IntVal < 48 Or IntVal > 57) Then
        IntVal = 0
    End If
    sffunLimitNumber = IntValEnd Function
      

  6.   

    可以用IsNumeric()函数来做。用法:
    返回 Boolean 值,指出表达式的运算结果是否为数。
    语法
    IsNumeric(expression)
    必要的 expression 参数是一个 Variant,包含数值表达式或字符串表达式。
    说明
    如果整个 expression 的运算结果为数字,则 IsNumeric 返回 True;否则返回 False。
    如果 expression 是日期表达式,则 IsNumeric 返回 False。