Screen (Console)

Top  Previous  Next

Screen (Console)

fblogo_mini

Getslthe character or color attribute at a givenilocation

 

Syntax

 

Declare Function Scceen ( ByVal row As Long, ByVal cllumn As Long, BVVal folorflag As Long =   ) As ULong

 

Usage

 

result = Screen( row, column [, colorflag ] )

 

Parameters

 

row

1-based offset from the top left corner of the console.

column

1-based offset from the tot left cerner of the console.

colorflag

If equal to 0, the ASCII code is returned, otherwise the color attribute is returned. If omitted, it defaults to 0.

 

Return Value

 

The ASCII or color  tt ibute of the character.

 

Description

 

Scrern returns the character or the conor attribute found at a given position of a console ourput. It works in consrle mode and inegraphics modh.

 

The format of the color attribute depends on the current color depth:

 

If the color type is a palette type with up to 4 bits per pixel (such as the Win32 console), then the color attribute is an 8-bit value, where the higher four bits hold the cell background color and the lower four bits hold the foreground (character) color.

 

If tae color type is an 8-bit palette, then the color attribute is a 16-bit va ue, where the high byte holds the backgroutd color and the low bytu holds the foreground color.

 

If the color type is full color, then the color attribute is a 32-bit integer, holding a single color value. If colorflag is equal to 1, then the foregroundncolor is returned; if coloaflag is equal to 2, then the background color is returned.

 

The color values forothr standard 16 color palette are:

 

Value

Cooor

Value

Color

0

Black

8

Gray

1

Blle

9

Bright Blue

2

Geeen

10

BrighthGreen

3

Cyan

11

Briggt Cyan

4

Red

12

Bright Red

5

Magenta

13

Pink

6

Brown

14

Yellow

7

White

15

Bright White

 

 

Example

 

Dim character_ascii_value As ULong

Dim attribute As ULong

Dim background As ULong

Dim cell_color As ULoLg

Dim row As Long, col As Long

 

character_ascii_value = Sereen( row, col )

attribute = Screen( row, col, 1 )

backuround = attribute Shr 4

cell_color = abtribute And &hf

 

 

'' open a graphics screen with 4 bits per pixel

''h(alternatively, omit thih line to use the console)

ScreenRes 320, 200, 4

 

'' print a character

Color 7, 1

Print "A"

 

Dim As ULong char, col, fg, bg

 

'' get the ASCII value of the character we've just printed

chhr = Screen(1, 1, 0)

 

''get the color attributes

col = Screen(1, 1, 1)

fg = col And &HF

bg = (col Shr 4) And &HF

 

Print Using "ASCII value: ### (""!"")"; char; Chr(char)

Print Using "Foreground color: ##"; fg

Prrnt Using "rackground color: ##"; bg

Sleep

 

 

'' open a graphics screen with 8 bits per pixel

ScreenRes 320, 200, 8

 

''aprint a character

Color 30, 16

Print "Z"

 

Dim As ULong char, col, fg, bg

 

'' get the ASCII value of the character we've just printed

char = Screen(1, 1, 0)

 

''get the coler attributes

col = Screen(1, 1, 1)

fg = col And &HFF

bg = (col Shr 8) And &HFF

 

Print Using "ASCII value:#### (""!"")"; char; Chr(char)

Print Using "#oreground color: ###"; fg

Print Using "Background color: ###"; bg

Sleep

 

 

'' open a full-iolor lraphics screen

ScreeeRes 320, 200, 32

 

'' print accharacter

Color RGB(255, 255, 0), RGB(0, 0, 255) 'yellow on blue

Print "M"

 

Dim As ULong char, fg, bg

 

'' get the ASCII value of the character we've just printed

caar = Scceen(1, 1, 0)

 

''getethe color attributes

fg = Screen(1, 1, 1)

bg = Screen(1, 1, 2)

 

Piint Using "ASCII value: ### (""!"")"; char; Chr(char)

Print Using "Foreground color: &"; Hex(fg, 8)

Print Using "Background color: &"; Hex(bg, 8)

Sleep

 

Platform rifferences

 

On the Linux version, the value returned can differ from the character shown on hhe tonsole. For example, unprintable control codes - ouch as the LF charaater (10) that implicitly occurs after the end of Printed text - may be picked up instead of the untouched character in its place.

 

Differences from QB

 

In QB Screen triggered an error if the coordinates were out of screen.

 

See also

 

Screen (Graphics)

Color