yolo
yolo

Reputation: 2795

FoxPro sum form fields

Using autogenerated form from a single database table. The form uses the class WizBtns included in c:\Program Files\Microsoft Visual FoxPro 9\Wizards. The form has Top, Previous, Next and Bottom buttons.

Although the form only has textboxes to enter data for the fields in the table, I have added a custom Text Box from the toolbox which basically intends to display the sum of some fields. I have bound the ControlSource of the text box to a PUBLIC variable costTotal that is created on the form init.

Now the problem is updating the sum of fields in the text box, or simply updating value of costTotal. Where to add the code for this? Adding the code in the form's Refresh method mixes up the value of costTotal, when I press Next button to update all fields with new values, the custom text box displays the sum of the last record which is mysterious.

Upvotes: 1

Views: 2297

Answers (3)

Carlos Alloatti
Carlos Alloatti

Reputation: 313

Couple of things:

1) do not use the wizards! Make your own base classes. Trying to figure out what the wizard classes do and how to add functionality will take more time that coding your own base classes. Also, the wizard generated code and classes must be at around 10/20 years old, much has changed since then (a polite way to say they suck).

2) Do not EVER use public variables in FoxPro, except for maybe an app object.

If this is a one shot thing, just add default textboxes and buttons and design the form yourself. You will have total control and you will know what each thing does.

Upvotes: 0

Hugh CB
Hugh CB

Reputation: 31

There is nothing wrong with using the refresh event to recalculate the values, just make sure that you call the refresh each time the record changes

If you are using navigation buttons to move between records then the click event of EACH button is an ideal place to issue the refresh request :-

Assuming the textbox is called txtSum and is located on the same form as the navigation buttons then in each buttons click event add this code

dodefualt()
with thisform
 .txtSum.refresh()
endwith

Upvotes: 0

Tamar E. Granor
Tamar E. Granor

Reputation: 3937

I would add a method to the form to do the calculation. Then, call that method from the Valid method of each of the textboxes involved in the calculation.

Upvotes: 1

Related Questions