Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Best practice – Form Calculations
Message
De
01/05/2005 07:27:05
 
 
À
01/05/2005 05:15:02
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01009973
Message ID:
01009987
Vues:
25
I fully agree that bindevent is perferct for this application, however I would not recommend binding to the interactive change as this event fires for EVERY keystroke! Rather I would use the following code:
Form::Init
* -- Use this "SET PROCEDURE" technique if using a "STANDARD" method to calculate
*------------------------------------------------------------------------------
if atc('\MySpecialCalc.',set('Procedure') = 0 && Check for "Standard" procedure 
  set procedure to MySpecialCalc additive
endif
*------------------------------------------------------------------------------
Bindevent(this.txtMyValue1,"lostfocus",this,"CalcResult",1)
Bindevent(this.txtMyValue2,"lostfocus",this,"CalcResult",1)
Bindevent(this.txtMyValue3,"lostfocus",this,"CalcResult",1)
* -- Initially calculate the result
*------------------------------------------------------------------------------
this.CalcResult()
*------------------------------------------------------------------------------
Add new method to the form and/or use a "standard" procedure to calculate the result. If this calculation is used in various places in your system it would be advisable to make a "standard" procedure.
Form::CalcResult
<pre>
with this
  .txtMyValue4.value=.txtMyValue1.value + .txtMyValue2.value + .txtMyValue3.value
endwith
Or
with this
  This.txtMyValue4.value=MySpecialCalc(.txtMyValue1.value, .txtMyValue2.value,.txtMyValue3.value)
endwith
>For this purpose, Bindevent is perfect!
>In the textbox where you want the result, I call it txtResult, you have something like this in the Refresh:
>This.value=this.parent.txtMyValue1.value + this.parent.txtMyValue2.value + this.parent.txtMyValue3.value
>Add these lines to your form, for instance in the Gotfocus method:
>Bindevent(thisform.txtMyValue1,"interactivechange",thisform.txtResult,"refresh")
>Bindevent(thisform.txtMyValue2,"interactivechange",thisform.txtResult,"refresh")
>Bindevent(thisform.txtMyValue3,"interactivechange",thisform.txtResult,"refresh")
>Then whenever you change any of the values in txtMyValue1, txtMyValue2 or txtMyValue3, txtResult will also get updated.
>
>>How do you experts implement form calculations? What I mean by this is, a form has several numeric fields and I want to make calculations based on these fields and display the results on the form, updating the results every time there is a change.
>>
>>When the form is displayed, it should calculate and display the results. When there are any changes in the numeric fields it should recalculate and display the results.
>>
>>In that I am not much of a programmer, the more specific the answer the better.
>>
>>Thanks.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform