我正在尝试创建一个函数来检查有效的学期,如fall ####或Spring ####,我一直收到此错误
Microsoft VBScript编译错误'800a03f6'
预期'结束'
否则
^
这是我的代码......
Function IsSemester(UserInput)
' Validation: Spring, Fall
Temp=UserInput
If Len(Temp)=9 Then IsSemester=True
For P=1 to 4
If Left(Temp,P,1)<>"Fall" Then IsSemester=False
Next
If Mid(Temp,5,1)<>" " Then IsSemester=False
For P=6 to 9
If Not IsInteger(Mid(Temp,P,9)) Then IsSemester=False
Next
Else
IsSemester=True
End If
If Len(Temp)=11 Then IsSemester=True
For C=1 to 6
If Left(Temp,C,6)<>"Spring" Then IsSemester=False
Next
If Mid(Temp,7,1)<>" " Then IsSemester=False
For C=8 to 11
If Not IsInteger(Mid(Temp,8,11)) Then IsSemester=False
Next
Else
IsSemester=True
End If
End Function
答案 0 :(得分:4)
太容易了,缩进代码就会发现问题。
Function IsSemester(UserInput)
' Validation: Spring, Fall
Temp=UserInput
If Len(Temp)=9 Then IsSemester=True
For P=1 to 4
If Left(Temp,P,1)<>"Fall" Then IsSemester=False
Next
If Mid(Temp,5,1)<>" " Then IsSemester=False
For P=6 to 9
If Not IsInteger(Mid(Temp,P,9)) Then IsSemester=False
Next
Else
IsSemester=True
End If
If Len(Temp)=11 Then IsSemester=True
For C=1 to 6
If Left(Temp,C,6)<>"Spring" Then IsSemester=False
Next
If Mid(Temp,7,1)<>" " Then IsSemester=False
For C=8 to 11
If Not IsInteger(Mid(Temp,8,11)) Then IsSemester=False
Next
Else
IsSemester=True
End If
End Function
如果您使用
IF Len(temp)=9 Then IsSemester=True
表示它是一个独立的If语句,只有同一行上的THEN之后的语句将由该条件控制,因此下一行的For循环是一个与该IF无关的单独语句。您应该将代码更改为
If Len(Temp)=9 Then
IsSemester = True
'<whatever your code here>
End If