Sunday, 2017-04-30, 3:22 AM

Welcome Guest | RSS

Qbasic Home

Catalog categories
Qbasic Tutorial [31]

Rate my Site
Rate JPSor Site
Total of answers: 156

Main » Articles » Qbasic Tutorial

Chapter 24 - Qbasic Tutorial

Most programming languages allow you to add notes to your programs that are ignored by the computer. This lets you explain what you've done to someone else who might read your program later. In QBASIC we use the apostrophe (') to begin a comment. Here's an example:

 ' A program to draw boxes all over the screen
' This is a comment, QBASIC will ignore it
' Draw 50 boxes
FOR I = 1 TO 50
' Pick the location of the box
X1 = INT(RND * 640)
Y1 = INT(RND * 480)
X2 = INT(RND * 640)
Y2 = INT(RND * 480)
' Pick the color for the box
Color1 = INT(RND * 16)
' Draw the box
LINE (X1, Y1) - (X2, Y2), Color1, BF

The computer will ignore all those comment lines, but us humans can read them and remember how a program works. Good programmers use comments to help others understand what they have done. Comments can also help us remember what we did when we come back to a program after working on something else for a while.


Another way to make your programs easier to understand is to use constants. Constants look and act like variables, but they cannot be changed. Here's a useful program:

 CONST Pi = 3.141593
INPUT "Enter the radius of a circle: ", Radius
PRINT "The circumference is:"; 2 * Pi * Radius
PRINT "The area is:"; Pi * Radius * Radius

If we didn't use the constant Pi, we would have to copy the number 3.141593 two places in the above program. Using a constant makes the program easier to read and understand. It also keeps us from making mistakes when copying.

Category: Qbasic Tutorial | Added by: JPSor (2009-02-26) | Author: JPSor
Views: 759 | Rating: 0.0/0 |

Qbasic Clock


Visit my Friends

Who's Online

Total online: 1
Guests: 1
Resgistered: 0

Copyright MyCorp © 2017