Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
Can a BASIC+ function return a reference to an array ?
I want to do this:
Function Split(string, delimiter)
length = Count(string,delimiter)+1
Dim arr(length)
MatParse string Into arr Using delimiter
Return arr
but I get the compiler error:
Variable has been dimensioned and used without subscripts at the return line.
I want to obtain a reference to arr and return the reference from the function. But I can't figure out if that's possible. Then once I return the reference, how do I dereference it? Or is this beyond the capabilities of BASIC+ ?
Comments
Wanna walk a dynamic array when you don't care about what delimiters are used? The Remove statement is your answer.
Need to loop through each field? The substring operator combined with Col2() will be faster than converting to a matrix. (Or, install our free SRP Utilities and use the SRP_PreCompiler to add For Each loops to your code.)
The only time I convert to a Matrix is when I am about to do lots of random access on a large dynamic array, but that seems to be rare. I'm almost always walking an array or accessing a single item once in a while.
If you run into a need to optimize and are curious how we approach the problem, tell us the specific bottleneck you are dealing with. We've probably optimized it before.