DiffRgn (Region) Example for Macintosh QuickBASIC and BASIC (45478)






This article was previously published under Q45478

SUMMARY

The following is an example of how to use the DiffRgn toolbox routine in Microsoft QuickBASIC Version 1.00, the Microsoft BASIC Interpreter Versions 2.00, 2.10, and 3.00, and the Microsoft BASIC Compiler Version 1.00 for the Apple Macintosh system.

The DiffRgn routine subtracts two graphics regions to create a third region that is the difference between the two.

MORE INFORMATION

Region handles in QuickBASIC Version 1.00 for Macintosh are long integers or single-precision numbers. In the BASIC 3.00 interpreter and the BASIC 1.00 compiler, they are single-precision numbers.

It is very easy to create a system error when working with any toolbox routine. You should be careful and save your program before any run. Some regions also create SYSTEM errors when DiffRgn is used with them.

The following example is designed to work with the BASIC 3.00 interpreter and the BASIC 1.00 compiler. To make the example work with QuickBASIC, remove the LIBRARY statement. When compiling under QuickBASIC, compile with the "Include MBPCs & MBLCs" option; otherwise, you get an error 35, "Undefined subprogram."

This program example creates two regions, takes their difference, and displays the result.

Code Example

' This LIBRARY is needed for Interpreter 3.00 and Compiler 1.00:
LIBRARY "ToolLib"   ' Delete this line to use in QuickBASIC 1.00.

' Initialize the region parameters before calling the toolbox routines
' The variables can be long integers in QuickBASIC.
picture1! = 0
picture2! = 0
difpic!   = 0

' Define a new region and open it for picture1!
newrgn picture1!
openrgn

' Draw a set of lines in the region.
' Only the LINE command without the bf option can be used for this:
SHOWPEN
LINE (10,10)-(440,230),,b

'    If the following region is used for picture1! it will create
'    a system error when the diffrgn is taken:
'        FOR i = 1 to 300
'          LINE (0,300-i)-(i,300)
'        NEXT
'    This creates the system error because the toolbox routine
'    does not know how to take the difference of the two regions.

' Close the region:
closergn picture1!

' Define a second new region in picture2!
newrgn picture2!
openrgn

' Draw a figure in the region:
SHOWPEN
LINE (0,0)-(110,200)
LINE -(130,140)
LINE -(450,150)
LINE -(0,0)

' Close the region:
closergn picture2!

' Define the difference region:
newrgn difpic!

' Take the DiffRgn of picture1! and picture2!.  Picture2! is being
' subtracted from picture2! and the result is put in difpic!
diffrgn picture1!,picture2!,difpic!

' Now clear the screen and display the resultant diffrgn:
CLS
framergn difpic!

' Do a WHILE LOOP to display the picture until a key is pressed:
WHILE INKEY$="":WEND
				

Modification Type: Minor Last Reviewed: 1/8/2003
Keywords: KB45478