User Tools

Site Tools


passing_20arrays_20to_20subs_20and_20functions

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

passing_20arrays_20to_20subs_20and_20functions [2018/03/31 13:19]
127.0.0.1 external edit
passing_20arrays_20to_20subs_20and_20functions [2018/04/17 18:08] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //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:​\\ ​ //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 lb>
       one(5) = 123       one(5) = 123
       call test one()       call test one()
Line 9: Line 10:
       print two(5)       print two(5)
   end sub   end sub
 +</​code>​
 To demonstrate that the array **two()** is genuinely '​local'​ to the SUB:​\\ ​ To demonstrate that the array **two()** is genuinely '​local'​ to the SUB:​\\ ​
 +<code lb>
       one(5) = 123       one(5) = 123
       two(5) = 456       two(5) = 456
Line 19: Line 22:
       print two(5)       print two(5)
   end sub   end sub
 +</​code>​
 Arrays are automatically passed 'by reference'​ (you don't need to specify BYREF):​\\ ​ Arrays are automatically passed 'by reference'​ (you don't need to specify BYREF):​\\ ​
 +<code lb>
       one(5) = 123       one(5) = 123
       two(5) = 456       two(5) = 456
Line 31: Line 36:
       two(5) = 789       two(5) = 789
   end sub   end sub
 +</​code>​
 But you **must** use BYREF if you want to REDIM the array inside the SUB (requires LBB v2.53 or later):​\\ ​ But you **must** use BYREF if you want to REDIM the array inside the SUB (requires LBB v2.53 or later):​\\ ​
 +<code lb>
       one(5) = 123       one(5) = 123
       two(5) = 456       two(5) = 456
Line 44: Line 51:
       two(15) = 789       two(15) = 789
   end sub   end sub
 +</​code>​
 Of course you can use a FUNCTION instead of a SUB:​\\ ​ Of course you can use a FUNCTION instead of a SUB:​\\ ​
 +<code lb>
       one(5) = 123       one(5) = 123
       two(5) = 456       two(5) = 456
Line 56: Line 65:
       two(5) = 789       two(5) = 789
   end function   end function
 +</​code>​
passing_20arrays_20to_20subs_20and_20functions.txt ยท Last modified: 2018/04/17 18:08 by tbest3112