Microsoft KB Archive/59007

= Displaying Multiple Text Colors at Once on SCREEN 1 in Basic =

Article ID: 59007

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0

-



This article was previously published under Q59007



SUMMARY
In SCREEN 1, the COLOR statement cannot be used to put text of more than one color on the screen at one time. However, this can be done by using the ROM BIOS Interrupt 10h, function 9, which displays a character with a specified attribute at the current cursor position.



MORE INFORMATION
The specified attribute of a character can be 0, 1, 2, or 3. This attribute and the COLOR statement determine the color of the character. When an even expression (0 to 254) is the value for the palette in the COLOR statement, the default colors are 1 (green), 2 (red), and 3 (yellow on CGA, or brown on EGA). When an odd expression (1 to 255) is the value for the palette in the COLOR statement, the default colors are 1 (cyan), 2 (magenta), and 3 (white). When the attribute is 0, the character is the background color specified by the COLOR statement. Attribute 0 can be used to erase a character. If no COLOR statement is used, the default is COLOR 0,1.

The following program CALLs Interrupt 10h (16 decimal), with function 9, to display a character of a certain color on the screen.

This program allows text to be printed to the screen at the location of the cursor by CALLing a subprogram named PrintColors. The text, attribute, and row and colum position of the cursor are passed.

To use this program with Microsoft Visual Basic for MS-DOS, version 1.0, do the following:


 * 1) From the File menu, choose New Project.
 * 2) Copy the code example to the Code window.
 * 3) Press F5 to run the program.

To run this program in the VBDOS.EXE environment, you must invoke the environment with the /L switch to load the Quick library. For example:    VBDOS.EXE /L To use this program with Microsoft QuickBasic for MS-DOS, or Microsoft Basic PDS for MS-DOS, do the following:

 Invoke QuickBasic by typing the following:

QB /L QB.QLB (for QuickBasic 4.0, 4.0b, or 4.5)

or

QBX /L QBX.QLB (for Basic PDS 7.0)

(The /L option above loads the QB.QLB or QBX.QLB Quick library, which contains the CALL INTERRUPT routine.) QB.BI must be used in the $INCLUDE metacommand (see below). QB.BI contains the user-defined TYPEs RegTypeX and RegType. Refer to the QB.BI text file for more information. For Basic PDS 7.0, this file is called QBX.BI.  If you are compiling and linking outside the environment, QB.LIB must be linked in. For Basic PDS 7.0, you must link in QBX.LIB. REM $INCLUDE: 'VBDOS.BI' ' For QuickBasic for MS-DOS, you must include 'qb.bi' ' For Basic PDS for MS-DOS, you must include 'qbx.bi'

DECLARE SUB PrintColors (text$, attribute, col, row) DIM SHARED inregs AS RegType, outregs AS RegType CLS SCREEN 1 COLOR 0, 0                  ' Black background and even palette. col = 1: row = 1            ' Current position of the cursor. attribute = 1 CALL PrintColors(&quot;green text &quot;, attribute, col, row) attribute = 2

CALL PrintColors(&quot;red text &quot;, attribute, col, row) attribute = 3

CALL PrintColors(&quot;yellow/brown text&quot;, attribute, col, row) PRINT &quot;Default is yellow on CGA, brown on EGA&quot; END

REM Subprogram PrintColors prints text to the screen at position col REM and row in a color determined by the attribute passed and the REM palette selected by the COLOR statement. The cursor is updated.

SUB PrintColors (text$, attribute, col, row) FOR i = 1 TO LEN(text$) inregs.ax = &H900 + ASC(MID$(text$, i, 1)) ' Function 09 in the ' high part of the register and the ASCII ' code of a character in the low part. inregs.bx = attribute ' Display page (0 is the current page) in                         ' the high part and the attribute in the ' low part. inregs.cx = &H1      ' Number of times to display the character. CALL Interrupt(&H10, inregs, outregs) col = col + 1       ' Relocate the cursor one place to the right LOCATE row, col     ' for every character written to the screen. NEXT END SUB 

Additional query words: VBmsdos QuickBas BasicCom 1.00 2.00 2.01 3.00 4.00 4.00b 4.50 6.00 6.00b 7.00

Keywords: KB59007

-

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

© Microsoft Corporation. All rights reserved.