passing_20arrays_20to_20subs_20and_20functions
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| passing_20arrays_20to_20subs_20and_20functions [2018/03/31 13:19] – external edit 127.0.0.1 | passing_20arrays_20to_20subs_20and_20functions [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| 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 | ||
| + | </ | ||
| To demonstrate that the array **two()** is genuinely ' | To demonstrate that the array **two()** is genuinely ' | ||
| + | <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 | ||
| + | </ | ||
| Arrays are automatically passed 'by reference' | Arrays are automatically passed 'by reference' | ||
| + | <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 | ||
| + | </ | ||
| 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 | ||
| + | </ | ||
| 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 | ||
| + | </ | ||
passing_20arrays_20to_20subs_20and_20functions.1522502372.txt.gz · Last modified: 2024/01/05 00:17 (external edit)