These lessons are ment for beginners of QBasic. I only assume that you know and are studied QBasic editor enough to know where Save File, Run, Help and so on are. It means that you are already once or twice opened then QBasic editor and probably wondered what a heck this is? =) QBasic editor is pretty simple, dark and there's nothing so special. No nice 3D effect's etc. Well, it's like kind of dark Notepad almost. You have probably writed there something and notice'd that when you press A button, then A appears on screen =)
This is the point where we start. QBasic and programming what ever language is typing codes after codes. In QBasic there are lot's of commands. If you are checked Help section on QBasic you have noticed that. Don't worry, in this lesson we are going to learn three commands and how you can comment your code. When you are finish with this lesson, you probably gona think gee, that wasn't so hard after all. Ok, so the idea of codes after codes is that QBasic read's them and then does that stuff you wanted it to do.
Firs't I need to be sure that you know where is Run. If you are not sure, take a minute and locate it. Finded it? Ok, here we go. Classic first program has usually been so called Hello World. We are going to make it. Yeah, we are going to make it right now =)
PRINT "Hello World" END
Type it on your QBasic editor. Use that Run you located some minutes ago. Get back here? =) So there was your first program with QBasic ever? I bet that now you have at least idea of what that PRINT command makes. Im also pretty sure that you know what PRINT and those two " marks makes together.
PRINT is for printing on screen and what ever read's between those two " marks are what QBasic prints. So if you try this.
PRINT "Hello for the whole world" END
Try it, just to make sure =) Back here? Ok. Screen might look weird because of that Hello World text what we use on earlier code is also there and Hello for the whole world is right under it? But because PRINT's idea is pretty easy I think we should expand this program a bit. Just one simple command there.
CLS PRINT "Hello World" END
Well, what's happened? Screen is empty expect that Hello World is there, and all alone. No earlier typed text's. CLS stand for Clear Screen. It wipes out everything from screen. Let's do a test.
PRINT "Hello World" CLS END
If you test that code you noticed that screen stays black and you cant see that Hello World text anywhere. You didn't suppose to =) QBasic prints that Hello World on screen but CLS command right after it clears screen. And it does it fast. If we were a super mans we might have a change to see that Hello World before CLS does it's job. =) Ok, two command's done, one to go. Oh, and that how you comment your code.
Hey, nothing happened? Hehe, it wasn't suppose to happen anything. =) END stands for End of code. When END comes, QBasic finishes program and quit's on QBasic editor or on OS. From where ever you started your program. Now, let's give that Hello World program a bit complex out look.
CLS ' Clear's the screen. PRINT "Hello World" ' Print's wanted text on screen. END ' End's program
This code does exactly the same than the upper one. Only difference is that now you have commented your code. QBasic doesn't care what comes after ' so you can write there what ever you want. Commenting this code probably feels useless. Well, it is. That code don't need commenting because it's so simple and short. But I recommend that you start commenting your codes this way. You learn commenting easily by doing it this way. After learning more QBasic, you probably drop out of commenting some certain code's but that's ok. But at beginning I recommend that you comment every line. Well, it's my opinion. =) You can use : REM too for commenting.
CLS : REM Clear's the screen PRINT "Hello World" :REM Print's wanted text on screen. END :REM End's program.
Yup, and nothing difference of that upper code. Why use ' instead of :REM? Well, it's shorter and looks lot's of nicer =) Well, there is certain things that works with ' but im not gona go there now. This was first lesson. You learned how to make Hello World program. You might think that it ain't mutch. Lot's of coders has started with that program. It's a classic and good start.
Before we move on Lesson 2 you could test what happens if you make more PRINT lines on that program and get known with PRINT command. On lesson 2 we are going to make Hello, your name here' program and some other interesting stuff.
E.K.Virtanen, public domain