=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= QBasic Basics =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= By: Michael Cooney stalfos45@hotmail.com last update: 10/5/99 Contents --------- Why learn QBasic? Hello World Variables Getting Input Conclusion ===================================================================== Why learn QBasic? ===================================================================== Obviously you already know the answer to this question, or you wouldn't be reading this. But just for fun, I'll give you my explaination. QBasic is a very easy language in comparison to some of the more popular ones (C, C++). Since its syntax is closer to english than most languages, it is reffered to as a Low Level lenguage, while something like C++ is Higher Level. QBasic is perfect for people who are just starting to learn programing. Hence the name; which stands for Begginers All-purpose Symbolic Instruction Code. After mastering QBasic it will make it much easier to learn a higher level language, where you may be able to get a job. I hope this has provided you with some insight and encouragement to start learning. ===================================================================== Hello World ===================================================================== If you've ever tried learning a programing language before, you've probobly come across an example like this. Where the line "Hello World" is simply printed out to the screen. It's obviously a good place to start if it's used so often. So here we go. Type this into qbasic and hit f5: CLS PRINT "Hello World" END Woah, fhew.. that was hard, eh? Well, not really. CLS stands for clear screen, you can guess what the rest does. Try omitting the CLS just to see what happens. It will show the DOS prompt and whatever you've been doing in DOS. That's all for this example. That was an easy one. Next we will experiment with variables. ===================================================================== Variables ===================================================================== Variables are a very imprortant part to programing. They allow you to store a string (text), or an integer in the computers memory to call on later. Here's an example: CLS name$ = "Mike" PRINT name$ END The second line creates a variable called name then assings it the value Mike. The $ means that this variable is a string. The third line simply prints the value of the variable name$ to the screen. Ok, if $ means string, then what symbol is used for integer? Well there are acctually two different types of integers. The first can either use a % in place of the $, or you can use nothing at all. This type of integer has a range of -32767 to 32767. The symbol for the second type of integer is &. This is a Long Integer and it has a range of -2 billion to 2 billion. Try out this program: CLS value1 = 2 value2 = 2 answer = value1 + value2 PRINT answer END Neat, huh? ===================================================================== Getting Input ===================================================================== You can't make a useful program without getting some sort of input from the user. First I'll give the code and then an explaination. CLS INPUT "What is your name"; yourname$ PRINT "Hello " yourname$ ". How are you?" END I bet you can figure this one out too. INPUT tells the computer to get ready for input, the ; ends the text printed asking the user for input, yourname is the name of the variable the input is stored in and the $ tells the computer what type of input to expect (as discussed in the previous section). Notice that when you asked "What is your name" there was no question mark. QBasic automatically adds it when the program is run. Also notice that on the third line when you want to print the variable you have to end the quotation marks and begin them again when you want to print something following the variable. ===================================================================== Conclusion ===================================================================== Hopefully, now you know the basics of QBasic and you can write a decent program, but things will start cooking up in the next tutorial when I'll teach you about using files to store and retrieve data. I encourage you to practice using the things you learned here and always experiment. You'll never learn if you don't. Until next time, Michael Cooney