I wonder whether anybody out there has come across the same
problem I have, (and has found a solution).
Basically, what I would like is to be able to re-dimension an array within
a subroutine (proc/fn) BY PASSING THE SUBROUTINE THE ARRAY
AS A PARAMETER.
For example, I have an array f$ (10,10) and a variable 'mycount%'
which contains the last element of the array that is filled in.
>From time to time, a new element of the array must be fileld in, and
mycount% makes sure that I use an, up to now, unused element of the
array for that - and also that I don't go over the top of the array.
Since I do that with several arrays, whenever I fill in an element in the
array, I'd like to use some sort of procedure, which could be as follows:
def proc check_array(array$,count%,new_string_to_add$)
local a%,b%,temp_array$
a%=dimn(array$,1)
if count%<a%
array$(count%)=new_string_to_add$
count%=count%+1
else
[copy array to temp array]
b%=dimn(array$,2)
DIM array$(count%+100,b%)
[copy array back from temp array]
[set new element, as above]
endif
end def
and for the above example the procedure would be called with
check_array f$,mycount%,"whatever"
However, that doesn't work, as the line " DIM
array$(count%+100,b%)" will generate an error - you cannot
redimension an array passed as a parameter.
This is a well known problem on all QL ROMs (well at least it appears in my SBASIC/SuperBASIC Reference Manual) - SMSQ/e introduced the new error for this particular instance:
"Procedure and Function parameters may not be re-dimensioned".
Earlier QL ROMs allowed this without an error, but the array was not re-dimensioned and some of its values were destroyed !! Even worse, you could not then assign another value to the elements which had been changed by the attempted re-dimension.
SMSQ/e has an outstanding bug in this instance as well - take for example:
10 DIM x(10)
20 c=1:TEST c,x
100 DEFine PROCedure TEST(a,b)
110 DIM b(100)
120 END DEFine
Running this program gives the error as described.
However, try entering as a direct command:
CLEAR: TEST c,d
no error reported !!
PRINT c,1000 or PRINT c,d
:-(
Or try using the variable d afterwards, eg d=100 or x=d
Doh.....
Solutions??
=========
Only one I can think of is to use a different temporary array inside the PROCedure or FuNction, copy the calling array's contents to this temporary array and then re-define the original array on exit from the PROCedure or FuNction and copy its contents back from the temporary array.
--
Rich Mellor
RWAP Services
35 Chantry Croft, Kinsley, Pontefract, West Yorkshire, WF9 5JH
TEL: 01977 610509
http://hometown.aol.co.uk/rwapsoftware
