Solved

If Else If

Posted on 2004-08-16
3
196 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
Comment Utility
Why not use a simple switch-case statement ?

0
 
LVL 8

Accepted Solution

by:
daffodils earned 125 total points
Comment Utility
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
Comment Utility
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 your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now