Compiler for .NET Wiki

Arrayparam new type for passing parameters like VB6

Modified: 2008/02/02 09:39 by pgilles - Categorized as: Wish List
All is in the title

Well you can understand it if you know what is arrayparam in VB.

For the people who do not know that, here is:

We would like to implement a function that takes a variable number of arguments and return the sum of squares. In VFP9 we are limited to 26 parameters, and we would have to declare that as this

PROCEDURE SumSquares
LPARAMETERS nVal1, nVal2, nVal3, nVal4  && more nVal until nVal26


The Compiler already supports arrayparam or VarArgs as in C++ with the following syntax, see the three dots after the last parameter.

PROCEDURE SumSquares
TPARAMETERS eValues() as double ...
LOCAL i, nResult
nResult = 0
FOR i = 0 TO ALEN(eValues)-1  && Start in zero because in .NET ParamArrays are zero based
	nResult = m.nResult + eValues(m.i)^2
ENDFOR
RETURN m.nResult


So you can run code as this:

? SumSquares(1,2,3,4)
? SumSquares(1,2,3,4,5,6,7)


the VFP compiler can this ? && i mean decrease len(lvalues) if # parameters exist after and dynamically (based on strong type)

PROCEDURE _icase
TPARAMETERS lValues() as boolean ..., eOtherwise as variant
.......
RETURN m.nResult


ScrewTurn Wiki version 2.0.2. Some of the icons created by FamFamFam.