BBC BASIC for Windows
Programming >> BBC BASIC language >> Resize Array
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1429647561

Resize Array
Post by Kirkkaf13 on Apr 21st, 2015, 8:19pm

Hello,

Is it possible to resize an array and keep the index values previously initialized?

I have attempted to redim an array and this can only be done on local and private arrays.

Thank you.


Re: Resize Array
Post by rtr2 on Apr 21st, 2015, 8:53pm

on Apr 21st, 2015, 8:19pm, Kirkkaf13 wrote:
Is it possible to resize an array and keep the index values previously initialized?

There's a Wiki article on exactly that subject, I'm surprised you didn't find it yourself:

http://bb4w.wikispaces.com/Re-dimensioning+arrays

From your description what you probably need is the PROCredimpreserve1d() routine. There's an example of its use listed in the article:

Code:
      DIM array(100)
      FOR I% = 0 TO 100
        array(I%) = SQR(I%)
      NEXT
      PROCredimpreserve1d(array(), ^array(1)-^array(0), 200)
      FOR I% = 101 TO 200
        array(I%) = SQR(I%)
      NEXT
      FOR I% = 0 TO 200
        IF array(I%) <> SQR(I%) STOP
      NEXT
      PRINT "Test completed successfully"
      END 

Richard.
Re: Resize Array
Post by Kirkkaf13 on Apr 21st, 2015, 9:01pm

Richard,

I did not consider the wiki page, I did thoroughly check the manual. Unfortunately I have limited Internet access at the moment while I wait for my new ISP to go live, therefore resorting to my blackberry device for a connection.

Anyway I appreciate your speedy response, this looks to be what I was after.

Thank you.