数据载入中,请稍等...
    数据载入中,请稍等...
博客公告
    数据载入中,请稍等...
时间记忆
    数据载入中,请稍等...
博客登陆
最新日志
    数据载入中,请稍等...
最新评论
    数据载入中,请稍等...
最新留言
    数据载入中,请稍等...
博客相册
博客好友
    数据载入中,请稍等...
友情连接
博客统计
    数据载入中,请稍等...
VB进行有效数字的判断 | 2007-4-24 22:23:00
'判断方法如下:
'1、肯定出现在0-9,点号(46),负号(45)之内
'2 ?负号必须出现在行首
'3、点号只允许出现一次,如果在最前面出现,在最前面补0,如果在最后面出现,在后面补0

'CHR是ASC的逆函数?

'在VB中按CTRL G

'然后再在焦点窗口中输入
'Print Asc(".")
Public Function IsDecimal(ByVal strValue As String) As Boolean
    strValue = Trim(strValue)
    '第一步,判断字符串中是否含有非数字字符
    Dim N As Integer
    Dim iCount As Integer, jCount As Integer
   
    For N = 1 To Len(strValue) '不属于有效数字内的字符
        If (Asc(Mid(strValue, N, 1)) < 48 Or Asc(Mid(strValue, N, 1)) > 57) And _
        Asc(Mid(strValue, N, 1)) <> 45 And Asc(Mid(strValue, N, 1)) <> 46 Then
            IsDecimal = False
            Exit Function
        End If
    Next N
   
    '第二步,判断字符串是否含有负号,如果有负号,则判断其位置
    If InStr(1, strValue, "-", vbTextCompare) > 1 Then
        IsDecimal = False
        Exit Function
    End If
   
    '第三步,判断字符串中负号的个数
    For N = 1 To Len(strValue)
        If Mid(strValue, N, 1) = "-" Then
            iCount = iCount + 1
        End If
    Next N
   
    If iCount > 1 Then
        IsDecimal = False
        Exit Function
    End If
   
     '第四步,判断字符串中小数点的个数
    For N = 1 To Len(strValue)
        If Mid(strValue, N, 1) = "." Then
            jCount = jCount + 1
        End If
    Next N
   
    If jCount > 1 Then
        IsDecimal = False
        Exit Function
    End If
    '小数点在检测前进行判断
     
    IsDecimal = True
   
End Function

发表评论:
数据载入中,请稍等...

超音速工作室 版权所有