字符判断

来源:互联网 发布:二级msoffice题库软件 编辑:程序博客网 时间:2024/06/08 23:10


Public Function IsNumeric(Str As Variant) As Boolean
    ' NULL
    If Information.IsNull(Str) Then
        IsNumeric = False
        Exit Function
    End If
    
    ' EMPTY
    If Information.IsEmpty(Str) Then
        IsNumeric = False
        Exit Function
    End If
    
    '
    If Not Information.IsNumeric(Str) Then
        IsNumeric = False
        Exit Function
    End If
    
    Dim iLen As Integer
    iLen = Strings.Len(Str)
    
    ' 半角
    If iLen <> Strings.Len(Strings.Trim(Str)) Then
        IsNumeric = False
        Exit Function
    End If
    
    ' 全角
    If iLen <> Strings.LenB(Strings.StrConv(Str, vbFromUnicode)) Then
        IsNumeric = False
        Exit Function
    End If
    
    IsNumeric = True
    Exit Function
    
End Function

原创粉丝点击