• Print

Author Topic: Dynamic Array Resizing.  (Read 111 times)

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Dynamic Array Resizing.
« on: March 24, 2013, 05:56:06 AM »
Hi all,
    Is there any better way to resize arrays other than dynamically?
Code: [Select]
REM
DEFINT A-Z

'$dynamic
DIM Changable%(0)


SCREEN 12

'GOSUB resize
ReSizer Changable%()
xyz = UBOUND(Changable)
PRINT xyz
SLEEP
SYSTEM

'---------------
resize:
RANDOMIZE TIMER
z% = INT(RND * 10) + 10
PRINT z%
REDIM Changable%(z%)

RETURN

SUB ReSizer (Array%( 0))
RANDOMIZE TIMER
z% = INT(RND * 10) + 10
PRINT z%
REDIM Array%(z%)
END SUB
OlDosLover.

mcalkins

  • Hero Member
  • *****
  • Posts: 1269
    • qbasicmichael.com
    • Email
Re: Dynamic Array Resizing.
« Reply #1 on: March 24, 2013, 11:42:54 AM »
Better in what way? Faster? You're probably not going to get any simpler.

You don't need the '$DYNAMIC metacommand. REDIM always creates dynamic arrays, so if you replace the original DIM with REDIM, you can get rid of the metacommand.

If you need to preserve the contents of the array, you can use REDIM _PRESERVE. This works best for single dimensional arrays. (For multiple dimension arrays, you have to remember that they are "column major".)

Regards,
Michael
The QBASIC Forum Community: http://www.network54.com/index/10167 Includes off-topic subforums.
QB64 Off-topic subforum: http://qb64offtopic.freeforums.org/

OlDosLover

  • Hero Member
  • *****
  • Posts: 3859
  • OlDosLover
    • Email
Re: Dynamic Array Resizing.
« Reply #2 on: March 24, 2013, 04:35:51 PM »
Hi all,
   
Quote
You don't need the '$DYNAMIC metacommand. REDIM always creates dynamic arrays, so if you replace the original DIM with REDIM, you can get rid of the metacommand.
    Ahh didnt know that. You are a wealth of info Michael! And thats better to my way of thinking also!
OlDosLover.

  • Print