Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Calculations in a control box
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00129868
Message ID:
00130373
Vues:
27
Well, In my current project, I got some difference situation on your case.
Let's study and see the method(s) on handling.

i) RowTotal for Orditems,
i.e. carry the Orditems.Discount * Orditems.Qty * Item.SellPrice
I use a grid to do this, because in grid, the controlsource of textbox can be
an expression, i.e. just put the above formula as controlsource!
The only thing I need to do is to replace the RowTotal when:
Orditems.item , Qty or Discount value change!!

Barbara just highlight a point, if calculated value is non-positive, pls don't replace the actual Field!

ii) The Cubic Meters of the package,
i.e. Item.pkLength * Item.pkWidth * Item.pkHeight / 100000
I will take John's method.
Use a public Variable 'ItemCBM' to carry result and a new proc Thisfrom.CalCBM
to calculate the Cubic Meters.
Reason to use a new proc to calculate:
- when change record, all values are different and need re-calculate
- when any factor change, need re-calculate
...
Then, the textbox controlsource is 'ItemCBM'.
So, when ThisForm.Refresh is Called, this value will Refresh the right value.
No need to do other tasks unless the above events occur.
Although Public variable is not a good pratrise, It work fine as the value is only used to view(Not further action need to take!) and totally not to use in other form!



Actually, the most hard to do is not try to display right value or replace field in table. The most hard thing is to consider the possible cases to call the calculation process! ^_~ Good Luck!





>Diana,
>Your method will only work if the control source of the BALANCE textbox is set to the balance field, which is often not the case in calculated fields. If the control source is blank, you must explicitly give a replace to put the value into the buffer.
>
>Barbara
>
>>John,
>>
>>I should have thought it better programming practice to change the value of the balance textbox and let the save process change the table's field value when the user chooses to execute it. Anyone else have comments on this?
>>
>>Diana
>>
>>>Hi Eric ---
>>>
>>>Place the calculation in a custom method in the form, such as CalcBalance. In the LostFocus of each control that could affect the balance do a THISFORM.CalcBalance. In the CalcBalance method, calculate the balance and use REPLACE to store it in the balance field in the table. The balance textbox should have a ControlSource of the balance field. After you have done the REPLACE in the CalcBalance method, refresh the balance textbox (THISFORM.txtBalance.Refresh). Also ensure that the balance textbox is disabled.
>>>
>>>
>>>
>>>
>>>>
>>>>What I need to do is create a "balance" text box on one of my forms, which involves a simple calculation using several fields. My question is how do I do the calculation, and then put the result into a field called "balance" in my table?
>>>>
>>>>If I set the control source to the calculation, the balance comes up correct, but the result is not entered into the table.
>>>>
>>>>Does anybody have the code to do this?
>>>>
>>>>Thanks a lot,
>>>>Eric
The weak wait for chance, The strong bid for chance,
The clever notch up chance, but The merciful give you chance.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform