Microsoft KB Archive/41581

= More Information about Basic's DRAW Statement Macro Language =

Article ID: 41581

Article Last Modified on 11/21/2006



This article was previously published under Q41581



SUMMARY
This information illustrates the DRAW statement, which is supported in the following products:


 * 1) Microsoft QuickBasic Compiler Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for the IBM PC
 * 2) Microsoft Basic Compiler Versions 6.00 and 6.00b for MS OS/2 and MS-DOS
 * 3) Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2.
 * 4) Microsoft GW-Basic Interpreter Versions 3.20, 3.22, and 3.23



MORE INFORMATION
The DRAW statement is only valid in a graphics mode (i.e., SCREEN 1, 2, and higher). The DRAW statement is not supported in SCREEN 0.

DRAW allows you to draw lines, shapes, change colors, fill in areas, and also perform powerful graphic functions. The DRAW statement combines most of the capabilities of the other graphics statements found in Basic into an object-definition language called the Graphics Macro Language (GML).

The syntax for the DRAW statement is as follows:

DRAW string-expression

This syntax is documented under the Basic statement DRAW in the &quot;Microsoft GW-Basic Interpreter: User's Reference&quot; and the Basic language reference manuals for QuickBasic and the Basic compiler. The valid options for string expressions are also documented with the DRAW command.

The DRAW command expects a string expression that is composed of the following, where &quot;x&quot; is a reserved letter (command) and &quot;n&quot; is a numerical value, interpreted as a string:

xn

You can have one or more combinations of xn's separated by a space or a comma. The following are examples:   DRAW &quot;U5&quot;         'Moves the pointer Up 5 DRAW &quot;U5 L7&quot;     'Moves the pointer Up 5 and Left 7 DRAW &quot;U5,L7&quot;     'Moves the pointer Up 5 and Left 7 DRAW &quot;G5&quot;        'Moves the pointer diagonally down and left 5 The integer value of &quot;n&quot; can also be assigned to a string variable and then used as in the following example. You will have to concatenate the strings to build the command. The following is an example: A$ = &quot;200&quot; : B$ = &quot;120&quot; : DRAW &quot;M&quot; + A$ + &quot;,&quot; + B$ The value for &quot;n&quot; can also be stored in an integer variable, and then converted to a string using the VARPTR$ or STR$ functions. If using VARPTR$, you must include the extra &quot;=&quot; signs or else an &quot;Illegal function call&quot; error is generated. The syntax is as follows: A% = 200 : B% = 120 : DRAW &quot;M=&quot; + VARPTR$(A%) + &quot;,=&quot; + VARPTR$(B%) DRAW &quot;M&quot; + STR$(A%) + &quot;,&quot; + STR$(B%) This command moves the pointer to pixel location (200,120) on the screen.

DRAW &quot;X&quot; is another powerful command. This command allows you to execute a substring of commands. The Basic reference describes this as being a powerful tool to execute second, third, etc. strings, but does not give any examples.

The DRAW &quot;X&quot; command allows you to embed draw commands within a string variable and then execute that string at any point. This is a nice concept but can be accomplished with simpler means. The following is an example of DRAW &quot;X&quot;: D$ = &quot;F60 L120 E60 BD30 P1,2 BU30 E60 L120 F60 BU30 P1,2&quot; DRAW &quot;X&quot; + VARPTR$(D$) The above command draws two triangles, sitting one on top of the other, and fills them both in. The following two commands do the same thing: DRAW &quot;F60 L120 E60 BD30 P1,2 BU30 E60 L120 F60 BU30 P1,2&quot; or D$ = &quot;F60 L120 E60 BD30 P1,2 BU30 E60 L120 F60 BU30 P1,2&quot; DRAW D$ You can use whichever DRAW syntax is easiest for you.

Note: Remember the following when using DRAW:


 * 1) If your &quot;n&quot; value is an INTEGER, use string concatenation with VARPTR$ and EQUAL signs, or use STR$.
 * 2) If your &quot;n&quot; value is assigned as a STRING variable, use string concatenation.

This Graphics Macro Language (GML) is a very powerful addition to the Basic language, but there are limitations. The DRAW statement just draws graphics, it does not have any conditional or looping statements. Therefore, the DRAW &quot;X&quot; command is not recursive.

Please refer to the Basic language reference for further details about the DRAW statement.

Additional query words: QuickBas BasicCom

Keywords: KB41581

-

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

© Microsoft Corporation. All rights reserved.