Solved

If Else If

Posted on 2004-08-16
3
200 Views
Last Modified: 2010-04-07
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
0
Comment
Question by:htillberg
  • 2
3 Comments
 
LVL 8

Expert Comment

by:daffodils
ID: 11811743
Why not use a simple switch-case statement ?

0
 
LVL 8

Accepted Solution

by:
daffodils earned 125 total points
ID: 11811821
Sorry.. I think in VB.NET it is called  Select Case contruct

Select rsSiteDetail.Fields.Item("OpenToPublic").Value
    Case 1
        Response.Write "Open to the Public"
    Case 2
        Response.Write "Viewable from Street"
    Case 3
        Response.Write "Not Open to Public"
   Case Else
        Response.Write " "
End Select

Select...Case Statements
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmselectcase.asp
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 11811828
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
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question