IF stmt in asp loop

Greeting,

I have the followings in asp. How to display objRec8("Amount") as negative number if objRec8("CreditDebit")='C'?

Do While Not objRec8.EOF
      Response.Write _
        "<TR ALIGN=CENTER BGCOLOR=ivory>" & _
                     "<TD>" & objRec8("CreditDebit") & "</TD>" & _
        "<TD align=right>" & FormatCurrency(objRec8("Amount"),2,-1,0) & "</TD>" & _
        "</TR>"


      objRec8.MoveNext
    Loop

Thanks in advance.
mrongAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Just like the CASE statement in the Oracle solution in your previous question but using IIF instead.

Untested but something like:
iif(objRec8("CreditDebit")='C',objRec8("Amount")*-1,objRec8("Amount"))

http://support.microsoft.com/kb/219271
0
mrongAuthor Commented:
tried the following but gave me error

 "<TD align=right>" & FormatCurrency(iif(objRec8("CreditDebit")='C',objRec8("Amount")*-1,objRec8("Amount")),2,-1,0) & "</TD>" & _
0
mrongAuthor Commented:
Microsoft VBScript compilation error '800a03ea'

Syntax error

"<TD align=right>" & FormatCurrency(iif(objRec8("CreditDebit")='C',objRec8("Amount")*-1,objRec8("Amount")),2,-1,0) & "</TD>" & _
---------------------------------------------------------------^
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

slightwv (䄆 Netminder) Commented:
I don't have access to vbscript right now to post a 100% working example.

IIF should be what you need.  You will need to take the syntax for it and apply it to your requirements.

I would start with just getting it to display correctly just with IIF.  Then add formatting with FormatCurrency until you find what is causing the error.

You might need to CAST objRec8("Amount") as a number before doing the multiplication.
0
mrongAuthor Commented:
I need the correct asp syntax.
0
slightwv (䄆 Netminder) Commented:
I don't have your code and your objects so I cannot provide 100% plug-and-play code.

I provided the link for the correct syntax for IIF.

Take the syntax for IIF and apply it to your code.

Since my untested code generates and error, start making if less complicated until it no longer generates an error.

I would start off removing the formatcurrency call.  If it still generates an error, start removing other pieces.


For example, does the example below generate an error?  It is the simplest IID statement I can make it.

If it runs, then add back in the amount.  This will help you figure out what is causing the issue.

"<TD align=right>" & iif(objRec8("CreditDebit")='C',"C","D") & "</TD>" & _
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.