Link to home
Start Free TrialLog in
Avatar of mrong
mrong

asked on

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.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

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
Avatar of mrong

ASKER

tried the following but gave me error

 "<TD align=right>" & FormatCurrency(iif(objRec8("CreditDebit")='C',objRec8("Amount")*-1,objRec8("Amount")),2,-1,0) & "</TD>" & _
Avatar of mrong

ASKER

Microsoft VBScript compilation error '800a03ea'

Syntax error

"<TD align=right>" & FormatCurrency(iif(objRec8("CreditDebit")='C',objRec8("Amount")*-1,objRec8("Amount")),2,-1,0) & "</TD>" & _
---------------------------------------------------------------^
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.
Avatar of mrong

ASKER

I need the correct asp syntax.
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

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