I have set up a simple data tracking form that breaks out the associated costs of a vehicle going to Auction ( dealer costs, transportation fees and so on) for my employer. It works great, and I can enter data into the database successfully, and my Report will print it out nicely sorted by Store. I would now like to create cells on my data entry form that calculate and display various math procedures on the data being entered. For instance, a cell that displays the Sum of all the fees and costs, and then a Result field that displays the amount we sold the car for minus the Sum total of the fees. Boy, do I need some help getting my mind around how to do this in VFP 9! Could someone please outline the general steps I need to do to make this happen It seems like I have to define variables, write expressions using them, and somehow plug them into the forms or reports... am I even close Any and all help sincerely appreciated! thanks!

Coming from Excel to VFP9 and need help understanding math functions on cells
isoandy
No.1 Of Mew
I feel like I’m making some progress in VFP, and have jumped in to some simple stabs at performing math functions on form fields and have them appear inside text boxes. Thanks to all who have replied, I figured out how to set up custom methods, Link the reporting text box via the control source, made custom properties and so on. I’m struggling a bit with syntax and the rather cryptic MS help files, but each step is a step forward. Here’s my very first custom method that in theory adds these two values together…< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
WITH thisform
.newprop2.value=.cost1.value + .cost21.value
.refresh()
ENDWITH
Dhivager Rathakrishnan
It sounds like what you want to do is put some textboxes on a form that will show some calculations as values change. As you suspected, this will involve writing some code. I recommend doing it like this:
1) Add a custom method to your form with a name like Calculate. You do this by choosing Form | New Method from the menu, and then entering the name you want for it. Click Add to actually add the method.
2) Add custom properties to your form to hold the values you want to calculate, one property for each value. To do so, choose Form | New Property and then type in the name for each, clicking Add to keep it.
3) In the Property Sheet, set the initial value for your custom properties to something appropriate. (I suspect 0 is a good choice.)
4) In your custom method, put the code that does the actual calculations, storing the results in your custom properties. Remember that to refer to a property, you need to specify the relevant object, so you'll have code like:
This.nTotal = <whatever it takes to compute the total>
If you tell us more about the set-up, we can help you work out the actual code.
5) Now you have to hook the code up to things in the form. First, add a textbox for each computed value you want to show. For each, set its ControlSource property to one of your custom properties.
6) The final step is getting the textboxes updated as things change. There are a couple of choices here. The simplest is to add a button (with a Caption like Calculate) and in the button's Click event method, call the custom method you set up:
ThisForm.Calculate()
ThisForm.Refresh()
The downside to this approach is that the textboxes only get updated when you click the button. If you want to have them updated every time something changes, you have to do a little more work. What this is depends on a) what version of VFP you're using and b) how the form is set up, that is, what kinds of controls you're using. It's not clear to me whether you're trying to show totals for a number of records displayed in a grid or for a series of records being added and saved. Tell me more and I'll try to explain more.
Hope this gets you started.
Tamar
SKasic
Tamar
Chris Lyon - MS
In the INIT of the form you should fire the function also, this will make sure the textbox will have the information filled in when it finally shows.
Trelly
rdrago
SDCripps
No, you did not turn anything off, just neglected to place a very important command: READ EVENTS.
VFP needs a wait state to wait for user input. During development the IDE itself does it (stays 'alive' waiting for you to do something). In an EXE, you do not use the IDE but the runtimes. They need a wait state.
Do it like this:
Create a main program (Main.Prg) that instantiates your main menu, main form (DO Form xxx), etc., then issue a READ EVENTS statement.
The form is displayed and stays awaiting user input.
To end, place a CLEAR EVENTS in the Exit button or Exit Option of you main menu. This would bring the program out of the event loop back into Main.Prg at the line immediately after READ EVENTS. That is where you do the final cleanup before QUIT.
See also the help file for:
ON SHUTDOWN
T-Jay
:)
IloveThis
Now click on the METHODS Tab
Move all the way down to the bottom and the name of your Method should be there.
Double click on the area to the right of the name, a code window will pop up.
Enter the code into this area and Save it when you are done (control key + W) saves it.
Slaru
Designs
Here is a sample method you can use parts of to help you understand.
This sample has a form that has fields on it with the following NAMES (in the properties window that is)
PRICE
TAX
LICENSEFEES
TOTALPRICE
METHOD created called CalcTax is below as a sample (not complete but you get the idea I hope)
**Method CalcTax
WITH thisform
.lnNoTradeTaxAmount.value=.Price.value * (.Tax.value/100)
.lnTradeTaxAmount.value=((.Price.value - .saledisc.value) - .tradein.value) * (.Tax.value/100)
.lnTotalPrice.value = .pricebeforetax.Value * .lnTradeTaxAmount.value + .LicenseFees.value + .DeliveryFees.value
** now refresh the controls on the form
.refresh()
ENDWITH
I call this method from the VALID of each control that can change the total amount. In the PRICE Valid I place this code:
thisform.CalcTax()
As soon as I press enter all the totals are updated for the new amounts.