'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
- 上一篇:S7-2xx使用USS协议通讯不正常的一个重要原因
- 下一篇:VB 全局热键
超音速工作室 版权所有