Solved

If statement in Classic ASP

Posted on 2014-04-25
6
455 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
[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
6 Comments
 
LVL 33

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 33

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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 53

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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

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…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

622 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