Solved

If statement in Classic ASP

Posted on 2014-04-25
6
451 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select case on click 3 26
Multiflying 2 Input Text On a Table 7 31
Insert Button on a table 16 47
Display field if column exists 7 33
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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