A separate section is appended for Z88 users on the routines for editing BBC BASIC programs in PipeDream.
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 .
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.
a) Go into BBCBASIC.
b) LOAD the named file, e.g. "BANKER"
c) Type *SPOOL BANKER.TXT
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:
COPY BANKER.TXT C:\WINDOWS\DESKTOP\ESMERALDA\NOTEPAD
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:
COPY C:\WINDOWS\DESKTOP\MSWORD\BANKER.TXT C:\BBCBASIC
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:
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
80 READ NAME$(J%)
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%)
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%)
210 DATA AMY,BELLA,CAROLINE,DAISY,EMILY,FELICITY,GERTRUDE
220 DATA HERMIONE,ISABEL,JESSICA
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.
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:
PRINT,REM,SQR,LET,RUN,INPUT,NEW,CLS,TAB,FOR,NEXT,STRING$,VDU2, VDU3,DIM,CHAIN,LIST,LOAD,RUN,COLOUR,MODE,DRAW,OPENOUT, OPENIN,PRINT,CLOSE#,INPUT#,OPENUP,PTR,EOF,REPEAT,UNTIL,LEN, SPC,IF,THEN,OR,ELSE,GOTO,PROC,END,DEFPROC,ENDPROC,LEFT$.MID$, RIGHT$,TIME$,VAL,FN,STR$,LEN,MID$,EDIT,*EDIT,*SPOOL,*EXEC,READ, DATA,RESTORE
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.
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:
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.