Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What are the Qbasic text colors?

What are the Qbasic text colors?

What are the Qbasic text colors?

This is an admittinly pitiful question from a new Qbasic programmer (I must be  the only NEW Qbasic programmer on earth). I need to know: What are the translations from basic colors to the numeral equivalants in Qbasic. Also, could you please tell me
how it is that you can make text blink by "adding 16 to the foreground color"? thank you very much for your time.  

RE: What are the Qbasic text colors?

This should be in the help file, also dont feel bad about being a new "QBasic" programmer, I get alot of newbies started on Qbasic almost every month, simply because some people who are too new to computers cant handle Visual Basic, (also cuz it's expensive, and not as fun to start immediatly on)

Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)

RE: What are the Qbasic text colors?

What you want to do is best seen in screen mode 0 (zero)--it's aka TEXT MODE--since you're new and cause QB defaults to it.


start QB.
type COLOR in the coding window.
move the cursor so that it is inside the word you just typed.
then press F1

Now, the numbers you see (1 to 15) are the standard palette that QB uses.  These numbers can be either the foreground or the background--and in TEXT mode they could also be the boarder color.

So whatever color you choose to the foreground color add 16 to it.  If you don't quite understand, read your QB help files again and play around with it.

English is too hard to learn, the vowles change too much like come/home, comb/tomb, book/school, high/bye/sty, etc., etc.  So should I say Geez or Sheez or Cheeze? hehe.

RE: What are the Qbasic text colors?

Time for a Quick Reference Chart...
   *** NOTE B-color means the color is blinking, ***
   *** L-Color means light color, and B-L-color  ***
   *** means Blinking - Light Color              ***

 0 - black        1 - blue          2 - green      
 3 - cyan         4 - red           5 - magenta    
 6 - brown        7 - white         8 - grey      
 9 - L-Blue      10 - L-green      11 - L-cyan
12 - L-red       13 - L-Magenta    14 - Yellow    
15 - Brt. White  16 - B-black      17 - B-blue    
18 - B-green     19 - B-cyan       20 - B-red    
21 - B-magenta   22 - B-brown      23 - B-white
24 - B-grey      25 - B-L-Blue     26 - B-L-green
27 - B-L-cyan    28 - B-L-red      29 - B-L-Magenta
30 - B-Yellow    31 - B-Brt.White

-PHREADD- >:^>

RE: What are the Qbasic text colors?

To learn quickly the number that refers to the colors, simply type this program in:

count = 1
y = 1
FOR x = 1 to 30
count = count + 1
LOCATE count, y: PRINT "Color"x"is this color!"
if count > 23 THEN count = 1: y = 30

Yeah, it's complicated for a newbie...but, it tells you the colors. Simply type in COLOR (1-30) to change text color!

RE: What are the Qbasic text colors?

This one is more typing but it also reminds you that 0 and 16 are black and won't show in screen 0.

FOR Colur = 1 TO 15
    LOCATE Colur, 1
    COLOR Colur
    PRINT "#"; STR$(Colur); " is this color/style."
RowCount = 1
FOR Colur = 17 TO 31
    LOCATE RowCount, 43
    COLOR Colur
    PRINT "#"; STR$(Colur); " is this color/style."
    RowCount = RowCount + 1

COLOR 15  'See this line? I told qb to use #15{brite-white) for any text it will display on screen after this point on--or until I change COLOR # to something else

PRINT : PRINT : PRINT "NOTE: Color #0 and #16 are black."

RE: What are the Qbasic text colors?

Before continuing, it is important to remember that computers operate inherently with numbers made up with bits -- that is, a number's digits inside the computer are 0's and 1's. This means that if you add 1 to 1, you get 10, and 1 to 11, you get 100. Instead of carrying when you go over 9, you carry when you go over 1.

Now, back in the (good?) old days of CGA graphics, there weren't a great many different screen modes to pick from. The basic video card had a whole 16 kilobytes of memory on it -- video cards with more allowed for this beautiful animation technique that involved telling the video card to start its next retrace from a different place in video memory. The video card allowed basically for just two pixel modes: 320x200 and 640x200. In text mode, you could pick from 40x25 and 80x25, and each character was made up of 8x8 dots (40x25 * 8x8 = 320x200, and similarly 80x25 * 8x8 = 640x200). In video modes, every pixel would be represented by a certain (small!) number of bits -- in 320x200, 2 bits per pixel, and in 640x200, only 1 bit per pixel (i.e., monochrome).

The video card, internally, had access to one brightness of each of the 3 additive primaries -- i.e., pure red, pure green, and pure blue. When representing a colour, you could for each colour either have it on or off. Additionally, you could halve the brightness with a 4th bit, which they thoughtfully inverted so that the first half, and not the second half, of colours would be halved.

  1  0  1  1
  |  |  |  `- blue channel
  |  |  `---- green channel
  |  `------- red channel
  `---------- brightness channel

The colour represented in the diagram above is bright cyan. In text mode, which, though extended by the EGA palette, is still essentially the way it was with the CGA card, every character has a whole byte of colour information -- that's 8 bits. Since a colour only needs 4 bits to represent, that allows us to give every character a foreground and a background colour. Later video cards changed the brightness channel of the background colour to be a blink channel for that character, which, if enabled, caused that character to turn on and off roughly every 1/4 second, but originally, it was simply brightness. All was bliss -- like at Christmas. But wait, though -- the graphics modes. How do you represent a 4-bit colour using only 2 -- or even 1 -- bit? Well, the short answer is that you can't, and you don't get as many colours. In 320x200 -- SCREEN 1 -- which takes 2 bits per pixel, the video card allows you to specify a value for the blue channel, and this, along with a brightness channel that is 'always on', is mixed in with the red & green channels that are specified for each pixel. This allows us to pick between two sets of colours: either every pixel can be one of black, green, red or yellow (you've seen games like this), or every pixel can be one of blue, cyan, magenta or white (you've seen games like this too). The video card is perhaps a bit more allowing with SCREEN 2, in that you can specify two distinct colours for the background and for the foreground, and then each pixel picks either one or the other by being either on or off.

How does all this tie in with QB? Well, first of all, the text mode colours can all be derived using this table:

 Red  Green  Blue   Value (binary),(decimal)  Colour
  0     0      0            000       0       Black
  0     0      1            001       1       Blue
  0     1      0            010       2       Green
  0     1      1            011       3       Cyan
  1     0      0            100       4       Red
  1     0      1            101       5       Magenta
  1     1      0            110       6       Yellow/Brown
  1     1      1            111       7       White/Grey

As you can see, you get cyan by mixing blue and green, magenta by mixing blue and red, and yellow by mixing red and green. This set of colours is duplicated for the second half of the palette, except that the brightness bit is turned on. QuickBASIC's colour command allows you to select all 16 possible foreground colours, but only allows you to specify a number between 0 and 7 for the background colour. This is because with later video cards, that setting that makes the background's brightness bit into a blink bit is on by default. It is possible to turn it off using direct hardware access with OUT, but QuickBASIC doesn't care either way, and only allows you to specify the 3 colour bits of the background colour. However, it adds a 5th bit to the foreground colour, and if you add 16 to your colour (which turns this 5th bit on), then the COLOR statement will turn on the brightness bit of the background colour. Under normal operation, this means simply that the text will blink. It is possible to find code snippets that allow for bright backgrounds, too. By the way, text viewed in a windowed (not full-screen) DOS box in Windows 95 always treats the background's brightness bit as a brightness bit, and not as a blink bit.

As for the two graphics modes, you can select the colours for them using the COLOR command. How it all works is documented in the help file, but I'll just quickly link it in with what I've said. For CGA graphics modes, the COLOR command's two parameters have different meanings than they do for text mode. While in text mode, you specify a foreground colour and a background colour, in SCREEN 1, you specify a background colour and a "palette." The background colour is what QuickBASIC will treat graphics drawn in colour 0 as, and the palette is the blue channel's value. With it set to 0, you get the red/green/yellow palette, and with 1, you get the magenta/white/cyan palette. Unfortunately, QuickBASIC does not provide any access to the "colourization" of SCREEN 1 for CGA adaptors, but under EGA and VGA adaptors, you can change the colours using the PALETTE statement. In fact, the EGA adaptor uses an array of 64 colours that the 16 colours in text mode, 4 in SCREEN 1 and 2 in SCREEN 2 can each be separately mapped to. This is a topic for a later discussion, though.

Enjoy the CGA palette given to you in SCREEN 0, and for the reference, here is a colour table for QB colours:

Colour 00: Black
Colour 01: Blue
Colour 02: Green
Colour 03: Cyan (Blue + Green)
Colour 04: Red
Colour 05: Magenta (Blue + Red)
Colour 06: Dark Yellow (Brown)
Colour 07: Gray (Dark White)
Colour 08: Dark Gray (Bright Black)
Colour 09: Bright Blue
Colour 10: Bright Green
Colour 11: Bright Cyan
Colour 12: Bright Red
Colour 13: Bright Magenta (Pink)
Colour 14: Yellow (Green + Red)
Colour 15: White (Blue + Green + Red)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close