★ APPLICATIONS ★ UTILITAIRES RSX/LIGNE DE COMMANDE ★ INSTANT ACCESS ★ |
INSTANT ACCESS (Computing with the Amstrad) | INSTANT ACCESS (Amstrad Action) | INSTANT ACCESS (Popular Computing Weekly) | INSTANT ACCESS (CPC Magazin) |
If you've got a disk-equipped CPC and you program in Locomotive Basic, you've got a lot of features available to you in the way of graphics and sound commands that PCW owners and their Mallard Basic don't have. Mallard does have one feature, though, that Locomotive can't match - and that's random access file-handling. THE PROBLEM When you want to read files in Locomotive Basic, you can only get at your information sequentially in the order you stored it in the first place, that is. If you've stored 100 phone numbers and want to get at the 50th one, you have to open the file and read in and discard 49 phone numbers to get the one you're after. If you now want to read the 38th number you have to close the file, reopen it and start the read/discard process again. THE SOLUTION What you need is a way of getting at the precise piece of information you want without having to plough through all the data up to that point. This is called random access and as I said earlier, Locomotive Basic can't do it. Till now, the answer has been to work in CP/M - both of the CP/M Pascals reviewed this issue offer random access, or if you prefer Basic you could buy a copy of Mallard. That does mean learning a new language, though, or at least a new implementation of Basic. THE ROUTINES There are nearly 40 RSXs in the package, a third of them actually dealing with random access. The key ones are |CREATE to set up a new random access file, |OPEN and |CLOSE for existing files. PRINT to write data and |INPUT to read it. The routine starts reading in characters from the random access file, putting them into stringname$ until it's full. If you've previously defined stringnameS as a string of 10 blanks then, after the routine has done it's job, the string will instead contain 10 characters read in from the file. The two numbers in the example tell the routine which part of the file you wanted to read from. If you don't bother to give them, the routine will carry on reading where it left off last time - just like a sequential system. |PRINT works in a similar way and, helpfully, can be freely used alongside |INPUT. You don't have to open a file specifically for input or output, in other words: if you read the data and find it needs updating you can rewrite it without the need to close and reopen the file - another advantage over Locomotive Basic. AMSTRAD ACTION n°12 |
|
|