Graphics GET/PUT and SaveArray/LoadArray Example in QuickBASIC (69584)
The information in this article applies to:
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0a
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0b
This article was previously published under Q69584 SUMMARY
A sample program below demonstrates how to use the SaveArray and
LoadArray MBLC routines found in Microsoft QuickBASIC versions 1.00,
1.00a, and 1.00b for Apple Macintosh. The sample program also
demonstrates the graphics GET and PUT statements using a
multidimensional array.
MORE INFORMATION
The graphics GET statement gets a bit image from the screen and places
that bit image into an array in memory. The graphics PUT statement
draws the bit image in this array back onto any area on the output
window.
SaveArray saves any array to the resource fork of any disk file.
LoadArray loads the previously-saved array from disk into a QuickBASIC
array in memory.
The LoadArray and SaveArray MBLC routines are documented on pages 486
and 491 of the "Microsoft QuickBASIC for Apple Macintosh: Language
Reference" manual. GET and PUT are documented on pages 143-145 and
273-275.
The following sample program can (optionally) be run multiple times,
either compiled or interpreted. The program writes the array to the
resource file just once, thus avoiding the writing of duplicate arrays
into the resource file. (Overwriting resources to the same id% number
creates duplicate resources, which would need to be removed with
RemoveRes.)
If you want the program to store the array into the program's own
resource fork, you must modify the program to use SYSTEM(7) to obtain
the resource file reference number (ref%) of the currently running
program (instead of using OpenResFile/CloseResFile).
OpenResFile/CloseResFile are used only to access resource files that
are external to the currently running program.
Example of Graphics GET/PUT and SaveArray/LoadArray
ON BREAK GOSUB breakhandle : BREAK ON ' Required in interpreter.
ON ERROR GOTO handle ' This error handler required in interpreter.
resfile$ = "Array Storage File" 'File name in which to store array.
flag% = 0 ' Must initialize parameters of MBLC toolbox routines.
' Test if file named in resfile$ exists:
Exists resfile$, flag% ' flag% is -1 (true) if file exists
ref% = 0 ' Must initialize parameters of MBLC toolbox routines.
id% = 1 ' Must initialize parameters of MBLC toolbox routines.
' If resource file doesn't exist yet, then create it just once:
IF NOT flag% THEN
DIM X%(44,2) 'Array X%() is 45x3, or 135 elements, or 270 bytes
FOR J = 1 to 6
PRINT "1234567890" ' Draw anything here.
NEXT
GET (10,20)-(30,40),X%(0,1) ' Get any image into array, then get
GET (30,20)-(50,40),X%(0,2) 'another image into another dimension.
CLS ' Note: This example doesn't use the first part of X%(0,0).
PUT (1,50),X%(0,2) ' Confirms that the GET worked.
PUT (1,100),X%(0,1) ' Confirms that the GET worked.
LOCATE 15,1 : PRINT "Press any key to continue."
WHILE INKEY$ = "" : WEND
OpenResFile resfile$, ref% ' Open the resource fork of a file.
bytes% = 270
SaveArray ref%, x%(0,0), bytes%, id% 'Store array in resource fork
CloseResFile ref% ' Always close explicitly-opened resource files.
ERASE x% ' Erase the old array.
END IF
DIM y%(44,2) ' Dimension a new array to load into.
OpenResFile resfile$, ref% ' Open the resource file.
LoadArray ref%, id%, y%(0,0) ' Load the array from disk into y%()
PUT (100,50),y%(0,2) ' Confirms that the array has graphics in it.
PUT (100,100),y%(0,1) ' Confirms that the array has graphics in it.
CloseResFile ref% ' Always close explicitly-opened resource files.
LOCATE 15,1 : PRINT "Press any key to continue."
WHILE INKEY$ = "" : WEND
END
handle: ' Error handler, just in case an error occurs.
CloseResFile ref% ' In the interpreter, you must close opened
' resource files before ending the program, or else
' resources may be misplaced in wrong files.
' [An exception is that you should never close the
' ref% number returned by the SYSTEM(7) function.]
ERROR ERR ' Aborts program and displays which error occurred, if any.
STOP
breakhandle: 'Break (COMMAND+PERIOD) handler, required in interpreter:
CloseResfile ref%
PRINT "Program aborted by the user."
STOP
Modification Type: | Major | Last Reviewed: | 10/20/2003 |
---|
Keywords: | KB69584 |
---|
|