Programmer's Toolkit -- tips and techniques for beginning programmers
The Toolkit is a collection of programs and subroutines that make it much easier for beginning programmers to create their own software using Microsoft QBASIC. If you are new to programming, you might want to start with the Really really basic BASIC course before using the Toolkit. This link also shows you how to find and install a free copy of QBASIC on your computer.
Begin by running the program TOOLKIT1.EXE. If you have installed the seminar on your computer you can locate this program file and run it yourself. You can also just click this link Run the Toolkit 1 demonstration program.
After you have run the program, you will want to run the original program code in QBASIC so that you and see how each step was done. You can then copy any of the program code and use it in creating your own programs.
This collection of four programs illustrates the programming tools and gives you an easy method for selecting the colors and color combinations you can use in writing your software.
This is the demo program that you can download and then run from the desktop by clicking on the Toolkit 1 icon. Follow the on-screen suggestions and see how all the ingredients of the toolkit work together to create many standard programming tasks.
This is the QBASIC version of the demo program. When you load this program using QBASIC, all the subs and commands are automatically added to the commands you normally use. You can copy any sub and add it to your own programs, or you can load TOOLKIT1.BAS, delete the demo program code, and write your own program in its place. This method automatically puts all the subs from the toolkit in your program and makes all these additional commands available.
It's easy to write your own programs using all the toolkit features. Just load the program START1.BAS and then save this program with your own program name. This automatically adds all the SUB in the toolkit and allows you to use all these features when you write your software.
You will need a color chart to figure out all the color combinations that are possible. This chart covers MODE 0 and shows how all sixteen colors and all of the eight possible backgrounds will look. As you will see, many of these combinations look awful, but this program lets you pick what works or looks best to you. The number zero (0) and the letter O look very much alike to humans and are seen very differently by a computer. In these examples, both color and mode refer to the number zero, not the letter.
This color chart shows you all eight colors that are available in MODE 12. The background is always black in this screen mode that you will use any time you want to print really small dots on the screen.
When you load TOOLKIT.BAS or START1.BAS, these subroutines and commands are added to the QBASIC programming language.
I use boxes a lot, and this sub makes placing a single-line box on the screen easy and fast. It is much more convenient than the Microsoft LINE command, which you can also use to accomplish the same result.
Clearing a section of the screen is easy with this command that lets you specify top and bottom lines, left and right edges, and a color.
Short delays from 1/10 second to as many seconds as you want can be added anywhere in your program with this command. Just add Delay 5, for example, and the program will pause for five seconds before continuing. This delay is independent of computer speed, so your programs will not vary as they are run on faster or slower machines. Slowing down the computer may not seem like a good idea, but delays are essential in creating games and other interactive programs that feel right.
If you use an external data base, as I do in storing words for the Hangperson game, this command will automatically select a unique item from your disk file. You can modify this sub to load the entire file, or to select a single word or phrase at random.
Nothing is more annoying than having the computer jump ahead unexpectedly when you have pressed the keyboard too many times or typed a key by accident. Simply adding Gobble to your programs before you check the keyboard for any input solves this problem nicely.
There are several ways you can input a word or phrase from the keyboard. I like this method the best, because it automatically shows the correct length of the word or phrase to type in, it handles the Backspace key, it exits with Enter and cancels with Esc or Alt-F4.
Whenever you want to give someone a choice in your program, this menu routine can do the trick easily. Just change the descriptions to match your choices, and Menu does the rest. This sub responds instantly, without having your user press the Enter key after a selection, and it beeps if any wrong key is pressed. It also exits with Esc and Alt-F4.
If the only choices you wish to offer are Yes and No, then this form of Menu is all you need. It recognizes both upper and lower case inputs, just because people can press the Caps Lock key and not know it.
Random numbers are fun and interesting. They can add spice to your software and zip to your games. This command gives you a number that's as random as the computer can manage, and all you have to do is specify the top and bottom numbers in the range you want. You can even specify the bottom and top numbers (backwards) and this clever command figures out what to do.
I've included my favorite robot image in the toolkit because I like it. Actually, it's a likeness of my friend Fenimore Gaak. You may not want to put this image in your programs, but a quick look at the code for writing this sub will show you all you have to know to make any picture you want, and even simple animation, using ASCII characters.
You will never use this command in a program, but you may use this tool often as you create software. If you are trying to center an image, a box, or a section of text on the screen, just type Ruler N and you will get a ruler on the screen at line number N. If you type Ruler 1 you will see the ruler on line one, at the top of the screen. Ruler 15 places a ruler at line 15, near the center of the screen. Use the Immediate mode at the bottom of the QBASIC screen to do this.
Putting a running timer anywhere on the screen is easy with this command. You can run, stop, set, and reset the clock whenever you want.
I've collected four tunes that I use a lot for announcing things, celebrating victories, and letting people know when they have messed up. I don't know whether you think my tunes are way cool or corny, but you can't argue with how easy it is to add the fanfare of your choice with a simple Tunes N, where N is a number from one to four. There's nothing stopping you from adding Tunes 5, 6, 7, and etc. if you are musically inclined -- or even if you aren't.
What key indeed? When someone types a key that you wish to use in a program, the results can be confusing. Especially if someone press Alt-F4 and expects the program to exit, or the PageUp key with the Num Lock turned on (which prints a "9" instead). I fix all this and more with a simple keyboard handler that I always use when I get keys from the keyboard. See how it runs and try it out yourself in the Toolkit demo.
Index of SUBs
Check this index to find where any SUB is used in the seminar programs.
1 Isaac -- drawing squares, adding delays.
Delay DrawSquare Gobble
2 Space Dock -- tunes, times, detecting crashes
Asteroid CrashDetect Delay DrawSquare Gobble TimeClock Tunes WhatKey
3 Newtona 500 -- race cars, vectors, Pythagoras
CrashDetect Delay DrawCourse DrawSquare Gobble LapCount ShowStats TimeClock Tunes WhatKey
4 Hangperson -- menus, boxes, getting data from files
Boxer Clearit CreateWord Delay GetFile Gobble InputLetter InputWord IsDone Menu MenuYN PrintScore PrintWord Rand Robot Tunes WhatKey
5 Music -- random numbers
AddNote Delay KillNote Quitsky Rand SetupData Shill
6 Simon Sings -- using the toolkit in your programs
Boxer ClearIt Delay Gobble Rand Tunes WhatKey
The next step
I hope that sharing some of the tools that I use has given you a boost or a head start in your own programming efforts. It has taken me quite a while to discover that creating useful and powerful tools is a very important part of writing good software. You, of course, don't have to stop with this modest collection. Write your own! Once you have developed an idea or subroutine, you can use it over and over again. In this way, you will quickly develop your own library of tools and tricks that make your software unique.
There's nothing else you need beyond creative ideas, a computer, and the standard version of QBASIC to learn on your own and write really good software. Your imagination is always the starting point for any creative work, and the computer is both a means and a perfect teacher for exploring your ideas and sharing your vision.
Microsoft QBASIC and my toolkit will get you started and should keep you busy for quite a while. If you decide to create professional software, or programs that you will share with other people, then I have a couple of suggestions.
If you're serious about programming...
This book by Wallace Wang is a great source of information. I highly recommend it if you find the examples I use in the Seminar interesting and would like to continue developing programs of your own. Please don't be insulted by my suggesting a book for "dummies." I use dummies books from IDG Books all the time -- and I've been programming for over 20 years.
Check your local bookstore, or order this and many other
books on programming from
To learn more about this book, check the following link
at the Amazon web site.
If you want to create professional programs that can be run without QBASIC present (EXE files like the program examples in the Seminar) you will need a compiler that translates your program into a file that can be run on any DOS computer. Your compiled programs can then be sent or sold to anyone running Windows or DOS. You can learn a lot more about QBASIC compilers and similar data from the Internet. I suggest using Yahoo! or a similar source and requesting information about QBASIC. You will get a listing of many types of compilers, advanced QBASIC techniques, and even clubs that specialize in QBASIC programming. It won't take long for you to quickly go beyond the simple examples I've shown you in the Seminar to creating software that is truly professional in appearance and content.
I also suggest that you consider getting additional programming tools that add even more capability to your software. I use and highly recommend a product called QuickPak(tm) Professional DOS. This is fairly expensive, but well worth the investment and adds hundreds of important and powerful features. You can get more information about this product and details about licensing agreements for schools by contacting Ethan Winer at Full Moon Software by Phone 860-350-8188, FAX 860-350-6130, or email firstname.lastname@example.org.
In creating the original Ainsworth Keyboard Trainer 3 and similar products I used the professional version of QBASIC, which includes a compiler for creating EXE files. This development software is no longer being sold by Microsoft. To my knowledge, this program is not available anywhere else, either, which is unfortunate. I also used several essential routines from Etan Winer's QuickPak, including the drop-down menu system and a variety of critical functions for reading and setting keyboard functions.