How to Use a Custom Method as a User-Defined Function (UDF)ID: Q136010 The information in this article applies to:
SUMMARYThis article gives details about how to create and use custom methods. In FoxPro version 2.x, you can define procedures and functions in the cleanup code of FoxPro version 2.x screens. Forms in Visual FoxPro don't have an analogous place for defining procedures and functions, so you can:
MORE INFORMATIONCustom methods can be coded to behave as functions behave; that is, they can return a value simply by ending the code definition with RETURN x where x is the name of a variable whose value is set in the method. Custom methods should not begin with the PROCEDURE or FUNCTION command, which is normally used to indicate that a procedure or function is being defined, nor should they end with ENDPROC or ENDFUNC.
Step-by-Step Example1. Create a new form, and add two text boxes (Text1 and Text2) and two 2. Add the Customer and Orders tables from the Testdata database to the
3. Set the ControlSource for the Text1 box to:
4. Set the ReadOnly property for the Text1 box to True (.T.).
5. Leave the ControlSource property for the Text2 box blank. 6. On the Form menu, click New Method. Enter Custcount as the name of the 7. Change the caption of the Command1 button to "Count orders," and enter
8. Change the caption of the Command2 button to Skip, and enter the
9. Enter the following code for the Custcount custom method:
When you click the Count orders button, the Custcount custom method is
called to count how many orders exist in the Orders table for the current
record in the Customer table. This number is returned to the Count orders
button.
Additional reference words: 3.00 VFoxWin KBCategory: kbprg kbcode KBSubcategory: FxprgClassoop |
Last Reviewed: August 31, 1995 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |