[22 Feb 2011] function args

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
asymetrix
Posts: 6
Joined: Tue Feb 22, 2011 8:14 pm

[22 Feb 2011] function args

Post by asymetrix »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 22 Feb 2011 19:44:10 -0000

Hi

I am trying to understand function args, but the code gives strange results and breaks, i have no way of stepping through/adding breakpoint for debugging:

Code: Select all

Function p_test(param1, param2, ...)
   
   Local pars = arg.n
   Local k
   DebugPrint("param1=", arg[0], " param2=", arg[1])

   For k = 1 To arg.n
	DebugPrint("k=",k," To ", arg.n)
	DebugPrint ("k= ", k," arg[k-1]= ",arg[k-1])
   Next

   DebugPrint (" pars = ", arg.n)
EndFunction

p_test("mypar1","mypar2")
p_test("mypar1","mypar2","mypar3")

WaitEvent

from the Help, it was my understanding arg.n holds number of parameters and arg[0] to arg[arg.n-1] holds all arguments.

so : arg[0] should be "mypar1" arg[1] should be "mypar2"

then on last function arg[2] should be "mypar3"

I get strange results when the code works. I get error: Error in line 7 (Unnamed1): Table field 0 was not initialized!

can anyone assist ?
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

[23 Feb 2011] Re: function args

Post by lazi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 23 Feb 2011 17:06:02 +0100

Hello asymetrix
Function p_test(param1, param2, ...)
You get the params in arg[] from the THIRD param! If you name variables in the function definition (param1, param2) then you get the values exatly in that variable.

Check this:

Code: Select all

function p_test(param1,param2,...)

print("param1=",param1, "param2=",param2,"parametc=",arg[0], arg[1])

endfunction

p_test(1,2,3,4,5,6)

waitleftmouse

asymetrix
Posts: 6
Joined: Tue Feb 22, 2011 8:14 pm

[23 Feb 2011] Re: function args

Post by asymetrix »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Wed, 23 Feb 2011 19:05:49 -0000

I see, thanks for that it makes more sense :

I thought

Function p_test(param1, param2, ...)

meant P_test(arg[0],arg[1],arg[arg.n-1]

but you are saying the FIRST missing argument starts at arg[0].

Ok I can work with this..
Locked