INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Need help from the experts building up an expression in a VFP9 report2

 Forum Search FAQs Links MVPs

## Need help from the experts building up an expression in a VFP9 report

(OP)
I currently have the following fields in a report;
qtyship = 6
price = 1.15
disc_num = 5 (this is stored as a number but would be treated as a percentage when calculating)
discount = y (this can be either "Y" or "N"

I want to be able to subtract PRICE - DISC_NUM only when Discount = "Y" and then multiply by qtyship
On the fields above it would be 1.15 - 5% = 1.0925 but would need to be round off to 1.09
therefore 6 * 1.09 = 6.54
But like I mentioned, it would only calculate the percentage where Discount = "Y".

I can't figure this out any help would be much apreciated
Thank you

### RE: Need help from the experts building up an expression in a VFP9 report

You have IIF() for inline decision about whether or not to make your discount calculation, so the epression would be something like

#### CODE -->

qtyship*IIF(discount='Y', discountprice, price)

This is simplyfied to clearly point out the IIF usege, you'll get the discountprice correct. Take a look at ROUND(number,decimalplaces) to round to 2 decimal places.

Bye, Olaf.

### RE: Need help from the experts building up an expression in a VFP9 report

(OP)
Thank you Olaf,
Im able to get the right number when I do the following
round2((1-disc-num/100)*(.price)) but if I add IIF(discount='Y',round2((1-disc-num/100)*(.price))) VFP tells me theres a comma missing, what am i doing wrong?

Thank you

### RE: Need help from the experts building up an expression in a VFP9 report

You're missing the second case in the IIF(). IIF() stands for "immediate IF" and it expects a condition, a true case and a false case. You're provided the condition and the true case. You need to tell it what to do when the condition is false.

Tamar

### RE: Need help from the experts building up an expression in a VFP9 report

You put in your discountprice expression, but you forgot this part: qtyship*IIF(discount='Y', discountprice, price)

If there is no discount, you want the unmodified price.

Aside of that I don't know where you get a "round2" function from, VFP has ROUND(num,2).
Also I don't see a WITH....ENDWITH, so how would ".price" work?

Are you talking about a VFP report here, at all?

Bye, Olaf.

### RE: Need help from the experts building up an expression in a VFP9 report

(OP)
Olaf and TamarGranor,

Yes, is in a report, I have everything working as requested thanks to your instructions. Now i'm having a little problem getting to print a field where i'm multiplying qtyship*price but only print when discount is either 'N' or empty. What expression can I use?

Thank you

### RE: Need help from the experts building up an expression in a VFP9 report

You haven't understood this, obviously. This is one expression for both cases of discount being 'Y' or not 'Y'. That's why the second option (third parameter of IIF) is the unmodified price.

You don't need two expressions for 'Y' and 'N'.

Bye, Olaf.

### RE: Need help from the experts building up an expression in a VFP9 report

Just try this at the command window:

#### CODE -->

discount = 'Y'
price = 100.00
? IIF(discount = 'Y', price *.95, price)
discount = 'N'
? IIF(discount = 'Y', price *.95, price) 

Also read the help topic of commands you don't know yet, to understand them. https://msdn.microsoft.com/it-it/library/7ttt15k6(...

Bye, Olaf.

### RE: Need help from the experts building up an expression in a VFP9 report

(OP)
Thank you

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!