Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avg function
Message
 
À
27/06/2005 09:58:19
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 8 SP1
Divers
Thread ID:
01026694
Message ID:
01026705
Vues:
14
>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform