Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Avg function
Message
 
To
27/06/2005 09:58:19
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01026694
Message ID:
01026705
Views:
16
>Help please
>How can I get variables/properties average?
>The function avg() give me the average only from table\cursors.
>I can't run:
avg(3,5)
? MyAvg("3,5,7")

DIMENSION aAvg[3]
aAvg[1] = 3
aAvg[2] = 5
aAvg[3] = 9
? MyAvg(@aAvg)

FUNCTION MyAvg(eValues)
   LOCAL lnRetVal[1], lcArr[1]
   CREATE CURSOR cAvg (cField N (16,3))
   IF TYPE("eValues[1]") == "N" && Aray is passed
      FOR EACH oVal IN eValues
          INSERT INTO cAvg VALUES (oVal)
       NEXT
   ELSE
      ALINES(lcArr,eValues,.t.,[,])
      FOR EACH oVal IN lcArr
          INSERT INTO cAvg VALUES (VAL(oVal))
      NEXT
   ENDIF
   AVERAGE cField TO ARRAY lnRetVal

RETURN lnRetVal[1]
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform