Qbasic Color statement is used to change the Foreground and the background color of the Text in the QBasic Program.
Qbasic COLOR statement syntax
the syntax of the COLOR statement is:
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.
COLOR 14,1 PRINT "yellow text with blue background"
yellow text with blue background
2) To change the foreground color only:
COLOR 2 PRINT “This is green text”
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
COLOR , 1 PRINT “this is blue background”
this is blue background
If you want to change the entire background color of the screen, use CLS command after setting the background color.
COLOR 14,1 CLS PRINT "Yellow text with entire background in blue"
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
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:
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]
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].
PRINT “This is green text”