01-23-2025, 09:12 PM
So while making some routines into libraries we have this common problem when arrays are involved, which is...
How to use an array in the main or calling routine without having to stick a REDIM a$(0) in that routine.
In other words say we need a$() in the calling routine and the library we are going to add for that routine like a mouse routine.
Main:
mouse x, y, a$()
Sub mouse (x, y, a$())
Static initiate
If initiate = 0 Then
initiate = 1
ReDim a$(_Height)
End If
End Sub
Now this will fail with a Duplicate Definition error, because a$() is being introduced as an array to be passed into the mouse sub, and therefore it must be initially defined in that calling routine, before it is passed.
So we have this, which will work...
Main:
ReDim a$(0)
mouse x, y, a$()
Sub mouse (x, y, a$())
Static initiate
If initiate = 0 Then
initiate = 1
ReDim a$(_Height)
End If
End Sub
...but we have to remember when we make the mouse routine part into a library, and use INCLUDE to add it to the main program, we also must remember it manually add the Redim() code in the calling procedure or make a companion library bi file that needs to also be included to add the needed Redim() statement in the main.
So am I missing any other library making alternatives here? If not, I feel a bit more compelled to just work with Shared arrays in a bi file, instead of passing them at all.
Pete
How to use an array in the main or calling routine without having to stick a REDIM a$(0) in that routine.
In other words say we need a$() in the calling routine and the library we are going to add for that routine like a mouse routine.
Main:
mouse x, y, a$()
Sub mouse (x, y, a$())
Static initiate
If initiate = 0 Then
initiate = 1
ReDim a$(_Height)
End If
End Sub
Now this will fail with a Duplicate Definition error, because a$() is being introduced as an array to be passed into the mouse sub, and therefore it must be initially defined in that calling routine, before it is passed.
So we have this, which will work...
Main:
ReDim a$(0)
mouse x, y, a$()
Sub mouse (x, y, a$())
Static initiate
If initiate = 0 Then
initiate = 1
ReDim a$(_Height)
End If
End Sub
...but we have to remember when we make the mouse routine part into a library, and use INCLUDE to add it to the main program, we also must remember it manually add the Redim() code in the calling procedure or make a companion library bi file that needs to also be included to add the needed Redim() statement in the main.
So am I missing any other library making alternatives here? If not, I feel a bit more compelled to just work with Shared arrays in a bi file, instead of passing them at all.
Pete