Page 1 of 1

Help: ReDim an Array from within a Procedure

Posted: Sun Aug 20, 2006 3:15 am
by texxsound
I want to change the size of StringArray$() from within the procedure.

Code: Select all

global dim StringArray$(size)
ArrayProcedure(StringArray$, anySize)
and the procedure

Code: Select all

Procedure ArrayProcedure(nameOfArrayToChange$, newArraySize)
 redim nameOfArrayToChange$(newArraySize)
endProcedure
But this will only change the size of the array nameOfArrayToChange$() within the procedure, but I want to change the size of the global array StringArray$() from within the procedure. Is there any way to do this? Because I have a large number of arrays to handle I don't want to make a procedure for every single one where the only thing that changes is the array-name.

Further, if I hand over the array-name to the procedure it thinks that it is a linked list but than an array.

Posted: Sun Aug 20, 2006 5:59 am
by netmaestro

Code: Select all

Macro ResizeArray(array,size)
  ReDim array(size)
EndMacro

Global Dim StringArray$(100)
Global Dim NumArray(100)

ResizeArray(NumArray, 500)
ResizeArray(StringArray$, 500)

NumArray(499) = 499
Debug NumArray(499)


StringArray$(499) = "Hello"
Debug stringarray$(499)
You use macros for that.
if I hand over the array-name to the procedure it thinks that it is a linked list
That's because you're doing it wrong. To pass an array it must have the number of dimensions in the brackets for the receiving procedure definition, this is what distinguishes it from a linkedlist:

Code: Select all

Procedure Show(ArrayIn(1))
  Debug ArrayIn(99)
EndProcedure

Dim NumArray(100)
NumArray(99) = 11
Show(NumArray())

Posted: Sun Aug 20, 2006 4:42 pm
by texxsound
oh that was the problem! i'll try that. thanks a lot!!

Posted: Sun Aug 20, 2006 5:12 pm
by Trond

Code: Select all

Dim Array.s(10)

Procedure A(Arr.s(1), Size)
  ReDim Arr.s(Size)
EndProcedure

A(Array(), 20)
Array(20) = "asdf2"