Link to home
Start Free TrialLog in
Avatar of Stefan Motz
Stefan MotzFlag for United States of America

asked on

If statement in Classic ASP

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.
Avatar of Big Monty
Big Monty
Flag of United States of America image

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

ASKER CERTIFIED SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stefan Motz

ASKER

Thank you very much, it's perfect. Both solutions worked.
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.
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
Thank you very much all of you.
Padas, I like your alternative; I will use it in the future.