User Tools

Site Tools


mmbasic:redim_redimension_an_array

REDIM Redimension an array (VB work-a-like)

VB6 is arguably the pinnacle of the traditional Microsoft basics (i.e. before the arrival of .NET with its bloat and some very “new” approaches that alienated decades of BASIC programmers). Array management was excellent and combined with TYPEs allowed very close analogues with C's STRUCTs. It is easy to let our enthusiasm run away with us when faced with an amazing product like MMBasic, but we must temper our expectations - these are micro-controllers after all, not PCs.

That said, dynamically sized arrays are very useful for “moving targets” in the process world and the ability to re-use an array (and vary its size) is very useful.

MMBasic does not support REDIM but it can be emulated easily enough with ERASE and DIM - some care must be taken to trap any errors that might occur on the first iteration. VB6 REDIM permitted dimensioning an array for the first time (implicit DIM). MMBasic will throw errors if you try to ERASE a non-existent array:

  ON ERROR SKIP
  ERASE A$       ' this will throw an error if A$ doesn't exist - hence the previous statement
  DIM A$(mynewsize)

VB6 also had the option of retaining the content of arrays with REDIM APPEND which trimmed excess elements or padded as necessary to achieve the new dimensions. Again, it would be nice to have but we must retain perspective.

mmbasic/redim_redimension_an_array.txt · Last modified: 2024/01/19 09:30 by 127.0.0.1