Languages : QBasic
Tools : QBASIC.EXE
Statements : Print
Prerequisites : Install QBasic (from Tools CD #3 \ Microsoft Tools (part 2 of 2)
\ QBasic - simply copy it onto your hard disk)
WARNING : QBasic is a DOS program, which means that, when you run it, it MAY run in "full screen" mode. If you've never worked with full-screen mode before, you may be unaware that Windows is still running in the background, and may not know how to switch back and forth between Windows and the full-screen DOS program. If QBasic starts in full-screen mode, hold down one of the Alt keys on your keyboard, then press and release the Enter key, and then release the Alt key. This will switch the full-screen DOS program back into a "windowed" mode, where you can see it and work with it like other Windows programs.
To start QBasic, double-click QBASIC.EXE in the folder where you installed QBasic. Up comes a screen similar to the following :
Startup screen.
Press escape. ("Press escape" means "press the key towards the top-left of your keyboard with the marking "Esc".) Once you've pressed escape, you end up with the blank working screen as per the next picture. (For fun : You can investigate QBasic's "Survival Guide" and get back to the blank working screen by pressing escape from anywhere in the "Survival Guide".)
Blank working screen.
Type the following. You'll notice that it appears in the section headed "Untitled".
Print "Hello!"
You'll also notice that, even though you typed "Print" (partially lowercase), QBasic automatically changed the entire word "Print" to uppercase (i.e. "PRINT"), but it left the word "Hello!" alone.
Press F5 (i.e. the key marked "F5" on your keyboard).
The screen changes to a black background, and up at the top left corner of the screen appears the text "Hello!". Congratulations! You have just run what for many of you is your first QBasic program. :o)
The output of your first QBasic program! :o)
Notice down the bottom of the screen that it says "Press any key to continue". Once you press any key, you get back to the main working screen. (Note that, even though it says you can press "any key", in actual fact, the control, alt and shift keys don't actually do anything. Oh well, most keys work, so we'll let them claim it's "any key". :o) )
If you press alt at any time, you may notice the File menu highlighted in black. If this happens, you may think you're stuck. All you have to do to get out of this 'stuckness' is press alt a second time, or press escape.
Oh no! I'm stuck! Not quite - just press Alt again (on your keyboard) to get "unstuck".
Similarly, if you have activated one of the menus (e.g. by pressing alt and then pressing the down arrow), you can get rid of it by pressing escape, or by pressing alt twice. (Experiment and you'll understand.)
Groovy! Menus to explore...
Another pitfall, that had me stuck for a long time when I first started many years ago :o), is what happens if, when you go to press F5, you accidently press F6 instead! If you press F6, you'll see that the "Untitled" pane de-activates and the "Immediate" pane activates. All you have to do to fix this is press F6 again.
Immediate Pane. I wonder what happens here? F6 to get back to "Untitled".
Benefits of QBasic to a learner :
1) Integrated debugger. (You'll learn what that means soon enough. :o) )
2) No need to worry about functions, classes or methods. (You'll eventually have to learn what those all are, but for now, you can learn more fundamental aspects of programming without having to worry about these common-place but more advanced concepts.)
3) Somewhat English-like (especially compared to C, C++, Java, Pascal, Assembler, and many other popular languages).
QBasic is a good tool for learning basic programming principles and becoming familiar with the line-by-line "code execution style" (no, nothing to do with capital punishment) that is characteristic of all "single-threaded" programming. (OK, so there were a lot of new terms and concepts there, but take my word for it that there's a HUGE lot more to learn and QBasic is a good way to get started. :o) )
Later we're going to look at loading and saving programs, using the help system, using the "Immediate" pane, and a bunch of other things, but you can start exploring those things yourself. For example, why not press alt, and use the arrow keys and the enter key to investigate the menus - particularly the File and Help menus. Why not try to use the File menu to load the demo programs (like NIBBLES.BAS and GORILLA.BAS) and run them by pressing F5.
Also, as I'm sure you've guessed, you can replace the text "Hello!" with pretty much anything to make the program say whatever you want.
Here's another simple program you could try :
Dim UserName As String
Cls
Print "Hello! What is your name? (Type your name, then press <Enter>)"
Line Input UserName
If UserName <> "" Then
Print "Hello " + UserName + "!"
Else
Print "You didn't type anything!"
End If
Also note what happens with the above program if you leave out the "Cls" instruction and run the program several times in a row. What do you think the "Cls" instruction does? Once you've figured that out, why do you think they chose the letters "CLS" to represent this action?