I am trying to make a function to check valid semesters like fall #### or Spring #### and I keep getting this error
Microsoft VBScript compilation error ‘800a03f6’
Expected ‘End’
Else
^
here is my code…
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
Too easy, indent your code and you will find the issue.
If you use
means it is a standalone If statement, only the statement after THEN on the same line will be controlled by that condition, therefore the For loop on the next line is a separate statement which is not related to that IF. You should change your code to