htillberg
asked on
If Else If
I am trying to create an if else statement using ASP/ VBScript
When I use the following syntax:
<% If (rsSiteDetail.Fields.Item( "OpenToPub lic").Valu e) = "1" then Response.Write "Open to the Public"%>
This appears to work fine. When the Field OpentoPublic has a 1, it prints the statement and when it does not, it does not print it.
But I want to be able to choose between 3 settings. So I tried the following syntax:
<% If (rsSiteDetail.Fields.Item( "OpenToPub lic").Valu e) = "1" then Response.Write "Open to the Public"
[Elseif (rsSiteDetail.Fields.Item( "OpenToPub lic").Valu e) = "2" then [Response.Write "Viewable from Street"]
[Elseif (rsSiteDetail.Fields.Item( "OpenToPub lic").Valu e) = "0" then [Response.Write "Not Open to Public"]
%>
This results in the following error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Elseif (rsSiteDetail.Fields.Item( "OpenToPub lic").Valu e) ...'
Any suggestions? I have tried various placements of [] but that doesn't seem to make any difference.
Thanks
When I use the following syntax:
<% If (rsSiteDetail.Fields.Item(
This appears to work fine. When the Field OpentoPublic has a 1, it prints the statement and when it does not, it does not print it.
But I want to be able to choose between 3 settings. So I tried the following syntax:
<% If (rsSiteDetail.Fields.Item(
[Elseif (rsSiteDetail.Fields.Item(
[Elseif (rsSiteDetail.Fields.Item(
%>
This results in the following error:
Microsoft VBScript runtime error '800a000d'
Type mismatch: 'Elseif (rsSiteDetail.Fields.Item(
Any suggestions? I have tried various placements of [] but that doesn't seem to make any difference.
Thanks
Why not use a simple switch-case statement ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The structure of If...ElseIf...Else is as under:
If [Condition1] then
'Do following
elseif [Condition2] then
'Do following
else
'Do following
end if
If the "If" statement is only one line statement, then you dont need to add end if at the end.
HTH, nauman
If [Condition1] then
'Do following
elseif [Condition2] then
'Do following
else
'Do following
end if
If the "If" statement is only one line statement, then you dont need to add end if at the end.
HTH, nauman