VB中,怎么判定一个Textbox中输入的是正整数

来源:百度知道 编辑:UC知道 时间:2024/06/05 01:23:29
..应该怎么写

只可以是正整数,,不是或者没输入留空都弹出提示...
弹出提示后点击确定后停止程序,,可以修改原来输入的东东..

Private Function JudgeUnsignInteger(strNum As String) As Boolean
JudgeUnsignInteger = False
On Error GoTo check1
Dim A As Double
Dim B As Integer

A = CDbl(strNum)
B = CInt(strNum)
If Len(CStr(A)) = Len(CStr(B)) Then
If B > 0 Then
JudgeUnsignInteger = True
End If
End If
check1:
End Function
这个是判断函数,是正数返回TRUE,不是返回FALSE
这个判断对形如22.00也判断为正确,不知这个算不算正数,如不算,改成如下形式.
Private Function JudgeUnsignInteger(strNum As String) As Boolean
JudgeUnsignInteger = False
On Error GoTo check1
Dim A As Double
Dim B As Integer

A = CDbl(strNum)
if len(cstr(A)) <> len(text1.text) then
exit function
end if
B = CInt(strNum)
If Len(CStr(A)) = Len(CStr(B)) Then
If B > 0 Then
JudgeUnsignInteger = True
End If
End If
check1:
End Function

1、打开VB6.0软件,新建一个标准ex