BEGIN WITH THE BASICS

  1. SENTENCE PROGRAM & CODE ON-LINE
  2. PROGRAM POINTERS
  3. JUST STARTING TO PROGRAM? LOOK HERE
  4. OTHER BASIC SITES ON THE WEB

SENTENCE PROGRAM & CODE ON-LINE

For this issue, I have a complete program that accompanies the column in the CÆLL Journal. The program is called the Sentence game because it reinforces word recognition in a sentence context as well as giving a bit of a push on spelling and keyboarding. While this program is definitely not ready for prime time, it is a good example of how BASIC can give a teacher (I am not a programmer) just the right program.

To load this program:

  1. download the Sent.exe OR Sent1.exe file (see instructions below).
  2. open QBASIC (it should be in your DOS directory) or Quick BASIC 4.5 if you have it.
  3. In the File menu choose Open.
  4. Locate the directory where you expanded the Sent.exe files and load the SENTENCE.BAS

The purpose of posting code here is to give readers the chance to try them out. Try loading up the SENTENCE.BAS module and changing some code or adding to it. I have taken time to comment the code throughout so that even if you are just beginning to program, you should be able to follow the flow of the code.

You can download the Sentence program from this page. The file, Sent.exe, is self expanding. Just place it in a directory and type SENT and it should expand to the following files:

PROGRAM FILES:

QBASIC (Free with DOS)

NOTE: For the QBASIC program, I have included all subs in the single module SENTENCE.BAS because QBASIC limits the number of modules.

  1. SENTENCE.EXE: This is the execute file already compiled and ready to run.
  2. SENTENCE.TXT: This is the text file that contains up to twenty sentences (you must have this in the same directory as Sentence.exe for the program to run.
  3. SENTENCE.BAS: This is the MAIN MODULE. Load this into Quick BASIC to change the program. NOTE: this file can be read by any text editor and includes all of the code for the program.


Quick BASIC 4.5

  1. SENTENCE.EXE: This is the execute file already compiled and ready to run.
  2. SENTENCE.TXT: This is the text file that contains up to twenty sentences (you must have this in the same directory as Sentence.exe for the program to run.
  3. SENTENCE.BAS: This is the MAIN MODULE. Load this into Quick BASIC to change the program.
  4. GAME.BAS: Can play three different typing games, from basic finger position to moving, bouncing letters.
  5. PRACTICE.BAS: This module is where the sentences are chosen and words scrambled, as well as user input to type words.

CODE ONLY FILES
(included in the Quick BASIC package)

  1. Sentenc.txt: Same as SENTENCE.BAS but in text format (NOTE: the last letter is removed so as not to conflict with the Sentence.txt file that contains practice sentences).
  2. Game.txt: Same as GAME.BAS but in text format.
  3. Practice.txt: Same as PRACTICE.BAS but in text format.

DOWNLOAD THE SENTENCE GAME (for QBASIC)

DOWNLOAD THE SENTENCE GAME (for Quick BASIC 4.5)

If you do download and give it a try, please come back and give your comments on the CÆLL page (FEEDBACK form). I look forward to any comments as well as any changes to the code.


PROGRAM POINTERS

NOTE: For the QBASIC program, I have included all subs in the single module SENTENCE.BAS because QBASIC limits the number of modules.

This is the basic design of the Sentence program. Three modules cover the three main parts of the program, although it would have been easy to complete the whole program in one module. Even though the all the subs could fit into the SENTENCE.BAS module (as has been done for the QBASIC version), we want to try to divide work as much as possible so that all our programming becomes building blocks that can easily be recycled. For example, the typing game in this program was lifted from a previous program I had written. All I needed to do was load the module up into QuickBASIC and then it became part of the Sentence program. The program begins in the SENTENCE.BAS and most of the activity takes place in the ShowSentence sub proceedure in the PRACTICE .BAS.


Just Starting?

Programming building blocks

Variables

Variables are the smallest units of a programming language. A variable is placed on the left side of an equal sign while the value to be placed in the variable is placed on the right side, e.g., X$="Press Any Key." BASIC classifies variables into three main categories: strings, numbers and variants. String variables can contain any text characters, including Arabic numerals, but cannot be part of a mathematical calculation. Number variables are used for calculations and measurements but cannot contain any text. Number variables are further divided into subclasses of integer and floating point variables. The other variable type, variant, is more flexible and can take text characters or numbers of both integer and decimal values (the variant does use more memory-the most valuable commodity for a programmer).

This all may seem a bit confusing and is what often discourages people from coding. Variables must clearly belong to one of the classes. This is represented by attaching the correct symbol to the variable name:

Variable Name Symbol Type Result in Code
StudentResponse $ String of characters StudentResponse$
StudentNumber % Whole number (integer) StudentNumber%
Score ! Fraction Score!
Name NONE Variant Name

Subs

Numerous sub routines can be contained in a single module. Each sub usually performs a single action, for example placing a question on the screen for the user to respond to. When you want the question to appear, a line of code will "call" the sub (this means execute the commands contained in the sub).

Sub routines' most important feature is that they can receive and return "arguments." These arguments are just like the X and Y in the formula X+5=Y. If you increase the value of X then the value of Y will also increase. The formula is flexible yet consistent. Our sub could take an argument such as X$. When we call the sub we include the argument we want, such as X$="How are you today?" The code contained in the sub displays whatever message placed in X$.

Modules

The largest building block in BASIC is the module. Each program will have one main module where the program begins its execution, this is the main module. Other non-main modules can be included in your program. These modules divide up the parts of a program into major categories. For example, all file access coding could be in the same module, while all code for interacting with the computer user is contained in another module.

Time Savers

Reusing code

The best part of writing your own code is that each module, sub procedure and individual lines of code can be plugged into any other program you create, just like building blocks. Each time you write a program, your work becomes progressively easier.

Comments

While programming, the best favor you can do for yourself is to write comments along side of your code that clearly labels what the variables represent and what the actions are intended to do. Each module and sub should begin with remarks that tell what the sub is meant to do, what variables need to be passed to it and what variables need to be declared when the program starts in order for the module or sub to execute correctly.

Comments are include by beginning a line with the letters REM. Any line preceded by the reminder comment, REM, will not be executed in the code, so REM is also useful for removing lines of code from executing while you debug or make changes that you may want to later include in the execution.


Other BASIC Sites

Here are some great sites to learn more about BASIC, the most popular programming language in the world!

Joe's QuickBasic Pag http://home.fuse.net/dplee/program.htm

QBasic Page http://www.qbasic.com

QBasic for Beginners http://www.geocities.com/SiliconValley/Heights/5976/index.html

Paul Kuliniewicz's QBasic Page http://members.aol.com/Borg953/html-1/qbasic.html

Steven Salmon's The Beginners BASIC Home Page http://intermid.com/basic/basic.htm