//by Jon Ripley, May 2011//\\ \\ //​Alternative method added by Steve Drain, Oct 2013//\\ \\ BBC BASIC for Windows does not provide a simple method of writing arrays to a file and reading them back again, doing so traditionally requires looping through the array and saving each separate item individually.\\ \\ The PROC_ReadArray and PROC_WriteArray routines below provide equivalents to PRINT# and INPUT# for arrays and are faster than the traditional method in most cases.\\ \\

//by Jon Ripley, May 2011//\\ \\ //​Alternative method added by Steve Drain, Oct 2013//\\ \\ BBC BASIC for Windows does not provide a simple method of writing arrays to a file and reading them back again, doing so traditionally requires looping through the array and saving each separate item individually.\\ \\ The PROC_ReadArray and PROC_WriteArray routines below provide equivalents to PRINT# and INPUT# for arrays and are faster than the traditional method in most cases.\\ \\

+

<code bb4w>

PROC_WriteArray(fileHandle%,​ ^array())

PROC_WriteArray(fileHandle%,​ ^array())

PROC_ReadArray(fileHandle%,​ ^array())

PROC_ReadArray(fileHandle%,​ ^array())

+

</​code>​

\\ When reading and writing arrays you must prefix the array variable name with the address of operator, the **^** symbol, this allows us to pass all types of array to a single routine rather than requiring a separate routine for each.\\ \\ **PROC_WriteArray** writes the contents of an array to the file specified by fileHandle%.\\ \\

\\ When reading and writing arrays you must prefix the array variable name with the address of operator, the **^** symbol, this allows us to pass all types of array to a single routine rather than requiring a separate routine for each.\\ \\ **PROC_WriteArray** writes the contents of an array to the file specified by fileHandle%.\\ \\

+

<code bb4w>

DIM array(9, 9, 9, 9)

DIM array(9, 9, 9, 9)

REM Initialise array

REM Initialise array

Line 10:

Line 13:

PROC_WriteArray(fileHandle%,​ ^array())

PROC_WriteArray(fileHandle%,​ ^array())

CLOSE#​fileHandle%

CLOSE#​fileHandle%

+

</​code>​

\\ **PROC_ReadArray** reads data from the file specified by fileHandle% and stores it in the specified array.\\ \\

\\ **PROC_ReadArray** reads data from the file specified by fileHandle% and stores it in the specified array.\\ \\

+

<code bb4w>

DIM array(1000, 10)

DIM array(1000, 10)

fileHandle% = OPENIN("​data.dat"​)

fileHandle% = OPENIN("​data.dat"​)

PROC_ReadArray(fileHandle%,​ ^array())

PROC_ReadArray(fileHandle%,​ ^array())

CLOSE#​fileHandle%

CLOSE#​fileHandle%

+

</​code>​

\\ For more information about **PROC_SwapMemory** see [[/​swapping%20the%20contents%20of%20two%20areas%20of%20memory|swapping the contents of two areas of memory]].\\ \\ The full code for PROC_ReadArray,​ PROC_WriteArray and PROC_SwapMemory is as follows:\\ \\

\\ For more information about **PROC_SwapMemory** see [[/​swapping%20the%20contents%20of%20two%20areas%20of%20memory|swapping the contents of two areas of memory]].\\ \\ The full code for PROC_ReadArray,​ PROC_WriteArray and PROC_SwapMemory is as follows:\\ \\