Passing+arrays+to+SUBs+and+FUNCTIONs

//by Richard Russell, March 2014//

LB Booster provides the capability of passing an entire array as a parameter to a SUB or a FUNCTION. Here is a simple example: code format="lb" one(5) = 123 call test one end

sub test two print two(5) end sub code To demonstrate that the array **two** is genuinely 'local' to the SUB: code format="lb" one(5) = 123 two(5) = 456 call test one print two(5) end

sub test two print two(5) end sub code Arrays are automatically passed 'by reference' (you don't need to specify BYREF): code format="lb" one(5) = 123 two(5) = 456 call test one print two(5) print one(5) end

sub test two print two(5) two(5) = 789 end sub code But you **must** use BYREF if you want to REDIM the array inside the SUB (requires LBB v2.53 or later): code format="lb" one(5) = 123 two(5) = 456 call test one print two(5) print one(15) end

sub test byref two print two(5) redim two(15) two(15) = 789 end sub code Of course you can use a FUNCTION instead of a SUB: code format="lb" one(5) = 123 two(5) = 456 print test(one) print two(5) print one(5) end

function test(two) test = two(5) two(5) = 789 end function code