VB的问题挖

来源:百度知道 编辑:UC知道 时间:2024/05/09 07:10:28
If Val(Text1) <> Text1 Then GoTo N
判断TEXT1是不是数字,有问题吗?错在哪了?

Val(Text1) <> Text1 ,当输入不是数字的时候,你将两个类型不一样的值作比较肯定出错,类型不匹配.比较需要两个数据类型相同的才能执行
你可以改成
If Not IsNumeric(Text1) Then goto N

dim temp as Integer
If Integer.tryParse(Text1,temp) Then GoTo N

判断学生的分数是不是整数,可以使用下面函数
if CIsInt(Text1,"学生分数") then
.....
end if

Public Function CIsInt(co As Control, ByVal strMsg As String, Optional ByVal blnZRS As Boolean = True, Optional ByVal bln0 As Boolean = False) As Boolean
'判断控件内容是否是整数
'co 控件名 strMsg:提示 blnZRS:是否是自然数 bln0:是否加0
Dim blnNull As Boolean
Dim strValue As String
blnNull = True
CIsInt = False
If TypeOf co Is TextBox Then
strValue = co.Text
Else
Exit Function
End If
strValue = IIf(IsNull(strValue), "", Trim(strValue))
If Not IsNumeric(strValue) Then blnNull = False
If blnZRS Then
If InStr(strValue, ".") > 0 Then blnNull