Microsoft KB Archive/31157

= Use PRINT# to MS-DOS &quot;CON&quot; Device to Send ANSI Escape Codes =

Article ID: 31157

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft GW-BASIC 3.2
 * Microsoft GW-BASIC 3.22
 * Microsoft GW-BASIC 3.23
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft QuickBasic 1.0
 * Microsoft QuickBasic 1.01
 * Microsoft QuickBasic 1.02
 * Microsoft QuickBASIC 1.0b
 * Microsoft QuickBASIC 1.0b
 * Microsoft QuickBasic 2.0
 * Microsoft QuickBasic 2.01
 * Microsoft QuickBasic 3.0
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS

-



This article was previously published under Q31157



SUMMARY
Sending ANSI escape codes to the screen with the PRINT statement will not perform ANSI screen control because the PRINT statement (in the products below) circumvents DOS and its device drivers.

To make ANSI escape sequences work properly, you must OPEN the DOS &quot;CON&quot; or &quot;CONS:&quot; (console) device instead, and use PRINT# for output.

This information applies to the following products:


 * 1) QuickBasic Versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for IBM Personal Computers and Compatibles
 * 2) Microsoft Basic Compiler Version 6.00 and 6.00b for MS-DOS
 * 3) Microsoft Basic PDS Version 7.00 for MS-DOS and MS OS/2
 * 4) GW-Basic Versions 3.20, 3.21, 3.22, 3.23
 * 5) IBM and Compaq versions of BasicA



MORE INFORMATION
To make ANSI control characters work properly, do the following:


 * 1) Obtain the file ANSI.SYS from the DOS release disk. Put it on the root directory of your boot disk.
 * 2) Put the statement DEVICE=ANSI.SYS in the CONFIG.SYS file on the root directory of the boot disk.
 * 3) Reboot. If the message &quot;ANSI.SYS Not Found&quot; displays, the ANSI control codes will not work.
 * 4) In your Basic program, OPEN the DOS &quot;CON&quot; (console) device for output as #n.
 * 5) Use PRINT#n to send output to the DOS &quot;CON&quot; (console) device.
 * 6) CLOSE#n at the end of the program.

For a list of the ANSI escape sequences, refer to the following:


 * 1) The &quot;Microsoft MS-DOS Version 3.20 User's Reference,&quot; Appendix C &quot;Installable Device Drivers&quot;
 * 2) IBM PC-DOS technical reference manual

The following code demonstrates how to use ANSI screen control codes from Basic: 'The following example changes the background 'and foreground color of the screen, sets blinking and bold characters, 'and positions the cursor: CLS escape$ = CHR$(27) + &quot;[&quot; attriboff$ = escape$ + &quot;0m&quot; blinkon$ = &quot;5m&quot; bold$ = &quot;1m&quot; reversv$ = &quot;7m&quot; red$ = &quot;41m&quot; green$ = &quot;42m&quot; blue$ = &quot;44m&quot; blackback$ = &quot;40m&quot; x = 30 y = 10 rowcol$ = MID$(STR$(y), 2) + &quot;;&quot; + MID$(STR$(x), 2) + &quot;H&quot; OPEN &quot;CON&quot; FOR OUTPUT AS 1 PRINT #1, attriboff$; PRINT #1, escape$ + rowcol$ + &quot;Locate the cursor with ansi.sys&quot; PRINT #1, attriboff$; PRINT #1, escape$ + blinkon$ + &quot;Blinking&quot; + attriboff$; PRINT #1, escape$ + bold$ + &quot;Bold&quot; + attriboff$; PRINT #1, escape$ + reversv$ + &quot;reverse&quot; PRINT #1, escape$ + red$ + &quot;red&quot; PRINT #1, escape$ + green$ + &quot;green&quot; PRINT #1, escape$ + blue$ + &quot;blue&quot; CLOSE #1

Additional query words: QuickBas BasicCom

Keywords: KB31157

-

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

© Microsoft Corporation. All rights reserved.