Solved

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

Posted on 2012-04-02
6
302 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 46

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 46

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
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 I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

12 Experts available now in Live!

Get 1:1 Help Now