Qbasic Color statement is used to change the Foreground and the background color of the Text in the QBasic Program.
Page Contents
Qbasic COLOR statement syntax
the syntax of the COLOR statement is:
COLOR [foreground],[background]
The word foreground color means color of the text and background color means color that appears behind the text i.e background.
You can use the QbasicCOLOR statement in Qbasic in the following ways:
1) To modify both foreground and background color:
COLOR [foreground color] , [background color]
Use a comma to separate the foreground and the background color.
Examples:
PROGRAM CODE
COLOR 14,1
PRINT "yellow text with blue background"
OUTPUT
yellow text with blue background
2) To change the foreground color only:
COLOR [foreground]
Examples:
PROGRAM CODE
COLOR 2
PRINT “This is green text”
OUTPUT:
This is green text
3) To change only the background-color
COLOR , [background]
Use a comma after COLOR command and then your background color code
Examples:
PROGRAM CODE:
COLOR , 1
PRINT “this is blue background”
OUTPUT:
this is blue background
If you want to change the entire background color of the screen, use CLS command after setting the background color.
Examples:
PROGRAM CODE:
COLOR 14,1
CLS
PRINT "Yellow text with entire background in blue"
OUTPUT:
yellow text with entire background in blue
The foreground and the background color are represented by numbers in Qbasic. You can use the Qbasic color codes to change the color according to your preferences:
Qbasic Color code table
Number | Color | Number | Color |
0 | Black | 8 | Grey |
1 | Blue | 9 | Light Blue |
2 | Green | 10 | Light Green |
3 | Cyan | 11 | Light Cyan |
4 | Red | 12 | Light Red |
5 | Magenta | 13 | Purple |
6 | Brown | 14 | Yellow |
7 | White | 15 | Light White |
There are 16 colors (in screen mode 0), numbered from 0 to 15. Use the Qbasic COLOR Statement and the number that the color represents to use it in your code.
You can see from the color code table that there are 8 main colors(from 0 to 7), and the color from 8 to 15 is just the repetitions of color from 1 to 7 but in a lighter shade. The colors are a combination of binary values (blue = 1, green = 2, red = 4), which makes it easier to memorize the color codes.
If you want blinking color, it is available from color code 16 to 31. At 16, the color starts again with blicking black color and end with blinking white at 31. The blinking option is not available for background, it only works for the foreground color(text color). Here the example how to get the blinking color code = 2 (green color code ) + 16 = 18( blinking green color), 4(red color code) + 16 = 20 (blinking red color).
Related topics on Qbasic Statements and Commands:
QBasic Commands and Statements-2020
FAQ related to COLOR statement in QBasic
How to change screen color in Qbasic?
To change the screen color i.e background color in Qbasic, use the COLOR statement. Syntax is :
COLOR , [background]
Example:
COLOR , 1 (use a comma before the background color code)
PRINT “this is blue background”
How to change text color in Qbasic
To change text color in Qbasic use the COLOR statement. Syntax is: COLOR [foreground].
Example:
COLOR 2
PRINT “This is green text”