Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with nested If..else statements

Status
Not open for further replies.

Yasminna

MIS
Feb 16, 2002
3
US
Hi,
This is a very simple example. I'm just beginning to learn VBScript. I keep getting an error message "Expected 'End" or "Expected 'Then" when running this code. It is out of a book and I copied it exactly. It's driving me crazy. Someone please help!!!

<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;VBScript&quot;>
Function ValidInteger(sNumber,iMin,iMax)

If IsNumeric(sNumber) = 0 Then
If InStr(sNumber,&quot;.&quot;) Then
If CLng(sNumber)>= iMin And CLng(sNumber)<= iMax Then ValidInteger=&quot;&quot;
Else
ValidInteger = &quot;You must enter a number between &quot; & iMin & &quot; and &quot; & iMax
End If
Else
ValidInteger = &quot;You must enter a whole number&quot;
End If
Else
ValidInteger = &quot;You must enter a number value&quot;
End If

End Function

Sub cmdCheckForm_onClick
Dim sValidity
sValidity = ValidInteger(form1.text1.value,1,10)
If sValidity = &quot; &quot; Then
MsgBox &quot;Valid!!!&quot;
Else
MsgBox sValidity
End If
End Sub

</SCRIPT>

<FORM action=&quot;&quot; method=POST id=form1 name=form1>
<INPUT id=text1 name=text1>
<INPUT type=&quot;button&quot; value=&quot;button&quot; id=cmdCheckForm name=cmdCheckForm>
</FORM>
</BODY>
</HTML>
 
Yes, I am still having the same problem. When I load it gives me error in line 14, expected 'End !!!
Any suggestions??
 
Thanks for your replies. John, you were right..part of the mistake was I had to put an enter! but also I had IsNumeric(sNumber) = 0, well the = 0 should have been on the next line InStr(sNumber,&quot;.&quot;)=0.
Anyway, this thing drove me crazy but at the same time it was nice to finally solve it! But I dont know if I want to do this everyday!!!
Thanks again!!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top