-
October 14th, 2003, 01:14 AM
#1
An attempted Qbasic Tutorial Part II
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….
\"Look, Doc, I spent last Tuesday watching fibers on my carpet. And the whole time I was watching my carpet, I was worrying that I, I might vomit. And the whole time, I was thinking, \"I\'m a grown man. I should know what goes on my head.\" And the more I thought about it... the more I realized that I should just blow my brains out and end it all. But then I thought, well, if I thought more about blowing my brains out... I start worrying about what that was going to do to my goddamn carpet. Okay, so, ah-he, that was a GOOD day, Doc. And, and I just want you to give me some pills and let me get on with my life. \" -Roy Waller
-
October 23rd, 2003, 07:53 PM
#2
Thanks I didn't know the LEN, UCASE, and LCASE commands. Nice work indeed.
You shall no longer take things at second or third hand,
nor look through the eyes of the dead...You shall listen to all
sides and filter them for your self.
-Walt Whitman-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|