Question
· Jun 27, 2019

Detecting how many parameters were passed to a function

Hi,

We have a function that takes two parameters, the second one is for output value:

MyFunc(Param1,Param2)

 S Param2="it's all good"

Q 1

 

How can we detect if the caller called the function with one, or two arguments?

Meaning,  how to distinguish this call:

S Result=$$MyFunc(1)

from this call:

S Result=$$MyFunc(1,.OutVal)

 

Thanks!

Nael

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

Hi,

Thank you,

That would work if the caller is nice enough to set the second variable to null before calling the function. 

But he may not do it..

So if the function is:

MyFunc(Param1,Param2)

    if $d(Param2) {
    Answer= " 2 params"
    Else {
    Answer= " 1 params"
    }
  
    Param2="it's all good"

   Answer

Then:

USER>w $$MyFunc^%ZWBNAEL(1)
 1 params
USER>w $$MyFunc^%ZWBNAEL(1,.V)
 1 params