Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If Else If

Posted on 2004-08-16
3
Medium Priority
?
209 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 500 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Loops Section Overview
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

972 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