SCREEN (function): Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
m (QBasic capitalisation)
Tag: visualeditor
No edit summary
Line 22: Line 22:


''Example 1:'' Finding the text foreground and background colors in SCREEN 0 only:
''Example 1:'' Finding the text foreground and background colors in SCREEN 0 only:
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 0
{{Cl|SCREEN}} 0
{{Cl|COLOR}} 0, 15
{{Cl|COLOR}} 0, 15
Line 29: Line 29:
{{Cl|PRINT}} "{{Cl|SCREEN}} ="; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1)
{{Cl|PRINT}} "{{Cl|SCREEN}} ="; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1)
{{Cl|PRINT}} "FG color:"; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1) {{Cl|AND (boolean)|AND}} 15 'low nibble
{{Cl|PRINT}} "FG color:"; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1) {{Cl|AND (boolean)|AND}} 15 'low nibble
{{Cl|PRINT}} "BG color:"; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1) \ 16 'high nibble '' ''
{{Cl|PRINT}} "BG color:"; {{Cl|SCREEN (function)|SCREEN}}(1, 1, 1) \ 16 'high nibble
{{CodeEnd}}
{{CodeEnd}}
{{TextStart}}'''SCREEN = 112'''
{{TextStart}}'''SCREEN = 112'''
Line 39: Line 39:


''Example 2:'' Reading the [[ASCII]] code and color of a text character using the SCREEN function. Graphic colors were not reliable in QBasic!
''Example 2:'' Reading the [[ASCII]] code and color of a text character using the SCREEN function. Graphic colors were not reliable in QBasic!
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN (statement)|SCREEN}} 12
{{Cl|SCREEN (statement)|SCREEN}} 12
row = 10: column = 10
row = 10: column = 10
Line 47: Line 47:
attrib% = {{Cl|SCREEN (function)|SCREEN}}(row, column, 1)  ' character color return parameter 1
attrib% = {{Cl|SCREEN (function)|SCREEN}}(row, column, 1)  ' character color return parameter 1
{{Cl|COLOR}} 14: {{Cl|LOCATE}} 15, 10: {{Cl|PRINT}} "ASCII:"; code%, "COLOR:"; attrib%
{{Cl|COLOR}} 14: {{Cl|LOCATE}} 15, 10: {{Cl|PRINT}} "ASCII:"; code%, "COLOR:"; attrib%
{{Cl|END}} '' ''
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}
{{OutputStart}}
Line 60: Line 60:


''Example 3:'' Finding the current program path placed on the screen using [[FILES]] and the SCREEN function in SCREEN 0.
''Example 3:'' Finding the current program path placed on the screen using [[FILES]] and the SCREEN function in SCREEN 0.
{{CodeStart}} '' ''
{{CodeStart}}
{{Cl|SCREEN}} 0, 0, 0, 0
{{Cl|SCREEN}} 0, 0, 0, 0
{{Cl|CLS}}
{{Cl|CLS}}
Line 76: Line 76:
{{Cl|SCREEN (statement)|SCREEN}} 0, 0, 0, 0
{{Cl|SCREEN (statement)|SCREEN}} 0, 0, 0, 0
{{Cl|LOCATE}} 3, 1: {{Cl|PRINT}} "The current directory is: "; a$
{{Cl|LOCATE}} 3, 1: {{Cl|PRINT}} "The current directory is: "; a$
{{Cl|END}} '' ''
{{Cl|END}}
{{CodeEnd}}
{{CodeEnd}}
{{small|Code by Pete from the N54 QB site}}
{{small|Code by Pete from the N54 QB site}}
Line 82: Line 82:




''See also:''  
''See also:''
* [[PRINT]], [[SCREEN]]
* [[PRINT]], [[SCREEN]]
* [[COLOR]], [[CHR$]], [[POINT]]
* [[COLOR]], [[CHR$]], [[POINT]]

Revision as of 02:36, 23 January 2023

The SCREEN function returns the ASCII code of a text character or the color attribute at a set text location on the screen.


Syntax

codeorcolor% = SCREEN (row%, column% [, colorflag%])


Template:Parameters

  • row and column are the INTEGER text coordinates of the SCREEN mode used.
  • Optional colorflag INTEGER value can be omitted or 0 for ASCII code values or 1 for color attributes.


Usage:

  • The code value returned is the ASCII code from 0 to 255. Returns 32(space) when no character is found at a coordinate.
  • If the colorflag value is omitted or it is 0, the function returns the ASCII code of the text character at the position designated.
  • When the flag value is greater than 0 in SCREEN 0, the function returns the foreground and background color attribute of text position.
* The foreground color(0 to 15) is the returned SCREEN color value AND 15: FG = SCREEN(1, 1, 1) AND 15
* The background color(0 to 7) is the returned SCREEN color value \ 16: BG = SCREEN(1, 1, 1) \ 16
  • QB64 can return color values in screen modes other than SCREEN 0. QBasic returned the wrong color values in graphic screen modes!


Example 1: Finding the text foreground and background colors in SCREEN 0 only:

SCREEN 0
COLOR 0, 15
CLS

PRINT "SCREEN ="; SCREEN(1, 1, 1)
PRINT "FG color:"; SCREEN(1, 1, 1) AND 15 'low nibble
PRINT "BG color:"; SCREEN(1, 1, 1) \ 16 'high nibble
SCREEN = 112
FG color: 0
BG color: 7
Note: How the SCREEN 0 background color can only be changed to colors 0 through 7! 7 * 16 = 112.


Example 2: Reading the ASCII code and color of a text character using the SCREEN function. Graphic colors were not reliable in QBasic!

SCREEN 12
row = 10: column = 10

COLOR 9: LOCATE row, column: PRINT "Hello"
code% = SCREEN(row, column, 0)     ' character code return parameter 0
attrib% = SCREEN(row, column, 1)   ' character color return parameter 1
COLOR 14: LOCATE 15, 10: PRINT "ASCII:"; code%, "COLOR:"; attrib%
END
         Hello



         ASCII: 72     COLOR: 9
Explanation: The SCREEN function returns the ASCII code for "H" and the color 9.


Example 3: Finding the current program path placed on the screen using FILES and the SCREEN function in SCREEN 0.

SCREEN 0, 0, 0, 0
CLS
PRINT "This is a directory test..."
SCREEN 0, 0, 1, 0
COLOR 0 'blank out the screen text
FILES "qb64.exe"        'the current program's filename can also be used
FOR i = 1 TO 80
  a$ = a$ + CHR$(SCREEN(1, i)) 'scan the black text on the screen
NEXT
CLS
COLOR 7
a$ = RTRIM$(a$)
SLEEP
SCREEN 0, 0, 0, 0
LOCATE 3, 1: PRINT "The current directory is: "; a$
END
Code by Pete from the N54 QB site
Explanation: The SCREEN page one is used to hide the FILES display using COLOR 0. The SCREEN function reads the top of the screen page text and creates the current path string. It is then printed on the visual page.


See also:



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link