SCREEN function

Purpose: SCREEN returns the ASCII value of the character located at coordinates vertical y%, horizontal x%. If the optional Mode% parameter is set to 1 then the color attributes of the character located at coordinates y%, x% is returned. This function works only in console mode programs.


 Syntax:

 RetVal% = SCREEN(y%, x% [, Mode%])

 Parameters:

  • RetVal% Returned attribute.
  • Ypos% Vertical console mode screen position.
  • Xpos% Horizontal console mode screen position.
  • Mode% [OPTIONAL] If set to 1 the color attributes of the character located at coordinates y, x is returned.

The following program demonstrates how to extract foreground and background color information from RetVal% when Mode% is set to 1.


 'Written by Robert Wishlaw December 31, 2001.
 
 DIM a$, b%, c%, d$
 
 CLS
 
 COLOR 15, 4
 a$ = "B"
 LOCATE 2,11,0
 PRINT a$
 COLOR 4, 7
 a$ = "C"
 LOCATE 2,12,0
 PRINT a$
 COLOR 15, 4
 a$ = "X"
 LOCATE 2,13,0
 PRINT a$
 COLOR 7, 0
 a$ = " "
 LOCATE 2,14,0
 PRINT a$
 
 b% = SCREEN(2,11) ' Note third OPTIONAL parameter is not used
 ' when retrieving the ASCII value of the character
 
 d$ = STR$(b%) & " is the ASCII value of char " & CHR$(b%)
 LOCATE 4,1,0
 PRINT d$
 d$ = " at coordinates vertical 2, horizontal 11"
 PRINT d$
 
 b% = SCREEN(2,11,1) ' NOTE use of the third OPTIONAL parameter
 ' to signal retrieval of character attributes.
 
 c% = b% AND 15 ' Calculates FOREGROUND color value
 
 SELECT CASE c%
 
 CASE 0
   PRINT " FOREGROUND COLOR is Black"
 CASE 1
   PRINT " FOREGROUND COLOR is Blue"
 CASE 2
   PRINT " FOREGROUND COLOR is Green"
 CASE 3
   PRINT " FOREGROUND COLOR is Cyan"
 CASE 4
   PRINT " FOREGROUND COLOR is Red"
 CASE 5
   PRINT " FOREGROUND COLOR is Purple"
 CASE 6
   PRINT " FOREGROUND COLOR is Brown"
 CASE 7
   PRINT " FOREGROUND COLOR is Light Grey"
 CASE 8
   PRINT " FOREGROUND COLOR is Dark Grey"
 CASE 9
   PRINT " FOREGROUND COLOR is Bright Blue"
 CASE 10
   PRINT " FOREGROUND COLOR is Bright Green"
 CASE 11
   PRINT " FOREGROUND COLOR is Bright Cyan"
 CASE 12
   PRINT " FOREGROUND COLOR is Bright Red"
 CASE 13
   PRINT " FOREGROUND COLOR is Bright Purple"
 CASE 14
   PRINT " FOREGROUND COLOR is Yellow"
 CASE 15
   PRINT " FOREGROUND COLOR is White"
 
 END SELECT
 
 c% =(b% AND 112) / 16 ' Calculates BACKGOUND color value.
 
 SELECT CASE c%
 
 CASE 0
   PRINT " BACKGROUND COLOR is Black"
 CASE 1
   PRINT " BACKGROUND COLOR is Blue"
 CASE 2
   PRINT " BACKGROUND COLOR is Green"
 CASE 3
   PRINT " BACKGROUND COLOR is Cyan"
 CASE 4
   PRINT " BACKGROUND COLOR is Red"
 CASE 5
   PRINT " BACKGROUND COLOR is Purple"
 CASE 6
   PRINT " BACKGROUND COLOR is Brown"
 CASE 7
   PRINT " BACKGROUND COLOR is Light Grey"
 
 END SELECT
 
 END
 

BCX Console Sample Programs using SCREEN function.

S140.bas