Solved

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

Posted on 2012-04-02
6
301 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
  • 3
  • 2
6 Comments
 
LVL 45

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 45

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

11 Experts available now in Live!

Get 1:1 Help Now