Solved

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

Posted on 2012-04-12
5
286 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 32

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 32

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
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.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

23 Experts available now in Live!

Get 1:1 Help Now