Link to home
Start Free TrialLog in
Avatar of htillberg
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("OpenToPublic").Value) = "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("OpenToPublic").Value) = "1" then Response.Write "Open to the Public"
                                                [Elseif (rsSiteDetail.Fields.Item("OpenToPublic").Value) = "2" then [Response.Write "Viewable from Street"]
                                                [Elseif (rsSiteDetail.Fields.Item("OpenToPublic").Value) = "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("OpenToPublic").Value) ...'



Any suggestions? I have tried various placements of [] but that doesn't seem to make any difference.

Thanks
Avatar of daffodils
daffodils

Why not use a simple switch-case statement ?

ASKER CERTIFIED SOLUTION
Avatar of daffodils
daffodils

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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