PART TWO: COMMENTING YOUR CODE, DOING CALUCLATIONS, MORE STUFF

Now, you have been making a couple simple programs on your own, right? Well, now, I’ll teach you how to comment your code. In Qbasic, there are two ways to do this. One is the apostrophe (‘) . The other is the REM command. The apostrophe is more versatile, because it can go on the same line as the code you are commenting, while the REM command has to go on it’s own separate line. The uses are like this:

CLS
‘This program started on 10/13/03
‘ written by slick8790
‘ This program displays a simple greeting
REM This is the other way to comment your code
PRINT “Hello, World” ‘pretty simple
END

However, the computer sees these instructions:

CLS
PRINT “Hello, World”
END

Use this if you want to document features, let yourself know about bugs, or just say anything.

Now, if you want to do calculations, it’s pretty simple. Simply do the calculation by having (w/o the quotation marks) “finalcalculation = 5 * 5” . Then print your data by doing PRINT “Your answer is “ ; finalcalculation ; “.” Pretty straightforward, right?
Like this:

CLS
PRINT “Wanna know what 5 times 5 equals?”
finalcalculation = 5 * 5
PRINT “Your answer is “; finalcalculation ; “.”
END

Now, I’m assuming that you know the mathematical operators on a PC, right? + (plus), - (subtract), * (multiply), / (divide), and ^ (exponent). You can make any calculation you want, or even put a variable in as follow:

CLS
INPUT “Which number do you want multiplied by 5?” ; number
final = number * 5
PRINT “The answer is “; final; “.”
END
So you typed it in and got your answers, right? (You are typing these in, aren’t you?)

Now, lets play around with strings for a little bit. To make a string all lowercase use the command LCASE$(“STRING THAT YOU WANNA MAKE LOWERCASE”). Also, the uppercase command is UCASE$(“string you wanna make uppercase”) They are used like:

CLS
PRINT UCASE$(“ I like to make things capitalized “)
PRINT LCASE$(“ LOWERCASE IS GOOD TOO”)
END

Note: The letters don’t have to be in the opposite case, I just did that to illustrate the functions of that command

Also, there are commands for counting the amount of characters in a string. That is the LEN command. Syntax is ‘ LEN(Greetings from New Jersey!”) ‘ Used as:

CLS
PRINT “Type a string.”
INPUT yours$
Totallength = LEN(yours$)
PRINT “There are” ; totallength; “characters in your string”
END

Well, I’m done for this one…more coming….