Solved

If statement in Classic ASP

Posted on 2014-04-25
6
441 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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