Microsoft KB Archive/45478

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

Article ID: 45478

Article Last Modified on 11/21/2006



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 &quot;Include MBPCs & MBLCs&quot; option; otherwise, you get an error 35, &quot;Undefined subprogram.&quot;

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 &quot;ToolLib&quot;  ' 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$=&quot;&quot;:WEND

Additional query words: BasicCom MQuickB

Keywords: KB45478

-

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

© Microsoft Corporation. All rights reserved.