Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Avg function
Message
De
27/06/2005 11:03:27
 
 
À
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:
01026726
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)
clear
? AVG(1)
? AVG(1,2)
? AVG(1,2,3,4,5,6,7,8,9)

? AVG2(1,2,3,NULL,5,6,7,8,9,4)

FUNCTION AVG
LPARAMETERS n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
		,	n11,n12,n13,n14,n15,n16,n17,n18,n19,n20;
		,	n21,n22,n23,n24,n25,n26
PRIVATE nSum,k
nSum = 0
FOR k=1 TO PARAMETERS()
	STORE m.nSum + EVALUATE("n"+LTRIM(STR(m.k))) TO nSum
NEXT
RETURN m.nSum/PARAMETERS()

FUNCTION AVG2 && SKIP NULLS
LPARAMETERS n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
		,	n11,n12,n13,n14,n15,n16,n17,n18,n19,n20;
		,	n21,n22,n23,n24,n25,n26
PRIVATE nSum,iCount,n
STORE 0 TO nSum
STORE 0 TO iCount
FOR k=1 TO PARAMETERS()
	STORE EVALUATE("n"+LTRIM(STR(m.k)))			 TO n
	IF ISNULL(m.n)
		LOOP
	ENDIF
	STORE m.iCount + 1 TO iCount
	STORE m.nSum + m.n TO nSum
NEXT
RETURN m.nSum/EVL(m.iCount,NULL)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform