Arrays cannot be passed to subs and functions
Jump to navigation
Jump to search
Description
Arrays cannot be passed to subs and functions.
The listed workaround obviates the most useful aspect of a subroutine, namely that of being able to use the same code to operate on more than one variable. This solution requires a different subroutine for each array name that the user wishes to process. If he only has to process one array, he doesn't need the subroutine. This REALLY needs to be fixed!
It is not strictly speaking a bug - as none promised it could be passed. So it not "needs to be" fixed. One may wish it could be *changed*, though.
Example code to demonstrate the bug.
dim array$(10)
array$(1) = "one"
array$(2)= "two"
call PrintArray array$()
wait
Sub PrintArray arrayname$()
for i = 1 to 10
if arrayname$(i)<>"" then print arrayname$(i)
next
end sub
Example code to work around the bug.
Arrays are global and can be accessed inside of subs and functions.
dim array$(10)
array$(1) = "one"
array$(2)= "two"
call PrintArray
wait
Sub PrintArray
for i = 1 to 10
if array$(i)<>"" then print array$(i)
next
end sub