Well i have the problem of not knowing how much or how little you do know, therefore i will have to start from scratch and presume you know nothing on the subject. A little boring for some of you i know, but at least i know i will have covered all levels of competence.
Well i have the STOS Manual at my side to refer to. Its now some time since i learnt how to use these commands and its only now that i realise just how useless the manual is. The commands i first learnt and the ones we will be covering ie: SEQUENTIAL FILES, "FILENAME.SEQ"
Before i go any further i will stop you falling into the same trap i did when i was trying to learn these, and that is the fact that the files we want to access do not have to have SEQ as there extensions. So we can use all the following on DOC, TXT, MUS, ASC etc etc...
Right then, the word sequence means that any access to these files will be done in order from start of file to end of file. In other words if you wanted to load line 300 from a DOC file you would have to load the first 299 lines to get to it. Random access files would let you load line 300 on its own, or save line 300 on its own. In order for us to save one line we would have to save the whole file, apart from the making of a database program i can think of no reason to want to load just the one part of a file. In fact i have never needed that system so we will just concentrate on SEQUENCIAL FILES.
Next we need to find a file to open, so we will use the file selector to find one. You will find the instructions for this in page 218 of your manual. But i have just looked at it and its not very clear is it, here i will show you what to do.10 DIM TXT$(1000)
20 F$=FILE SELECT$ ("*.*")
This will bring up a file selector that will list all the files and folders
in the root directory. The "*" simply mean show all, so it will show all
the file names and all the extensions. If you only wanted DOC files to
be listed then you would change it to:
20 F$=FILE SELECT$ ("*.DOC")
Then whatever file you click on, F$ will hold the name of that file, so
if you click on READ_ME .DOC , then thats what F$ would equal.
Next we want to open that file, we can have more than one file open at once, so we have to keep them numbered. We then use that number for everything we do to that file so as not to confuse STOS. If you are only using one file at once then you must still number it. So to keep things as clear as possible we will call this one number one, but it must be prefixed by a #,So we are working on file #1
"Open" speaks for itself ( i hope ) ,"F$" holds the filename,"#1" is the number of the file we are using, "IN" means we are opening the file for retrieving/getting data and bringing it into our program. The oposite function ie: saving data is the opposite command ie: open out #1, f$, but dont worry about that yet, so long as you fully understand line 30 and what each peice means.30 OPEN IN #1, F$
Now we obviously want more than one peice of information bringing in, ie: each line of the DOC file is a seperate peice of info that we will be puttting into each cell of our array. Therefore we will now need to set up a loop in order to bring it all in.
Now to explain the above,40 E=0 : REPEAT 50 LINE INPUT #1,TXT$(E) 60 INC E 70 UNTIL EOF(#1) 80 DEC E 90 CLOSE #1 : rem we have got it!
To open a file for Saving something to disk we use the following command.
Or if you have just loaded a doc file or an high score table or something with a variable as in the loading commands, open in #1, F$, then you can use the same variableOPEN OUT #1, "FILENAME.DOC"
Then instead of INPUT #1, TXT$(E) we would do the opposite and..OPEN OUT #1,F$
So to save out the doc file you loaded in with the loading commands, you would now use the following.PRINT #1, TXT$(E)
The EOF(#1) will not work when saving out, but we already know how many lines to save as we got that with the E variable, so its easy enough to make a controlled loop from 0 to E and we cannot miss then can we.100 OPEN OUT #1,F$ 110 FOR N=0 TO E 120 PRINT #1,TXT$(N) 130 NEXT N 140 CLOSE #1
Please note: When you open out a filename, it will erase any file with that filename thats on the disk. Therefore if you had a doc file with lets say five hundred lines in it and you wanted to add one line, you cannot open the file and print to disk just line TXT$(501) ,because then the file with that filename will then simply consist of the one line you just saved. Hence the explanation earlier about SEQUENCE, you would have to load the whole five hundred lines, then add one line, then save the five hundred and one lines.
The use of RANDOM ACCESS files will however let you load or save just one line, but i dont know enough on random access files to enable me to write an article on the subject, If you do then write it up for us!.
Well i hope the above is enough to get you started on using the saving and loading commands that are at your disposal. There are lots of other commands that can be used in conjunction with the above. I suggest that once you can do the above then the rest will come to you a lot easier with the use of your trusty manual.
HAPPY STOSSING!