Help: ReDim an Array from within a Procedure

Just starting out? Need help? Post your questions and find answers here.
texxsound
User
User
Posts: 11
Joined: Sun Aug 29, 2004 12:04 pm
Location: Austria, EU

Help: ReDim an Array from within a Procedure

Post 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.
Some do code in sweet delight, some do code in endless night
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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())
BERESHEIT
texxsound
User
User
Posts: 11
Joined: Sun Aug 29, 2004 12:04 pm
Location: Austria, EU

Post by texxsound »

oh that was the problem! i'll try that. thanks a lot!!
Some do code in sweet delight, some do code in endless night
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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"
Post Reply