--- Qbasic ---
When I learned mathematics at school, I have to use "Tables", and learn how to do multiplication etc. with logarithm. Now, even students in primary school have computers.
About 25 years ago, an IBM 370 computer cost about 7 million Hong Kong dollars. Its main memory was only 256K bytes. Later mini-computers appeared. But still the price was formidable : 256K bytes memory, 8 inches floppy, 20 Mbytes hard disk .. cost roughly half a million H.K.dollar. At that time, hard disk of 5 ~ 10 Mbytes has a diameter of more than a feet, and weighed several pounds!
Now we can buy a PC with 64 Megabytes RAM, 15 Gigabytes hard disk, 15 inch monitor, floppy, CDROM, printer, scanner for less than H.K.$ 10000! (Hence it is good news for manufacturers who would like to computerize their operations!)
Many people shy away from programming, thinking it to be difficult. And manufacturers would mostly hire others to do the programming for them. Is it really that difficult to learn programming?
Several years ago, a Form 3 student visited me. At that time, that was a Wang Computer in my work place. That Wang computer can run BASIC, and was equipped with a cassette drive and printer. I thought it good for him to learn a little about computer. So I said to him, "Computer is really dumb, it understands very few words ! " Then I proceeded to teach him to write simple program, using "input, simple assignment statement, print, goto ", and showed him how to use "lprint .. " to print onto the printer. I only taught him for about half an hour. But he was hooked! He felt fascinated and came to my office repeatedly to write programs, he also read manual by his own . Later, he bought an Apple II computer, and even learned 6502 assembler programming! The time I spent with him was only about half an hour, and he can learn programming in that short time!
If you are willing, you can learn programming in a very short time too. (The lessons I prepared for Qbasic consist of only 12 chapters). Qbasic (a very popular programming language) comes free with DOS. Moreover, the PC you buy now is much more powerful than the 7 million IBM 370 25 years ago. (If you plan computerization many years ago but was hindered by lack of money, you wouldn't have such problems now.)
Microsoft did a very good job in improving Qbasic, and you can program practically anything, whether it be data-processing, or scientific number crunching, with it. (except for speed, the Qbasic Microsoft gives us free is an interpreter, though Microsoft has a Qbasic compiler). It is much user-friendly than many computer languages, e.g. COBOL, FORTRAN, PASCAL, C ....
After learning Qbasic, which should suffice 95% of your computer needs, if you are still interested, you may buy LINUX, a UNIX clone, for about US$ 50 ~ 60. (I bought a computer book from Taiwan, which included a Linux CDROM, for about HK$120.) LINUX comes with FORTRAN, PASCAL, C, BASIC (the original version of BASIC, not Microsoft's Qbasic), Bison (a compiler that can write other compilers) ,.... You would wonder why it is so cheap. It is because of the Finnish student Linus Torvald, he wrote the kernel of this operating system as a project under his teacher, and he put it on the Internet, free for everybody to download. Moreover, "Free Software Foundation" supply the operating system with many, many, very good quality software, free.
I wish to teach Qbasic in these 12 lessons. After learning Qbasic, you should be able to handle 95% of your programming needs, whether it be for data processing or engineering calculations. Qbasic should give you a good understanding of what a computer does, and after that, if you so desire, you may learn FORTRAN, C, ... (but these languages are really not necessary unless you want to enter this profession). Qbasic also gives you a good start in mastering Microsoft's Word, Excel, Powerpoint, ... or other companys' softwares, because you know programming, and you can learn such softwares much faster than one who doesn't know programming.
Programming also enables you to understand many aspects of the present Information Technology and will prepare you for technologies to come.
Before starting the lesson, it is advisable to get your son, or daughter, or anyone who knows computer to sit beside you.
(Note : my copy of Qbasic was stored on WINDOW 95 CDROM, under the directory D:\other\oldmsdos. There are 4 files in that directory, qbasic.exe, qbasic.hlp, help.com, help.hlp. I copied them onto C: , (you may ask your friend to do that for you if you don't know how to do that). If you have old computers with MSDOS, you can usually find Qbasic.exe, qbasic.hlp, help.com, help.hlp there.)
Although Window 95/98 replaces DOS, but Microsoft still retains a stripped down version of DOS with Window. Hence you have two operating systems in your PC.
To switch from Window to DOS :
Start -> programs -> MS-DOS promptAfter that, you may type in commands for DOS.
exit
Exercise Calculate area of triangle
First switch to DOS operating system,
Start -> programs -> MS-DOS promptthen type the command "Qbasic". Then you will be presented with an Qbasic welcome screen. You may follow that screen to read the on-line manual, or you press "ESC" to skip over that. Now type in (or download program)
L20:
input "Please enter height of triangle "; height
input "Please enter length of base "; length
area = .5 * height * length
print "Area of triangle is = "; area
goto L20
Computer really knows very few words, "input, print, goto" are keywords
that must be spelled correctly (Qbasic will change all keywords from lower case
to Capital letters, input will become INPUT, print will become PRINT, goto
will become GOTO, ..).
Please enter height of triangle ?
Then you type in a number, say 4.7 and press "Enter".
Please enter height of triangle ? 4.7
Please enter length of base ?
You type in another number, say 5.23 "Enter"
Please enter height of triangle ? 4.7
Please enter length of base ? 5.23
Area of triangle is = 12.2905
Please enter height of triangle ?
Now you may enter another set of data. When you want to stop,Press Ctrl + Pause ( = Ctrl + Break )You may now save the program onto a floppy. Put in a new floppy.
Alt -> File > Old -> then type in filename, a:\anynameAnd the program will be loaded back from floppy onto memory.
Exercise Calculate area of circle.
Press "Alt -> File -> New " then the previous program will be erased,
and you may enter the new program.
Ans :
L20:
input "Please enter radius of circle ";r
a= 3.1416 * r * r
print "Area of circle = ";a
goto L20
Exercise Calculate area of trapezoid
Ans :
L20:
input "Please enter length at top "; t
input "Please enter length at bottom "; b
input "Please enter height "; h
ans = (t + b) * h / 2
print "Area of trapezoid = ";ans
goto L20
Note :
variable_name = arithmetic_expressionThis is called "assignment statement", the arithmetic_expression on the right will be evaluated, and the result put into variable_name. Hence you may find statement like
a = a + 1which means "a is to be incremented by 1, and the result put back into a".
k = 3
k= k+ 7
print "The final value of k is = ";k
k will be 3 at first, then k = 3 + 7. Hence the computer output
will be " The final value of k is = 10 "
L20:
input "Please enter number whose square root is needed ";a
b= sqr(a)
print "The square root of ";a;" is = ";b
goto L20
Alt -> File -> ExitThen we escaped from Qbasic, and into DOS.
exitand we will be back to Window.
lprint "Area of triangle is ";area
After printing, press "resume" button on the printer to roll out the paper.
(Note : to control a printer fully, e.g. left margin, right margin, top margin,
no. of lines per paper, no. of lines per inch, font, size, .... You will have
to use "printer control codes" , e.g.
lprint chr$(27);"C";chr$(60) --- set 60 lines per page
lprint chr$(27);"l";chr$(7) --- left margin starts at column 7
lprint chr$(27);"Q";chr$(72) --- right margin ends at column 72
lprint chr$(13) --- leave one blank line
lprint chr$(12) --- eject paper.
The above control codes are for "Epson LQ-2550" printer; but as many printers,
e.g. those by Canon, also support this code, you may use it on other printers too.
These control codes are usually in "programmer's manual" and you will have to buy it
from dealers or manufacturers.
label_name :
which should be on separate line, with a label name, followed by ":".
if ..... then
....
....
elseif ..... then
....
....
elseif ..... then
....
....
else
....
....
end if
" if, then, elseif, else, endif " are all keywords. Coupled with " input, print, goto "
you can already write many useful programs !
| [Home] | [Next] |