kldck_hul:
Like: VAR("Pattern"+STR$(pnum))
. I think that would be necessary. Now I've got to think about this a bit.
Here are a couple of functions which I use to read and write arrays to prog slots. I created them because I wanted to save any number of arrays at runtime, and didn't want the SAVE command's dialog prompt to appear.
Firstly a little helper function, ARR2STR:
COMMON DEF ARR2STR(A)
VAR O$="" 'OUTPUT STRING
VAR I%=0 'COUNTER
'USING PUSH() IS MUCH FASTER THAN APPENDING TO STRING
FOR I%=0 TO LEN(A)-1
PUSH O$,STR$(A[I%])+","
NEXT
'STRING TRAILING COMMA AND RETURN:
RETURN LEFT$(T$,LEN(T$)-1)
END
And here are the two functions:
'COPY ARRAY A TO PRG SLOT P%
'AS DATA LINES WITH LABEL L$
COMMON DEF ARR2PRG A,P%,L$
DIM S$ 'STRING USED TO SEARCH PRG
IF P%>=0 AND P%<4 THEN
USE P%
IF CHKLABEL(STR$(P%)+":@"+L$) THEN
'L$ EXISTS, FIND WHERE TO OVERWRITE:
PRGEDIT P%,1
REPEAT
S$=PRGGET()
UNTIL "@"+L$+CHR$(10)==S$ OR ""==S$
'NOW HAVE THE INSERTION POINT.
'EMPTY STRING CONDITION SHOULD NEVER MATCH
ELSE
PRGEDIT P%,-1 'START INSERTION AT EOF
ENDIF
PRGSET "@"+L$
PRGSET "DATA "+STR$(LEN(A))+" 'ARRAY LENGTH"
PRGSET "DATA "+ARR2STR(A)
ELSE
?"ARR2PRG(ARRAY,PRG%,LABEL$)"
?"* PRG% MUST BE 0,1,2, OR 3"
ENDIF
END
COMMON DEF PRG2ARR(P%,L$)
DIM L%=0 'LENGTH
DIM T 'TEMP VARIABLE
DIM O[0] 'OUTPUT ARRAY
IF P%>=0 AND P<4 THEN
IF P%>0 THEN
USE P%
ENDIF
L$=STR$(P%)+":@"+L$
IF CHKLABEL(L$) THEN
RESTORE L$
READ L%
WHILE L%>0
READ T
PUSH O,T
DEC L%
WEND
RETURN O
ELSE
?"ERROR: '"+L$+"' NOT FOUND"
ENDIF
ELSE
?"PRG2ARR(PRG%,LABEL$) RETURNS ARRAY"
?"* PRG% MUST BE 0,1,2, OR 3"
ENDIF
END
Hope this helps.
Bear in mind these functions only work with number types. You'll need to tweak them for strings.
EDIT: just to follow up: these functions only work with 1D arrays. Also, large arrays (eg. the output of GSAVE()) will probably use too much memory and fail.
I have a version of ARR2STR which uses COPY to copy the input to a temporary array first, which has the side-effect of flattening it if it's a multi-dimensional array.
The main problem is that there's no way to determine the width of a multidimensional array, so you need to store that extra bit of info when saving and restoring.
It just ends up being a pain, and easier to use multiple 1D arrays than to mess with 2D or higher...