• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

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.
0
colonelblue
Asked:
colonelblue
  • 3
  • 2
3 Solutions
 
Martin LissRetired ProgrammerCommented:
That should work as long as RS_Event.Fields.Item("location").Value is "A", etc. Have you checked to make sure it is?
0
 
whosbetterthanmeCommented:
1. Can you provide more codde to look at?
2. Are you sure there is a value in the field you are testing?


How about writing the value on each iteration to see if you are getting anything:

 <%
Response.Write(RS_Event.Fields.Item("location").Value & "<br>" & vbCrLf)

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
%>
0
 
colonelblueAuthor Commented:
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

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Martin LissRetired ProgrammerCommented:
What do you do with the 'result' variable that's in your Select case statement?
0
 
colonelblueAuthor Commented:
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.
0
 
colonelblueAuthor Commented:
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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now