VB 函数回值失败

来源:百度知道 编辑:UC知道 时间:2024/06/14 07:04:07
大家帮我看看下面的代码有什么错误,为什么函数返回的boolean值老是失败,sub里的boolean值就是无法被赋值。。。

Private Function string_or_not(st As String)As Boolean ’判断输入内容是不是数字
Dim t As Boolean
for i=1 To Len(st)
If Asc(Mid(st,i,1))>47 And Asc(Mid(st,i,1))<58 Then
t=False ’如果是输入的是整数,则t为false
Else
t=True ’如果不是整数,则t为true,终止循环
Exit For
End If
Next i
End Function

Private Sub Command3_click()
Dim a As Integer
Dim str As String
str=Text1.Text
If str="" Then
Msgbox "you entered nothing",vbOkonly,"error"
ElseIf string_or_not(str)=True Then ’不是数字,提示输入数字
Msgbox "please input numbers",vbOKonly,"error"
Else
a=Val(str) ’把字符型数字转换成整型
evaluate (a) '评估成绩的函数
End If
End Sub

Private Function string_or_not(st As String) As Boolean '判断输入内容是不是数字
For i = 1 To Len(st)
If Asc(Mid(st, i, 1)) > 47 And Asc(Mid(st, i, 1)) < 58 Then
string_or_not = False '如果是输入的是整数,则t为false
Else
string_or_not = True '如果不是整数,则t为true,终止循环
Exit For
End If
Next i
End Function

Private Sub Command3_click()
Dim a As Integer
Dim str As String
str = Text1.Text
If str = "" Then
MsgBox "you entered nothing", vbOKOnly, "error"
ElseIf string_or_not(str) = True Then '不是数字,提示输入数字
MsgBox "please input numbers", vbOKOnly, "error"
Else
a = Val(str) '把字符型数字转换成整型
evaluate (a) '评估成绩的函数
End If
End Sub

==============================================

你没有把true 或false赋给函数,而是把他给了变量t,函数自然得不到返回值。

Private Function string_or_not(st As String) As Boolean '判断输入内容是不是数字<