Using ANSI Escape Sequences to Clear the Screen

Last reviewed: July 17, 1995
Article ID: Q67195
The information in this article applies to:
  • Microsoft FORTRAN for MS-DOS, versions 3.2, 3.3, 3.31, 4.0, 4.01, 4.1, 5.0, and 5.1
  • Microsoft FORTRAN for OS/2, versions 4.1, 5.0, and 5.1

SUMMARY

An ANSI escape sequence can be used within a FORTRAN program to clear the screen. Programs can use a subset of the ANSI 3.64-1979 standard escape sequences to erase the display, set the display mode and attributes, and control the cursor in a hardware-independent manner.

MORE INFORMATION

In real mode, the ANSI.SYS device driver is used to support ANSI escape sequences. It is installed in the CONFIG.SYS file with the following command:

   DEVICE=[drive:][path]ANSI.SYS

In protected mode, support for ANSI escape sequences come from an OS/2 AVIO ("advanced video input/output") function.

An ANSI escape sequence is a sequence of ASCII characters, the first two of which must be the escape character (char(27)) and the left-bracket character ([). The characters following the escape and left-bracket characters vary with the type of control function being performed.

An escape sequence cannot be entered directly at the system prompt because each ANSI escape sequence must begin with an escape character. If you press the ESC key, MS-DOS cancels the command line.

The following program uses the ANSI escape sequence (ESC[2J) to clear the screen:

      character*1 clrstr(4)
      data clrstr /' ','[','2','J'/
      clrstr(1) = char(27)            ! Escape character (ASCII 27).
      write (*,'(1x,4a1\)') clrstr    ! You must use a 1x as the first
      end                             ! part of the format specifier
                                      ! to ensure output of escape
                                      ! character.

The CHAR(int) intrinsic function is used to form either printing or nonprinting characters using the corresponding integer from the ASCII table.


Additional reference words: kbinf 5.00 5.10
KBCategory: kbprg kbcode
KBSubcategory: FORTLngIss


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 17, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.