• Keine Ergebnisse gefunden

INPUT "WHAT IS THE PART NAME N$

Im Dokument North to (Seite 143-147)

The same general information pertaining to LINE 50 goes for this LINE with one notable exception -- the dollar sign,"$", which follows the

"N". In pure computer talk this INPUT statement wants you to type in a STRING. For some unknown reason all alphabetic or alphanumeric values are called a STRING. For ease of understanding, I have found it useful to automatically substitute WORD every time I see or hear STRING. This conversion is not exactly valid, but by the time you understand the reasons why it's not, you will understand the concept of STRING variables.

Now back to LINE 60. On the monitor we would see:

WBAT IS TBE PART NAME

You would then type in (INPUT) BY-TEMP SPARK PLUGS

We have now assigned the "word" - BY-TEMP SPARK PLUGS - to the

"word variable", "N$". Or in computer talk the STRING VARIABLE, "N$", is equal to : BY-TEMP SPARK PLUGS

The relationship between the two variables

-123-N 1001

N$ HY-TEMP SPARK PLUGS

is essentially the same as far as the computer is concerned. They are handled the same way, as illustrated above for the numeric variable, if we told the computer to PRINT "N$" it would PRINT : HY-TEMP SPARK PLUGS, since that is what "N$" is equal to.

The computer now has the required information for performing the task that we set out to do, i.e. , values for both variables, or answers to both its questions. We must now tell the computer what to do with this information (data).

We want it to WRITE this unique combination of part number and part name on a mini-disk so that ''I~Ol'' and "HY-TEMP SPARK PLUGS" are inseparable. If one knows the part number the computer can tell you the part name or if one knows the part name the computer will tell you the part, number.

If we were doing this by the "hand" method, we would have to go to the file cabinet (the mini-disk), open the cabinet and take out our file folder for AUTO PARTS (OPEN the FILE named AUTOPART), write down the information on a sheet of paper in the folder (WRITE N,N$), and then close the file and put it back into the file cabinet (CLOSE), and we are finished (END). The computer must be inst.ructed to do essentially the same thing. We tell the computer to :

40 OPEN #0, "AUTOPART"

This STATEMENT tells the computer to :

a. Go to "file cabinet" #0 Turn on the disk-reader b. OPEN the "file cabinet"

Search for a FILE

c. Find the "file folder" named "AUTOPART"

Finds and OPENs the FILE - AUTOPART

At this point the computer has the required information to be recorded, has located the proper FILE to WRITE the information to, has OPENed the FILE and is READY to put it in the FILE. We must now tell the computer to put the data into the "file folder". So our next STATEMENT is :

80 WRITE #0, N,N$

The "#0 " makes sure that the computer WRITEs the values for " N" and

"N$" to the same FILE that i t spent all that time locating and OPENing. So, that's what i t does: i t WRITEs the values of the variables in the FILE represented by #0. If we could see the FILE AUTOPART we would see :

1001,HY-TEMP SPARK PLUGS

*

The computer will automatically WRITE the values of N, N$ at the start of the FILE. The asterisk at the end of the value of N$ is my representation of an END MARK. After each WRITE command the computer will place an END MARK at the end of the last item it recorded - it is like a p~riod at the end of a sentence. The need for the END MARK will become evident as we go on~

We are now ready to add more data. The next item will have the part number 1002, and it is a SEALED BEAM LIGHT. Therefore N

=

1002 and N$

=

SEALED BEAM LIGHT. In order to get back to the start of our program we have to tell the computer to go back and get some more data. Since we did not tell the computer to CLOSE the FILE i t , left it OPEN and the recording head (pointer) is at the end of the previous INPUT. This being the case, we will not have tell i t to do all that again. All we have to tell the computer to do is go back for more data or INPUT. So, we tell it to go to LINE 50, which is the first of the two INPUT statements:

90 GOTO 50

The next thing to appear on the monitor is

WHAT IS THE PART NUMBER

You would then type i n : 1002

WHAT IS THE PART NAME

You would then type in SEALED BEAM LIGHT

The computer would then go through the same motions as before and our FILE would now look like this :

-125-1001,HY-TEMP SPARK PLUGS,1002,SEALED BEAM LIGHTS*

Then the computer would go back for more data

INPUT WRITE GOTO INPUT

This cycle would continue as long as you want i t to. After a few minutes our FILE would look like this :

1001,HY-TEMP SPARK PLUGS,1002,SEALED BEAM LIGHTS, 1003,BONDED BRAKE LINING,1004,STEEL BELTED TIRES, 1005,SEAT BELTS,1006,LOW PRESSURE OIL GAGE,1007, AIR HORN,1008,HI-LOAD SHOCK ABSORBERS,1009,LOCK TYPE GAS CAP,lOlO,WIDE ANGLE MIRROR*

That's exactly what we want. But it's not all that easy. If we were to PRINT the contents of our FILE AUTOPART as we have constructed it, we would not get what we have shown above, but all of our STRING vairables (words) would be cut short and limited to only 10 characters (10 bytes).

Thus our first item:

1001,HY-TEMP SPARK PLUGS would be

1001,HY-TEMP SP

There is a pre-set limit to the size (DIMENSION) of any STRING vairable (word). Unless told otherwise the computer will give all STRING variables the DIMENSION of 10 characters. If the size, length, or DIMENSION of a "word" is greater than 10 characters, only the first 10 characters are accepted by the computer and the rest are ignored.

Although, this 10 byte limit would not effect some of the data entries in our FILE, it would render others unintelligible. Unless one is willing to play word games every time they got only a portion of a "word", this situation would be considered unacceptable.

There is a method of correcting the problem. One need only consider the length (DIMENSION) of the longest single

" word ",STRING vairable, in his data. In our case that would be 23 characters found in part number 1007. We must then tell the computer how many characters to reserve for each of our "words", STRING variables. This is called DIMENSIONing a variable. Our DIMENSION statement is part of the BASIC program and must appear befor the

Im Dokument North to (Seite 143-147)