Microsoft KB Archive/50004

= Example of Saving Numeric Array to Disk Using BLOAD and BSAVE =

Article ID: 50004

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q50004



SUMMARY
The program below demonstrates how to BSAVE a numeric array as a memory image file to disk and how to BLOAD the array from disk into a new array in memory.

This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS, and to Microsoft PDS Version 7.00 for MS-DOS.



MORE INFORMATION
The BSAVE statement allows you to copy the contents of a memory location to a memory-image file on disk. A memory-image file is a byte-for-byte copy of what is in memory along with control information used by BLOAD to load the file. The program below initializes an array, transfers the contents of it to an output file using BSAVE, erases that array from memory, and then loads the saved array into a new array in memory using BLOAD.

Code Example
REM $DYNAMIC DIM array%(8, 8)      ' 9 elements per dimension. FOR i% = 0 TO 8       ' Initialize the array with desired values. FOR j% = 0 TO 8 array%(i%, j%) = i% + j%  ' Arbitrary values assigned. NEXT j% NEXT i% ' Set DEF SEG at the segment (paragraph address) of the array: DEF SEG = VARSEG(array%(0, 0)) ' Specify the output disk file name (JUNK.DAT), the offset of the ' starting address of the area in memory to be saved, and the number ' of bytes to save (9*9*2 is 162 bytes): BSAVE &quot;Junk.dat&quot;, VARPTR(array%(0, 0)), 162 DEF SEG               'Restore Basic segment to default PRINT &quot;After save&quot; ERASE array% DIM array2%(8, 8)     ' Dimension new array. DEF SEG = VARSEG(array2%(0, 0))  ' Set DEF SEG for subsequent BLOAD. BLOAD &quot;Junk.dat&quot;, VARPTR(array2%(0, 0))  ' Reloads the array. FOR j% = 0 TO 8 FOR i% = 0 TO 8 PRINT array2%(i%, j%);  ' Confirms array is reloaded. NEXT i%   PRINT NEXT j% The following is the output for this program: After save 0 1  2  3  4  5  6  7  8 1  2  3  4  5  6  7  8  9 2  3  4  5  6  7  8  9  10 3  4  5  6  7  8  9  10  11 4  5  6  7  8  9  10  11  12 5  6  7  8  9  10  11  12  13 6  7  8  9  10  11  12  13  14 7  8  9  10  11  12  13  14  15 8  9  10  11  12  13  14  15  16

Additional query words: QuickBas BasicCom

Keywords: KB50004

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.