Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

Luiz Eduh

Technical User
Jan 10, 2012
51
US
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
 
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.
 
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
 
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
 
You put in your discountprice expression, but you forgot this part: qtyship*IIF(discount='Y', discountprice[highlight #FCE94F], price)[/highlight]

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.
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top