Link to home
Start Free TrialLog in
Avatar of colonelblue
colonelblue

asked on

HOw to use a dynamic filed value in a Select Case statement?

Instead of using many if/else statements I thought I'd use Select Case Statements.
But the variable I'm trying to use is from a database field and I can't get the two working.
This is what I have.

 <%
Select Case (RS_Event.Fields.Item("location").Value)
Case "A"
   result = "Alpha Station"
Case "D"
   result = "Delta Station"
Case "AA"
   result = "All Stations"
End Select
%>
      
What am I doing wrong?
Thank you in advance.
SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of colonelblue
colonelblue

ASKER

Hey guys thanks for the reply.
This one's got me scratching my head.

OK here's my code but how does it link together?

Location can only be one of three values, A, W, or BO.

It is a loop going through a table.
AT the moment the values, just show as A, W, or BO.
But I'd like A to show up as Alpha Station,
D as Delta Station, etc..
I can do it with if/else statements but thought a Select Case might make it simpler.


 <% 
While ((Repeat1__numRows <> 0) AND (NOT RS_Events.EOF)) 
%>
<%
<%=(RS_Events.Fields.Item("Event").Value)%><br>
<%=(RS_Events.Fields.Item("Date").Value)%>
<%
Select Case (RS_Events.Fields.Item("location").Value)
Case "A"
   result = "North/South Building"
Case W
   result = "West Building"
Case BO
   result = "Both Buildings"
End Select
%> 
<% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  RS_Events.MoveNext()
Wend
%>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I don't know.
How do I response write a Select Case statement named after the filed it is getting the variable from?

That is the conundrum to me.
I figured it out.
Thanks for the help.

<%
building = (RS_Events.Fields.Item("location").Value)
Select Case building
Case "A"
   response.write("Alpha Station")
Case "D"
   response.write("Delta Station")
Case "AA"
  response.write("All Stations")
Case Else
  response.write("Not Specified")
End Select
%> 

Open in new window