Question
· Apr 13, 2018

creating a macro with an unknown number of parameters

I use macros everyday, but its the first time I want to create a macro like this

I want to create a new macro whereby I can pass a variable amount of parameters

the macro (much simplified version) would be 

#define myMacro(%params)         $listBuild(any Number Of %params I pass in)

so I want to be able to call $$$myMacro(user,ID,vehicle)         ie 3 parameters would generate

$lb(user,ID,vehicle)

but equally I might want to call that same macro $$$myMacro(companyID)          ie 1 paramter and would generate

$lb(companyID)

so the question is, 

how can I create the macro without knowing how many parameters I'm passing in up front.

(Hope this makes sense)

kevin

Discussion (4)0
Log in or sign up to continue

that doesn't seem to work Eduard.

here's my macro (according to you)

#define testEmptyParams(%args)    i $listfind($listbuild("%args"),"")>0 $$$quitMissingParams
here's the call

    $$$testEmptyParams(ExtID,UserID,originalVehicleID,newVehicleID,reasonID)
 

when I compile that, I get

"Too many arguments to macro: 'testEmptyParams'"

I've tried removing the quotes inside the macro and it still says too many arguments.

so I want to do a nested $lb, and then quit with another macro $$$quitMissingParams.

because I'm testing for empty parameters, I never know how many params I want to pass in.

example

s a="1",b="2" i $listfind($listbuild(a,b),"")>0 w " - missing"

s a="",b="2" i $listfind($listbuild(a,b),"")>0 w " - missing"

s a="",b="2",c=3 i $listfind($listbuild(a,b,c),"")>0 w " - missing"

s a="1",b="2",c=3 i $listfind($listbuild(a,b,c),"")>0 w " - missing"

Am I missing something ?