Get and Put

Get and Put are very complicated statements, so it may be a while before this entire tutorial is completed. First off, Get. It is like the copy statement in windows (if you don't know what that is, you probably shouldn't be programming). It saves a section of the screen to an array, rather than to the clipboard. To create an array, you use the following code, generally at the beginning of your program:

dim shared YourArray%(1 to x)

Dim creates the array, shared tells QB that it should be available for all subroutines, YourArray% is the name of the array, and 1 to x (where x is the size of the array) tells QB how large the array is. Using 1 to x is better than just typing x because it allows QBasic to only use as much space as it needs, saving you the trouble of finding out exactly how large the array needs to be. I generally use the % sign after my arrays, rather than the defint a - z command because it doesn't mess up your other variables. Now, do you remember the B and BF switches for the line command? Get's coordinate system is very similar to them. You type the location of the upper left corner of the image you want to store, and then a hyphen, then the lower right coordinates, a comma (,), and then the name of the array to store it in (YourArray%). Here's an example, we're assuming something is at the example locations and that you already dimmed the array.

get (10, 10)-(20, 20), YourArray%

That was the simplest way to use the coordinate system. As with line, circle, pset, etc, you can use steps to define locations, but I explained that in another tutorial, and this one's complicated enough, so I won't go into details on it. Now, the really complicated command, Put (as if Get wasn't complicated enough). Put, well, what else, puts the image that you got with the Get command, and Put's it (no pun intended, okay, so maybe it was) at a specified location on the screen. You do the same thing with Put as you did with Get, except you don't specify the ending location, just the upper left corner. Here's an example:

put (10, 10), YourArray%

That example assumes that you got YourArray% with a Get command, and dimmed the array YourArray%. You should know how to do this by now. You can use steps (as with nearly all commands) to put the images like always. Some actionverbs (options) can be used to create special effects, such as animation. Here's a list of the actionverbs:

PSET- Draws the image as it is stored. Overwrites any image currently at those coordinates.
PRESET- Draws the image in reversed colors, also overwriting any existing image.
AND- Merges image with current image(s)
OR- Superimposes stored image with current image(s).
XOR- Reverses points with the current image or with the background. This can be used with progressive PUT Statements to create animation.

I believe that that covers the Put statement (see, that wasn't so hard).

Back to the Tutorials...

Email: cybertron@flashmail.com