USE "C:\Program Files\Microsoft Visual Studio\MSDN98\98VS\1033\Samples\VFP98\Tastrade\Data\CUSTOMER.DBF" lnI = 0 SELECT sqlTest(), RECNO() FROM customer
FUNCTION sqlTest lnI = lnI+1 RETURN lnIAs Larry suggested, you could use private memvars and update the memvars from your UDF. The example below calculates a running total of the discount field. Note that the UDF skips the first call in order to get the correct result:
lnSum = 0 lnCount = 1 *-- calculate a running total of the discount field SELECT sqlTest(discount), discount FROM customer
FUNCTION sqlTest LPARAMETER tnValue *-- UDF that allows calculating running totals. *-- Adds tnValue to lnSum. *-- Assumes that the following variables are inititalized before *-- the SQL SELECT command: *-- PRIVATE lnCount, lnSum *-- lnCount = 1 *-- lnSum = 0 IF lnCount > 1 lnSum = lnSum + tnValue ELSE *-- skip first call (called by SQL parser) lnSum = 00000000.00 ENDIF lnCount = lnCount + 1 RETURN lnSum>Hi,
> >SELECT * FROM csrInvoice ; >WHERE THIS.Include(Qty, StockQty, @lnCount, @lnSum) ; >INTO CURSOR csrInvoice > >