Classic Computer Magazine Archive COMPUTE! ISSUE 21 / FEBRUARY 1982 / PAGE 179


Jim Wilcox
Vienna, WV

The following program will alphabetize letters or put numbers in order from lowest to highest. The first thing that will happen is the screen will clear and the message "HOW MANY VARIABLES?" will appear on the screen. You then type in the number of names you wish to sort. The variable "VAR" will take on the value typed in. The statement at line number 20 will set the amount of variables of the dimensioned variable "A$". If you are stuck on dimensioned variables, read on.

DIMensioned Variables

Dimensioned variables can be compared to houses on a street. Let's say the house numbers on this block start at one and end at ten. They all belong to the street named, say "Washington." To make things easier than naming each house after a different president, they are given numbers. There might be another house with the number two, but not on the same street. The name of the street is the variable, but there is more than one house on the street, which are variables too. To get a letter to house #2 on Washington Street, one would have to write the person's name, "Jones," who would reside at 2 Washington Street. In a computer program, one could set the variable WASHINGTON$(2) = "JONES". 1 Washington Street might have the "George's" living there so the variable would be WASHINGTON$(1) = "GEORGE". So a dimensioned variable is a variable that has other variables related to it, i.e. all the people on the block have in common the fact they live on Washington Street.

I recommend that you try a small list first, such as ten of the letters of the alphabet mixed up. This will not take long to put the characters in order and the programmer can tell whether the program was typed in properly. On longer lists it becomes tempting to hit the RUN/STOP key to see if the computer is stuck in an endless loop, but the longer the list, the longer it takes.

20 DIM A$ (VAR + 22)
40 PRINT"#" A;
50 INPUT A$ (A)
80 FOR A = 1 TO VAR-1
90 FOR B = A + 1 TO VAR
100 IF A$ (B) <= A$ (A) THEN SM$ = A$(B) : A$(B) = A$(A) : A$(A) = SM$
110 NEXT B
120 NEXT A
140 POKE36878,8
150 POKE36874,250
160 FOR A = 1 TO 500
170 NEXT A
180 POKE36878,0
190 POKE36874,0
200 FOR A = 1 TO VAR STEP 22
210 FOR B = A TO A + 21
220 PRINT A$ (B)
230 NEXT B
240 GETA$ : IF A$ = "" THEN 240
250 NEXT A
260 END