Solved

If statement in Classic ASP

Posted on 2014-04-25
6
442 Views
Last Modified: 2014-04-27
Hi Experts,
<%=rs("EmpStatus")%> can display 3 values on my page:
A
I
T
These stand for Active, Inactive, and Terminated.
How could I display the actual words instead of the abbreviation with the help of an If statement?
Thank you for your help.
0
Comment
Question by:romsom
6 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 40023847
i would use a select statement:

select case rs("EmpStatus")
    case "A"    Response.Write "Active"
    case "I"     Response.Write "Inactive"
    case "T"    Response.Write "Terminated"
end select

Open in new window

0
 
LVL 32

Accepted Solution

by:
Big Monty earned 500 total points
ID: 40023850
if you prefer IF statements, you would do the following:

if rs("EmpStatus") = "A" then
    Response.Write "Active"
elseif rs("EmpStatus") = "I" then
    Response.Write "Inactive"
elseif rs("EmpStatus") = "T" then
    Response.Write "Terminated"
end if

Open in new window

0
 

Author Closing Comment

by:romsom
ID: 40023853
Thank you very much, it's perfect. Both solutions worked.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40023857
You might want to put the code earlier in the page and leave a simple result inline.
If rs("EmpStatus") = 'A' Then reEmpstatus = "Active"
If rs("EmpStatus") = 'I' Then reEmpstatus = "Inactive"
If rs("EmpStatus") = 'T' Then reEmpstatus = "Terminated"

Then later you would use..
<%=rsEmpStatus%> 

Open in new window

Oops... had to answer a phone call while I was typing.
0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40024772
Big Monty is faster at answering but this is a great alternative.  No if/then and you can easily reuse.  

  
' place towards the top of your page
<%
Dim iStatus
Set iStatus=Server.CreateObject("Scripting.Dictionary")
iStatus.Add "A","Active"
iStatus.Add "I","Inactive"
iStatus.Add "T","Terminated"
%>
<ul>
<%
do until rs.eof
   ' Where you need it in your page
   'Response.Write "This should print out Active: " & iStatus.Item("A")
    response.write "<li>Status:"&iStatusItem(rs("EmpStatus"))&"</li>"
rs.move.next
loop
%>
</ul>

Open in new window

For more info on the dictionary object http://www.w3schools.com/asp/asp_ref_dictionary.asp
0
 

Author Comment

by:romsom
ID: 40026534
Thank you very much all of you.
Padas, I like your alternative; I will use it in the future.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

930 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

10 Experts available now in Live!

Get 1:1 Help Now