Solved

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

Posted on 2012-04-12
5
291 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:Martin Cotterill
[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
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:Martin Cotterill
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query still returning duplicates 5 60
Sudden decrease in performance when updating mysql using classic asp 6 41
window close link 7 62
Display field if column exists 7 58
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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