Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing param list to function but have it arrive as arr
Message
De
19/06/2002 11:53:29
 
 
À
19/06/2002 06:51:41
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00670055
Message ID:
00670164
Vues:
22
>I want to pass a series of parameters to a function but have them arrive in the function as an array.
>
>So far there are 2 ways I can think of doing this but I am hoping there is a more obvious way that I am missing.
>
>eg
>
>
>
>? myfunc('apple','orange','pear')
>
>
>func myfunc
>lparam myarray  && somehow this needs to get populated from the param list
>? myarray(1)
>? myarray(2)
>? myarray(3)
>return
>
>
>
>Here are the ways I am considering using
>
>1. Create the array first and send it by reference :( not pretty
>
>2. send a single string myfunc('apple,orange,pear') and then parse the string into an array.


>
>this is a great little function for parsing a comma deliminated string into an array
>* nRows = ALINES(myarray, STRTRAN(cTest,",",CHR(13)))
>
>
>Can someone put my mind at rest, whats the obvious thing I am missing?


Mark,

Here's a method I sometimes use
function FunctionWithVarArgs

lparameters	_p01,_p02,_p03,_p04,_p05,_p06,_p07,_p08,_p09,_p10,_p11,_p12,_p13, ;
		_p14,_p15,_p16,_p17,_p18,_p19,_p20,_p21,_p22,_p23,_p24,_p25,_p26,_p27
	
	local argc, argv[1], _i_, _p_
	argc = pcount()
	dime argv[ max(argc, 1) ]
	for _i_ = 1 to argc
		_p_ = '_p' + padl(ltrim(str(_i_,4,0)),2,'0')
		argv[_i_] = &_p_
	endfor
	
	release all like _p??
	release _i_, _p_

        local i
        for i = 1 to argc
            ?argv[ i ]
        endfor
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform