Solved

Turn If... Then... Else... to Case statement

Posted on 2012-04-12
5
287 Views
Last Modified: 2012-04-12
Hello all

I trying to create a menu for a site.

I've picked up this script to show and/or hide layers. It uses an If... Then... Else statement which in the example is fine. My menu will have up to eight entries so I think a Case statement may be the way to go.

My problem is I don't know anything about using Case in this instance so I'm looking for some help.

Here's the code.
<%
'declare 1 for each layer
Dim vis1, vis2

If request("show") = 1 Then
   vis1 = "visible"
   vis2 = "hidden"
Else
   vis1 = "hidden"
   vis2 = "visable"
End IF

%>

<div id="hide" style="visibility:<%=vis2%>;">this is my visable div</div>
<div id="test" style="visibility:<%=vis1%>;"> this is my hidden div</div>

<a href="testdiv.asp?show=1">show hidden layer</a>
<a href="testdiv.asp?show=2">show other layer</a>

Open in new window


Thanks in advance for the help.

Regards

Pb
0
Comment
Question by:Pantyboy
5 Comments
 
LVL 6

Expert Comment

by:wshark83
ID: 37837898
case when request("show") = 1 Then  vis1 = "visible"
        when request("show") = 1 Then  vis2 = "hidden"
        when request("show") <> 1 Then  vis1 = "hidden"
        when request("show") <> 1 Then  vis2 = "visable"
end
0
 
LVL 15

Accepted Solution

by:
pateljitu earned 500 total points
ID: 37837926
Please see this article explaining IF / ELSE as well as SELECT CASE statements:

http://www.w3schools.com/vbscript/vbscript_conditionals.asp


Sample:
Select Case request("show")
  Case 1
    vis1 = "visible"
    vis2 = "hidden"
  Case 2
    vis1 = "hidden"
    vis2 = "visible"
  Case else
    vis1 = "visible"
    vis2 = "hidden"
End Select
0
 
LVL 1

Author Comment

by:Pantyboy
ID: 37837946
Thanks for the replies both.

I take that the Dim statement remains the same. ie:

Dim vis1, vis2

Regards

Pb
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 37837956
the code above is wrong, here is the correct code:
select case Request("show")
    case 1:
          vis1 = "visible"
          vis2  "hidden:
    case 2:
          vis1 = "hidden"
          vis2 = "visible"
    case "n/a":
          vis1 = ""
          vis2 = ""
    case else:
          '-- do whatever 
end select

Open in new window


this is just an example obviously, you'll need to fit it to your needs. the "case else" statement is the same as the else statement in a nested if/else block, it is not required.
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 37837969
pateljitu's code is correct, i was referring to wshark83's code being wrong
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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