Microsoft KB Archive/29943

= SCREEN Function Gives COLOR Attribute; Foreground, Background =

Article ID: 29943

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 1.01
 * Microsoft QuickBasic 1.02
 * Microsoft QuickBasic 2.01
 * 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
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q29943



SUMMARY
When using text mode (using the SCREEN statement with mode 0), the SCREEN function can return the color attribute of a character on the screen. If the SCREEN function is invoked at a location where a character is printed, the color attribute returned is a combination of the foreground and background colors. However, on a graphics screen mode (a SCREEN mode other than 0), the SCREEN function always returns zero.

If the character is not blinking (that is, the high-order, eighth bit is off), the foreground color can be obtained by taking the color attribute MOD 16, and the background color can be obtained by dividing the color attribute by 16. If the character is blinking, just turn off the eighth bit in the attribute byte before this calculation. For example: X% = SCREEN (1, 1, 1) X% = X% AND &amp;H7F  ' Turns off bit 8. The following formula shows the relationship between the attribute and the foreground and background colors, taking into account all eight bits of the attribute: ATTRIBUTE = 128*(FOREGROUND\16) + BACKGROUND*16 + (FOREGROUND MOD 16) This information applies to Microsoft QuickBasic versions 1.00, 1.01, 1.02, 2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS; to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2; and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.



MORE INFORMATION
The following is a bitmap of the attribute returned by the SCREEN function:        BIT ->    7     6     5     4     3     2     1     0 _________________________________________________              |  0  |  1  |  0  |  0  |  0  |  0  |  0  |  1  |               -                  ^     ^     ^     ^     ^     ^     ^     ^                  |     |     |     |     |     |     |     |        Blinking --     -     |     - |     Intensity --     | Background Color --                      -- Foreground Color

Code Example
CLS COLOR 4, 1 PRINT &quot;hello&quot;; X% = SCREEN (1, 1, 1) PRINT &quot;Attribute: &quot;; X% X% = X% AND &H7F         ' Makes sure blinking bit (bit 8) is off. PRINT &quot;Foreground: &quot;; X% MOD 16 PRINT &quot;Background: &quot;; X% \ 16

Additional query words: QuickBas BasicCom

Keywords: KB29943

-

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

© Microsoft Corporation. All rights reserved.