Qbasic Color statement

Qbasic Color statement

Qbasic Color statement is used to change the Foreground and the background color of the Text in the QBasic Program. The Syntax of COLOR statement is:

 COLOR foreground, background

The word foreground means the color of the text and background color means the background color behind the text.

You can use the COLOR statement in Qbasic in the following ways:

1) To modify both foreground and background color:

SYNTAX: 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

2) To change the foreground color only:

SYNTAX: COLOR [foreground]

Examples:

PROGRAM CODE

COLOR 2

PRINT “This is the green text”

3) To change only the background-color

SYNTAX: COLOR , [background]

Use a comma after the COLOR command and then your background color code

Examples:

PROGRAM CODE

COLOR, 1
PRINT “this is the blue background”

To change the entire background color of your screen, use CLS (clear screen) command after setting the background color.

Examples:

PROGRAM CODE

COLOR 14, 1
CLS
PRINT “Yellow text with entire screen blue background”

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.

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 are 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 ends with blinking white at 31. The blinking option is not available for the 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 Articles:

Qbasic Control Statements with Examples

Download Qbasic (QB64) Free for Windows 10 and 11

Qbasic Programming Examples and Exercises

Qbasic Looping statements with Examples

Free QBasic Online Compilers – Online Editors

QBASIC Programming – Beginner’s Friendly

Related Posts

Qbasic Looping statements

Qbasic Looping statements with Examples

Qbasic is an easy-to-learn programming language, especially for beginners. It provides a wide range of features and functionalities that can make learning a programming language fun and enjoyable. And one…

Read more
Qbasic Programming Control Statements

Qbasic Control Statements with Examples

If you are new to programming or just a beginner you might find it hard to understand the concept of control statements, especially while working with the QBASIC programming language….

Read more
QBasic Online Compilers – Online Editors – Online IDE

Free QBasic Online Compilers – Online Editors – Online IDE (Complete List)

As a beginner, one can program QBasic Online by using the web-based editors, which provide all the functions that free QBasic software provides. The best thing about using online compilers/ Editors is that one…

Read more