UNIT 6: Workshop management: BASIC, Text-files and DOS.

Unit 6 brings us to the half-way stage of our course. We have covered the greater part of the fundamental BBC BASIC keywords needed for practical programming, and we need at this point to turn our attention to managing our growing list of programs. We need, in fact, a workshop, both for editing programs and storing them in directories. For this we must explore the interface between BBC BASIC and DOS, as well as the routines for converting BBC BASIC programs into text-files which are compatible with both DOS and Windows word-processors.

A separate section is appended for Z88 users on the routines for editing BBC BASIC programs in PipeDream.


A full explanation of these keywords is given in the BBC BASIC MANUAL, under Editing, and now that you are familiar both with writing short programs, and re-writing them when they go wrong, it is time to study this section of the Manual, so that you can edit your programs, instead of rewriting them.

Beeb veterans will naturally look for the equivalent of the "copy-key" on the BBC Micro keyboard. Both veterans and new students need to be aware that although there is no designated "copy-key" on the PC, the TAB key has been co-opted to serve this purpose. Its purpose is to save you the labour of retyping a whole line when you only want to change one or two details. The TAB key takes on this role when you go into editing mode, and to activate it you simply press it. Both veterans and new students will find that the editing commands on the PC version of BBC BASIC are extremely versatile. These are EDIT and *EDIT respectively.

EDIT is used for correcting a single line. Let's say you forgot the inverted commas for a PRINT statement in line 450. Herewith the incomplete line:

450 PRINT "It looks like a mistake in punctuation

To correct this, you simply type EDIT 450 - the offending line is selected and you can alter it using the cursor keys and the normal editing functions of the PC keyboard.

Suppose, however, you want to alter a much bigger section of program, say a procedure, taking up the length of the screen or more? Here you need the screen editor rather than the line editor, and it is accessed by the star command *EDIT, followed by the first line of the program section in question, e.g. *EDIT 450

This will display all the lines from 450 onwards for the full length of the screen. As before, you use the cursor and delete keys in the same way that you would for editing text on the PC. And here you press ESCape to exit the editor and return to your program.

If you just want to correct a single error in a program line by copying the whole program line and inserting the alteration, then the COPY key emulator is ideal for this purpose. As stated above, there is no designated COPY key on the PC as there was on the BBC Micro keyboard. To initialise the TAB key to perform this function you simply press it. This creates a the small cursor which you direct to the line you want to copy by means of the arrow keys. Having located the line in question, you simply press the TAB key again to start copying, and then either press it repeatedly to copy character by character or hold it down to copy the whole line at speed. This can be extremely useful for the repetitive duplication of procedure lines, where you might have a series of procedures which are similar but not identical.

We shall now put this into practice by getting to the bottom of the palindrome problem, as promised, in Unit 5. Load the program, then copy line 80 to remove the +P$ from the end of the line. Then copy line 70 and cut the loop down to one pass, so that it reads

70 FOR J%=1 TO 1

Run the program and enter, as an example, the name HERMIONE when prompted at line 20. You get the first letter - H - of the name. This is logical enough if you consider how the definition of MID$ works! (If you have forgotten, it would be well to revise it at this point!) Now edit line 70 again to increase the loop to 2, so that it reads

70 FOR J%=1 TO 2

You get the second letter of the name - E. You can carry on increasing the value of J% in this way until you reach 8, at which point you can restore the line to its original value of LEN(A$). Since, as you will see, this returns each letter of the name in the "correct" left to right sequence, the question arises: why does the palindrome function reverse the sequence? To answer this, before we restore the +P$ to line 80, we now need to recollect that the assignment of a variable works from right to left across the equals sign. With that in mind, the telegram language of this BASIC line needs to be amplified by a mental note:

"New P$ =MID$(A$,J%,1) concatenated with Old P$"

You cannot, at the start, concatenate P$ with the "previous" P$, because the "previous" P$ doesn't exist at the start! So each increment "lags behind" the previous one at each pass through the loop.

You will find, if you apply this "sectional" technique to the study of professional programs, that the TAB key in copying mode will enable you to isolate difficult procedures or functions, strip off the complexities, add framework lines to run the section of program separately, and thus see how the skeleton program works before restoring the bits and pieces you have stripped off.

Another useful adaptation of the above-detailed copying function, when writing a program, is to prepare your own individual procedures separately, for "trial runs" as mini-programs. When you have checked them out in this way, there's no need to write each one out again as a section of your main program: you can convert these sections into text files, and edit them in a word-processor such as Notepad, from which they can all be merged into one in MSWord. (The reasons why the editing cannot be done in MSWord will be given when the editing itself is discussed.)

Let's say you are going to merge three program sketches called "P_ONE" "P_TWO" and "P_THREE". If the program lines are to be numbered in sequence, you have an initial problem, since each separate program starts at line 10. To overcome this you can use the automatic line numbering function RENUMBER 1000, to renumber each line of P_TWO, giving 1010,1020, etc. You then use the command RENUMBER 2000 in order to renumber P_THREE. In order to merge the three programs directly in BASIC, however, a rather more complex routine is needed than the familiar process of merging text-files on a word-processor. So we will start with the familiar process and convert the BASIC programs, which we want to merge, into text-files first. This involves toggling between BASIC and Notepad (if you have Windows) to edit the text-files, and before we toggle, we need to take a look at the partnership between BBC BASIC and DOS on the PC .

Working with DOS

It would naturally be out of place here to embark on a crash course in DOS - however, there are certain essential DOS routines, needed for handling files, which must be reviewed at this point. (For those who want to make the most of the interface with DOS, there is an excellent little paperback by Oliver & Kantaris, entitled DOS - One Step at a Time, in the Babani series.)

Our first task is to get into the root directory of DOS. If you are in a Windows environment, you can either do this by restarting your computer in DOS mode, (unless you happen to have put a shortcut to DOS on your desktop), or you can click on "Start" - "Programs" - "Command Prompt". The DOS prompt should look like this:


Why is the C drive so-called? From the beginning the IBM PC and compatibles had DOS. Most machines had twin drives for floppy disks, called A and B. So when the hard drive appeared, they called it C.

Unlike the DFS system on the BBC Micro disk drives, which had an alphabetical index within a single directory, DOS provided support for 360 KB floppy disks and subdirectories as from Version 2.0 in 1983. The root directory, under which all others are classified on the hard disk, is C: itself. Those who once operated a pre-Windows DOS PC will need no introduction to this. But if you use Windows, and are unfamiliar with DOS, the best plan is to stay in the Windows directory, which is the default directory when you restart your PC in DOS mode. (One of the main advantages of this, as we shall see later, is the facility of toggling between your BBC BASIC window and the text window in which you read this BBC BASIC Tutor.)

Let us assume you have moved into DOS. You need to access the directory in which BBCBASIC is resident. If you or the person who installed BBCBASIC went by the book, the directory itself will probably be called BBCBASIC, in which case you access it with the command:


CD means "change directory" and is used to check the existence of, and move into, a named directory. To get back to the highest level of all in the directory tree (paradoxically called the "root" directory!) you simply type CD\ [ENTER] on its own.

To list the contents of a small directory - and in our case, that means the original directory of BBC BASIC - you type DIR , and if it scrolls past at lightning speed, you can either type DIR /W (meaning "wide"), which lists the directory in horizontal format, or, if that also doesn't give the entire directory contents, you can type DIR /P (meaning "pause"), which lists the directory one screen at a time, pausing for you to press [ENTER], until it gets to the bottom. If you want to print the directory out, then press SHIFT and PRINT SCREEN each time round before you press ENTER. It would be a good plan to print out the whole directory, since you will then be in a position to see what needs tidying up. The right hand column gives the date of creation of the file, which in turn will be a fair (but not foolproof!) indicator of those files which came with the software itself. These must naturally be kept. But the rest can be weeded out.

The DOS command for deleting a file is ERASE although it is possible to use DEL.

If you want to store files of a given kind, you make a directory by typing MD, followed by the name chosen. Let's suppose you are going to put financial management programs under the heading BANKER. You type MD BANKER. Then you move into the directory by typing CD BANKER. To copy a file - say STATMNT.BBC - into this directory from the BBCBASIC directory, you type COPY C:\BBCBASIC\STATMNT.BBC

This task of file management can also be done within BBCBASIC itself, but for the moment we shall stay in DOS, which shows both program files and text files - the latter having the extension .TXT In order to tidy up the text-files, you could create a directory called TEXTFIL, move into it, then use the wild-card *.TXT to copy all text-files into the directory.

If you are not very familiar with filename extensions, it would be a good plan to study the filenames within BBC BASIC(86) whilst you are in DOS itself. You will find that the files have a number of extensions: .EXE is for a file which executes a program, such as BBC BASIC itself, whilst the extension .BBC is for a BBCBASIC program, and .TXT is for a text file. (When you exit DOS to go into BBCBASIC, the .BBC file extension disappears, and the text files go behind the scenes.) All of this is of crucial importance as we now come to spooling BASIC files into text files for editing and merging purposes.


The term "SPOOL" is an acronym for "Simultaneous Peripheral Operation On-Line", which originated in the need to prevent slow peripheral devices from holding programs up. However, that need not bother us. We need it, in practical terms, to convert a BASIC file into a text file. To do this, carry out the following steps:

a) Go into BBCBASIC.
b) LOAD the named file, e.g. "BANKER"
d) LIST the file
e) type *SPOOL

If you now exit BBC BASIC by typing *BYE and go into DOS to view the BBC BASIC directory, you will find BANKER.TXT listed as a text file. If it is a short file, you can actually type it onto the screen by using the command TYPE followed by the file name. Much better, however, is to transfer it to a word-processor. And this is where a the above- recommended filing skills in DOS comes into their own, since they can circumvent difficulties thrown up by Windows.

Let us assume, for the moment, that your operating environment is Windows 95/98. It comes with a small-scale resident word-processor called Notepad. It is much better than MSWord for spooling BASIC files, because it reproduces single and double speech marks - essential for line-spacing and INPUT commands in BBC BASIC - exactly as they are, whereas MSWord turns them into "leading" or "trailing" speech-marks, which play havoc with single inverted commas used for line-spacing.

So, to transfer the spooled BBC BASIC text-file, called BANKER.TXT, to Notepad, it is better to go into DOS, where you can type the full file-name with all the necessary hierarchical backslashes and dots which cannot be included in a Windows filename itself, as follows:

Let us assume that you share a Windows 95/98 PC with several other users, and your own desktop folder is named ESMERALDA. Type the following command in DOS:


Then exit DOS, go into Notepad on your desktop and click on BANKER.TXT. You will find it spread across the screen in a single line. So click on Edit and then Word-wrap, which will list the lines. You can then carry out any further text editing you wish - and also, more importantly, you can merge your separate spooled files into one single program. Once the constituent mini-programs have been correctly written in Notepad, they can be merged in MS Word by being inserted as files - the correct inverted commas will be imported from Notepad. (But make sure all the editing has been done before merging in MS Word! ) The use of 1000's and above to preface program sections will ensure correct sequencing when the file is *EXECuted back into BBCBASIC. However, before we can do this, we must go back into DOS and transfer the merged file to the BBC BASIC directory, as follows:


You then go back into BBCBASIC and type *EXEC BANKER.TXT. The program will appear in BBC BASIC line by line, each one preceded by the > sign. You then type LIST to read the complete new program, and RUN to execute it.

Richard Russell has kindly furnished an illustration of using the *SPOOL and *EXEC commands to merge files within BASIC. First revise the paragraph above which illustrates the routine for merging three BASIC files, P_ONE, P_TWO and P_THREE as text-files. Then compare it with the following illustrations by Richard Russell, the second of which uses *LOAD:

Method 1 (using *SPOOL and *EXEC)


Method 2 (using *LOAD)

*LOAD P_TWO nnnn [where nnnn is the value printed]
*LOAD P_THREE mmmm [where mmmm is the value printed]

More on handling data and merging files


We have seen that one of the great advantages of programming in BBC BASIC is that you can quickly edit tailor-made files yourself, instead of having to scroll through sheet after sheet of editing instructions in a large-scale commercial software application. That said, the facilities of a modern word-processor on the PC can, as we have seen, enormously speed up and rationalise the business of editing executable programs as text-files.

One particular routine for which this will be of great help is an established facility for entering data into a program, to be read and processed. At the time of writing, the academic year is drawing to a close in the UK, and students in schools and colleges will be taking examinations. Let us assume you are a teacher in charge of three sets taking the same examination in a given subject, in a given year. There are three questions in the test paper, each with a total of twenty marks, and from the grand total you want to arrive at a percentage. The program below has an overall framework into which the figures for the test can be entered as variables, from year to year. It also has all the names of the pupils in a given set. The BBC BASIC keyword READ causes the program to read the names which follow the DATA statement. They are then printed out with the results entered.

10 DIM markone(10)
20 DIM marktwo(10)
30 DIM markthree(10)
40 DIM total(10)
50 DIM P%(10)
60 DIM NAME$(10)
70 FOR J%=1 TO 10
90 CLS:PRINT'''"Enter the marks for ";NAME$(J%)
100 INPUT'"Mark one ",markone(J%)
110 INPUT'"Mark two ",marktwo(J%)
120 INPUT'"Mark three ",markthree(J%)
130 @%=&00009
140 total(J%)=markone(J%)+marktwo(J%)+markthree(J%)
150 P%(J%)=(total(J%)/60)*100
160 NEXT
170 PRINT "NAME","Q1","Q2","Q3","Total","Percentage"
180 FOR K%=1 TO 10
190 PRINT' NAME$(K%),markone(K%),marktwo(K%),markthree(K%),total(K%),P%(K%)
200 NEXT

On closer examination, it doesn't take a great deal of common sense to spot a potential drawback in this program: how much labour is going to be saved if the names of the members of each separate set have to be typed afresh every time the program is run? On the BBC Micro this sort of thing used to take a fair amount of backroom labour in file management - but if you have a Windows PC, you can store each class list as a text-file, and then go through the routines detailed earlier in this unit to merge the program with the text-file of the class list in question, then *EXEC the program back into BBC BASIC.


An alternative to merging the data-files as text-files into the main program, as detailed above, would be to have three separately numbered DATA lines, each containing the names of one of the three sets. To get the program to read a particular data line, you type RESTORE followed by the line number. So if you have three sets of students, listed in line numbers 1000,1100 and 1200, you could put the program through a nested loop, in which, on each pass, you RESTORE the data pointer to the next DATA line. Try it. You can also use RESTORE on its own to reset the pointer to the first DATA line.

Line130, by the way, is there to record the marks as integers, without decimal places in the marks or percentages. @% controls the arrangement of the figures in a column or "field". The character & means that Hexadecimal numbers follow . These are numbers where, instead of writing 10,11,12,13,14,15, you write A,B,C,D,E,F, in other words, it enables you to use a single character instead of two characters for numbers up to 15. This relates to the use of binary code in the hardware, which need not concern us here. However, since in the above example we are using the @% variable to lists the test results without decimal fractions, it would be interesting to note the definition of the frequently-used @% variable for two decimal places (@%=&20209) in the original BBC Micro User Guide :

For the more technically minded @% is made up of a number of parts
(Means hexadecimal numbers follow) Format number 2, i.e. fixed number of decimal places 2 decimal places field width of 9 characters

There are no formal assignments in this Unit, since everything discussed here, if applied, will involve a major overhaul of the way in which you write, store and use your programs and data. A full Index of BBC BASIC keywords can naturally only be drawn up when our online Tutor is completed. But you should at this stage print out the list of keywords given in the BBC BASIC Manual, and tick those which we have defined and used. These are, in order of appearance:


Clearly some of the above keywords have to date only been briefly introduced, and there is much more detail to fill in, particularly in the field of graphics, but we are well over the half-way mark now in our study of BBC BASIC keywords.

Unit 6.Z

Editing BBC BASIC programs on the Z88

For Z88 users who originally learnt BBC BASIC on the BBC Micro, as well as for new users, there is an obvious problem in the lack of a COPY key - and the TAB key cannot be drafted in for this purpose as in BBC BASIC for the PC. You can, however, for small jobs, emulate a line editor by printing to screen the line you want to edit, then underneath you can write your new line, and compare it character by character with the old one.

Much more effective, however, is to convert your program into a text-file and then edit it in PipeDream. You can even write new programs from the beginning in PipeDream and edit them much more easily as text-files than you can in BASIC.

Certain precautions have to be taken first, however, and they are truly vital. You go into a new PipeDream page and type #B at the top. This will direct your file to BASIC when it is executed. Next you type .J underneath it. The purpose of this is to ensure that the lines are separately listed, instead of appearing as a continuous string. These two steps can be remembered as a sort of mantra, as "hash-B-dot-j" - use any method you like, but never forget them!

You can then write your program, using the normal PipeDream tools to edit it. When you have finished, save it as "plain text". This is also vital. Then go into the Filer application, highlight the file, then select Execute from the menu of options. The file will now be EXECuted into BBC BASIC automatically. These operations clearly correspond to the *SPOOL and *EXEC commands both on the BBC Micro and in BBC BASIC for the PC.

An alternative to using the Filer application is to use the CLI - "Command Line Interpreter". The square key which accesses so many Z88 applications will be represented below by []

The steps for editing an existing file are as follows:

  1. Enter BASIC and LOAD your BBC BASIC program file.

  2. Type LIST [] +S <ENTER> (This corresponds to *SPOOL on the BBC Micro and in BBC BASIC for the PC.)

  3. Type []-S

  4. The spooled file has been stored in :RAM.- as S.SGN

  5. You can now load this file into PipeDream - provided you have gone through the above-mentioned steps of entering #B and .J as the first and second lines respectively, albeit without needing to number the lines. (If you happen to have the BBCBASIC (Z80) Reference Manual you will find this procedure under *SPOOL and *EXEC in Star Commands - if there are any problems with using the CLI, the best policy is to use the Execute option with the Filer, as detailed above.)

That said, PipeDream is the best word-processor available for editing spooled BBC BASIC files. If you have both a PC and a Z88, then PC PipeDream, which is still available from Rakewell Ltd, is worth installing on your PC as a much better word- processor than Notepad or MSWord for this purpose.

Left UNIT 5

UNIT 7Right

Best viewed with Any Browser Valid HTML 3.2!
© Edmund Burke 2000