In fact, here's an up-to-date version of the code that supports scaling of string and numeric arrays:
Code:' Simple Array Functions
' by Joseph Essin and Richard Russell
'
' For use with LBB:
' http://www.bbcbasic.co.uk/lbb/
'
' The functionality to make this work is not found in
' Liberty BASIC alone. This is for use with Richard Russell's
' Liberty BASIC Booster "compiler." Richard even customized LBB
' to allow these user-defined functions to work.
'
' Please find LBB below:
' http://www.bbcbasic.co.uk/lbb/
' -------------------------------------------------------------- '
' -------------------------------------------------------------- '
' These are necessary for the Array Library.
' Don't name any of your arrays these names
' or you'll be subject to data loss.
redim ArrayLib(0)
redim ArrayLib$(0)
' -------------------------------------------------------------- '
function nsize(array())
' Returns the upper index limit of the numeric array array().
s = 2^24
do
on error goto [Error]
[Error]
s = int(s / 2)
temp = array(nsize + s)
nsize = nsize + s
loop until s = 0
end function
function size(array$())
' Returns the upper index limit of the string array array$().
s = 2^24
do
on error goto [Error]
[Error]
s = int(s / 2)
temp$ = array$(size + s)
size = size + s
loop until s = 0
end function
sub preserve byref array(), newSize
' Redimensions the given one-dimensional numeric array to the
' specified newSize.
u = nsize(array()) ' Get the upper limit
redim ArrayLib(u)
for i = 0 To u
ArrayLib(i) = array(i) ' Get old contents
next i
redim array(newSize) ' Resize given array.
for i = 0 To u
array(i) = ArrayLib(i) ' Replace old contents
next i
end sub
sub preserve$ byref array$(), newSize
' Redimensions the given one-dimensional string array to the
' specified newSize.
u = size(array$()) ' Get the upper limit
redim ArrayLib$(u)
for i = 0 To u
ArrayLib$(i) = array$(i) ' Get old contents
next i
redim array$(newSize) ' Resize given array.
for i = 0 To u
array$(i) = ArrayLib$(i) ' Replace old contents
next i
end sub