Solved

If Else If

Posted on 2004-08-16
3
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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