Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with user defined functions
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00745324
Message ID:
00745330
Views:
19
This message has been marked as the solution to the initial question of the thread.
Hi Ulises.

If you create a new method of the form, you can put all the code in there, and just call the method from each lostfocus (thisform.NewMethodName()).

To create a new method, open the form, go to the Form menu option, and select "New Method." Give the method a name, and then in navigate to that method in the code window (select form on the left side combo, and then the new method name on the right).

PS: I believe that you can sum right to the THISFORM.text2.VALUE etc. without needing the intermediate xImpDD variable -- unless you are using that for another purpose not included in your sample code)?)

PPS: it might be quicker to sum those fields all at once:
SUM importedd TO xImpDD, costounit TO xCostoUnit, costot TO xCosTot, costoumn TO xCostoUMN, costotmn TO xCosTotMN...





>Hi everyone..
>I have this form with many calculated fields. Since the values of these fields are dependent upon values of several other fields, which can be modified at will by the user, I have the same lines of code repeated over and over in the Lostfocus event of these fields. So I have this code repeated about 7 or 8 times in my form:
>
>SUM importedd TO xImpDD
>SUM costounit TO xCostoUnit
>SUM costot TO xCosTot
>SUM costoumn TO xCostoUMN
>SUM costotmn TO xCosTotMN
>
>THISFORM.text2.VALUE=xImpDD
>THISFORM.text9.VALUE=xCostoUnit
>THISFORM.text10.VALUE=xCosTot
>THISFORM.text11.VALUE=xCostoUMN
>THISFORM.text12.VALUE=xCosTotMN
>
>and if I have to do modifications I have to do it in every instance. I know this is not good programming.
>
>I think this can be done by writing a function once, but I'm lost regarding this subject.
>Could somebody give me some general advise about how to write and make a function work, or maybe direct me towards an article that deals with this subject? VFP Help is not much help.
>Thank you again for your time.
>Ulises
The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts. - Bertrand Russell
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform