Solved

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

Posted on 2012-04-02
6
308 Views
Last Modified: 2012-04-02
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
Comment
Question by:colonelblue
[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
  • 3
  • 2
6 Comments
 
LVL 48

Assisted Solution

by:Martin Liss
Martin Liss earned 333 total points
ID: 37798137
That should work as long as RS_Event.Fields.Item("location").Value is "A", etc. Have you checked to make sure it is?
0
 
LVL 7

Assisted Solution

by:whosbetterthanme
whosbetterthanme earned 167 total points
ID: 37798180
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
 

Author Comment

by:colonelblue
ID: 37798497
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
Independent Software Vendors: 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!

 
LVL 48

Accepted Solution

by:
Martin Liss earned 333 total points
ID: 37798522
What do you do with the 'result' variable that's in your Select case statement?
0
 

Author Comment

by:colonelblue
ID: 37798536
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
 

Author Comment

by:colonelblue
ID: 37798625
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

717 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