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 danielledunham on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

invoice functions?

Status
Not open for further replies.

Guest_imported

New member
Joined
Jan 1, 1970
Messages
0
Hi,

This will be the first time I can do mathematical functions in foxpro.

1.) What are the functions for add ?'+', substract?'-', multiply ?'*' and divide ?'/'????

2.) Second question is this code....

USE items
NTotal=0
Nsingleprice=0
SCAN
NTotal=(items.price)*(items.discount) && multiply
REPLACE items.discountprice WITH NTotal &&set discount price
Ntotalprice=(items.price)-(items.discountprice)&&substract
replace items.singleprice WITH Nsingleprice && dosingleprice
ENDSCAN

I am trying to do double step -- price $2.00 X 0.10 = discountprice.... then step two I want to take that discountprice -(minus) price X(times)quantity makes totalprice. (I hope and with that I have to do only the records put in for this person customerid! It might be one, two or more articles from the thrift store! We have to put in the discount in the moment since some clothes etc are yellow (10% off) some are green (25%off ) and some are blue (50% off)' So I put the program command button for each percentage (as of today) on the items form and want to do these mathematical calculations on the fly at the moment.
Strange, when I click the button it whites out the grid. I have to shut it off and it comes back again. Any help would be appreciated.

jonezbuz@aol.com
 
in your command button call the Refresh method for the grid

Use the Update command where ever possible it runns faster
*************************************
Update items Set ;
items.discountprice = (items.price*(1-items.discount))
********************************************

this assumes the items.discount is in decimal form ex. 0.10 is 10% off

also look at the Calculate command in the help files

helpfull hint in Select statments you can also do math and create new fields on the fly example
*******************************************************
Select price, discount, (price*(1-discount) AS NewPrice FROM items
*******************************************************
you can then dump this new table into cursors, arrays or into a table your choice
 
jonezbuz

Strange, when I click the button it whites out the grid. I have to shut it off and it comes back again. Any help would be appreciated.

Before you start you calculations try this:
Code:
THISFORM.LOCKSCREEN =.T.
THISFORM.GRID1.RECORDSOURCE='' && no space in between
&& Do your calculations here
THISFORM.GRID1.RECORDSOURCE ="MyChildTable"
THISFORM.LOCKSCREEN = .F. && Don't forget this one.

Mike Gagnon
 
MIKE,

In what property on the grid do I do this code to lockscreen=.t.! Another question is how to do substractions. I have tried to use the - (bar space) and I also put "minus" but to no results?

I have searched under ever word in the Help files, calculations, add, substract, etc etc but can not find the list to do mathematics?

jonezbuz
 
jonezbuz:

1- The numeric functions are under,

Reference-> Language overview-> Language categories-> Data types-> Numeric functions in the help file (foxhelp.chm)

Subtractions are just like anywhere else in math - subtract :-) valuenew = value1 - value2


2- You place the code in the command button's click method I assume.

 
JONEZBUZ
In what property on the grid do I do this code to lockscreen=.t.! Another question is how to do substractions. I have tried to use the - (bar space) and I also put "minus" but to no results?

It depends where you do your calculations. For expample, if you have a grid that holds invoice detail items, and your column 3 is the price and the column4 is the discount and column5 is the total, you would want to recalculate everytime these three items change, so I would create a method in the form( and put the above suggested code in there), and in the valid of each of the three thextboxes of the grid you call on the function to recalculate your grid:
THISFORM.myRecal()

I have searched under ever word in the Help files, calculations, add, substract, etc etc but can not find the list to do mathematics?

In the command window try these:
LOCAL a,b,c
a=10
b=5
c=a-b &&Substraction
MESSAGEBOX(TRANSFORM(c)) && Gives you 5

c= a/b &&Division
messagebox(transform(c)) && && Gives 2

c=a*b && Multiplication
messagebox(transform(c)) && Gives you 50

c=a+b && Addition
messagebox(transform(c)) && Gives you 15







Mike Gagnon
comp14.gif
 
Dear Mike,

Thank you very much for your patience with me. I am so excited that I got each mathematical function to work, and copied all of the trinometric functions from help files too. Enough bragging!

I have to work this quote out..[ I would create a method in the form( and put the above suggested code in there), and in the valid of each of the three the txtboxes of the grid you call on the function to recalculate your grid:
THISFORM.myRecal()--]. I have to hold the math function to stay with the dex_id on that row of grid. I might have to put a click button at the tail of each row to sum it, since I would have "price" * discount (0.10%)which changes each week!some 10%,some 20%, some 50%!

I still don't know who to keep the cursor to just one dex_id row of the items. When I do any function it will do everyone of the rows all the way down to the bottom.

jonezbuz@aol.com
 
jonezbuz

()--]. I have to hold the math function to stay with the dex_id on that row of grid. I might have to put a click button at the tail of each row to sum it, since I would have "price" * discount (0.10%)which changes each week!some 10%,some 20%, some 50%!

No, you don't really need a command button to recalculate. The recalculation won't hurt the speed. If you want to do a calculation just for that row, just set a filter on the RECNO() of that records. But if you have 3 or 4 records in your child table you could set a filter on just those 3 or 4 records and do a loop through them to recalculate.




Mike Gagnon
comp14.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top