Sinclair QL User Manual
Oglas
Oglas
•
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
User Guide
Introduction
Beginner's Guide
Reference Guide
Keywords
Concepts
Applications Software
QL Quill
QLAbacus
QLArchive
QL Easel
Information
•
User Guide
PLEASE READ THIS BEFORE UNPACKING
THESE PAGES
Your QL User GUide is supplied unbound, to avoid damage in transit and to make rapid updating easy. In addition to this packet containing the pages ot the GUide Itself, you should also find a ring binder and then divider cards packed with your QL.
Insert the dividers Into the binder first. The recommended order is as follows:
Position
Front
Tab Label
Introduction
Beginniner's Guide
Keywords
Concepts.
QL Quill
QL Abacus
QL Archive
QL Easel
Information
1367
Back
This will put the divider tabs in a logical order. If you wish, you may put the sections in a different orde( perhaps to put often used sections near the front; or even miss out sections you do not expect to use.
Now look through the pages to identify the various sections; each begins with a title page with the Sinclair logo at the top. The pages within each section will be packed in the correct orde( so be careful not to mix them up; the individual sections, howeve( may be in a different order to that shown above if a section or sections have recently been reprinted.
Once each section is placed in the binder as you like it, thiS sheet may be discarded; it does not form part of the GUide.
•
•
Sinclair Research has a policy of constant development and improvement of their products. Therefore, the right is reserved to change manuals, hardware, software and firmware at any time and without notice.
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
•
OL User GUide Second Edition
Published by Sinclair Research Limited 1984
25 Willis Road, Cambridge.
Edited by Stephen Berry (Sinclair Research Limited)
©Sinclair Research Limited
©Psion Limited
Printed and bound in Great Britain by
William Clowes Limited, Beccles and London
Designed and typeset by
Keywords, Manchester
No part of this User Guide may be reproduced in any form whatsoever without the written permission of Sinclair Research Limited.
QL, QLUB, QL Net, Qdos and OL Microdrive are trade marks of
Sinclair Research Limited.
Quill, Archive, Easel and Abacus are trade marks of Psion Limited
•
•
•
sinl::lair
QL
Introduction
©1984 SINCLAIR RESEARCH LIMITED
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844·351694
FAX: 01844 - 352554
•
When you unpack your QL computer you will find:
The QL computer
INTRODUCTION
TO THE QL
•
The QL User Guide
Two wallets
one of which contains:
QL Abacus
QL Archive
QL Easel
QL Quill
• and the other contains: four blank QL Microdrive cartridges.
Three plastic feet
A power supply
these can be fitted under the QL to tilt the keyboard for more comfortable typing. The pips in the top of the legs should be fitted into the holes in the rubber feet, twisting them to make them fit securely.
12/84
2
Introduction
An aerial lead
about two metres long with different connectors at either end. It is used for connecting your OL to your television's aerral socket.
A network lead
also about two metres long, with Identical connectors at either end. It IS used to connect your OL to other OLs so that data and messages can be sent between them.
A GUIDED
TOUR
On the back and sides of the computer there are a serres of connectors.
There are two slots on the right hand side of the computer - the two OL Microdrives.
The cartrrdges for these Microdrives are used for storing programs and data on the
OL. Next to each slot there IS a small light. When the light is on the Microdrrve is in use and the cartridge should not be removed. The yellow light on the front lefthand
Side indicates whether the OL is switched on.
~==;11~9111!f
II microdrive. slots
•
•
!
0
'=-~~;{¥~t~"'C"""~"'···I-~~~~~~~~~~~~~~~-§!~ power light Microdrive lights
On the right-hand end of the OL there is a slot covered by a plastic strip. This slot is for attaching up to six more OL Microdrives. ZX Microdrives are not suitable for use with the OL but blank Microdrive cartridges can be used on either machine.
•
12/84
•
Introduction
•
The connectors at the back of the computer are for attaching the following:
NET
NET
POWER -
connector for the OL Network connector for the OL Network power supply for the computer connection to a monochrome or colour monitor RGB
UHF
SER1
SER2 connection to the aerial socket of a television set
RS-232-C serial port
RS-232-C serial port control port for Joystick CTL1
CTL2
ROM control port for Joystick
OL ROM cartridge software (use reversed one to 10)
•
•
Peripheral expansion slot
~
F:t:;.,'-reset button
Mlcrodrrve expansion slot
The slot on the left-hand side of the OL is used for adding peripherals (equipment to expand the computer's capabilities) to the OL, One peripheral can be plugged directly
Into the expansion slot
The reset button IS on the right-hand end of the computer near the Mlcrodrlve expansion slot It IS used to 'reset' the OL to its Original 'switch on' state, Any programs in the machine will be lost If reset is pressed and sometimes data already recorded on Microdrlve cartridges can be corrupted, Use reset with caution and always remove Microdrive cartridges before doing so,
To make the computer operate, various connections have to be made:
Your OL power supply has two leads, One is fitted w'lth a small rectangular connector
With three holes in it The other is the mains lead and is supplied with bare ends to which a sUitable mains plug must be fitted,
SETIING UP
THE POWER
SUPPLY
Please do not connect the power supply lead to the computer until all other leads and peripherafs have been connected, Always connect the power supply lead to the computer last of all.
Connect the mains plug as follows:
• The blue wire goes to the terminal marked N or neutral, or coloured blue or black,
• The brown wire goes to the terminal marked L or live and coloured brown or red.
• The power supply is double insulated and does not need an earth connection.
• If you are using a fused plug, it must be fitted with a three amp fuse.
• Make sure all connections are sound.
If necessary, get someone with electrical experience to help you.
Although the OL will work once the power supply is connected, you will not be able to see what it is doing until you add a television set or a monitor.
A monitor has a screen like a television, but it cannot receive television signals. It usually has better resolution than a television set and so can display more text and is therefore more expensive.
A colour television or monitor will of course be required to make use of the OL:s colour display, but the computer will work perfectly well In black and white, representing colours as shades of grey.
THE DISPLAY
12/84 3
IntrodJction
Most television sets In current use will be suitable for the OL provided they are able to receive 625 line UHF transmissions, ie. BBC2 and Channel 4.
Locate the aerial socket at the back of your TV and remove the aerial cable that may be plugged into It If your set has more than one socket, use the one labelled UHF or 625. Plug in the OLs aerial lead. Use the end that looks similar to the onginal aerial plug, and plug the other end into the socket marked UHF on the back of the computer.
Plug the power supply into a mains socket and switch on. Remove any cartridges from the Microdrive slots and push the small power supply connector into the three pin plug marked POWER on the back of the OL. The yellow power light below the F5 key should now be glowing and your set up should look like thiS:
•
Television
UHF POWER
OL
When the computer has been on for a while, the case above the Microdrives will feel warm; this is quite normal. The OL has no on/off switch but can be turned off by unplugging the power supply connector. Remember that any program or data in the machine will be lost when it is turned off and should first be saved on a Microdrive cartridge (for details of how to do this see the Beginner's Guide and Concept sections).
If the OL is not going to be used for a while you should also switch the power supply off at the mai ns.
TUNING IN
The display signal to the television set is near channel 36. If your set has continuous tuning, tune to channel 36. If your television has push buttons, choose an unused button and tune this to the computer's signal. You may need to consult your dealer or the instruction manual to find out how to do this.
TV
Once you are correctly tuned in you should see the copyright screen.
•
•
4
Sinctai r Research
The Copyright Screen
The OL doesn't use television sound because it has its own internal loudspeaker. You
can turn the television volume down if you wish.
•
12/84
Introduction
•
•
•
A coloured pattern will appear aKer you switch on or reset the computer; this is the QL testing its memory. The pattern will disappear after a few seconds to be replaced by the copyright screen.
If you cannot get a picture at all, first check that your television can receive the normal broadcast stations. If it can then try the computer with another television set
If you get a fuzzy or indistinct picture check that you are tuned in correctly; It may be possible to pick up the computer's signal in more than one place in the tuning range.
Also check that the aerial lead is firmly plugged in, and that you are using the correct socket on your television set (if It has more than one).
It you wish to use a monitor instead of a television set. the connections will depend on whether it is colour or monochrome; details can be found in the Concepts section under the heading Monitor.
A monitor lead with a plug to fit the QLs RGB socket IS available from Sinclair Research. The order torm is in the Information section of this guide.
The QL needs to know if you are using a monitor or a television set. Press
[Ej]
tor a monitor or
I F21 for a television.
Microdrive 1 will run briefly and the red Mlcrodrive light will glow; the QL IS looking for programs to load and run (this can be ignored for now). The computer will start up and display its cursOr a flashing coloured square, and the computer is now ready to accept commands.
USING THE QL
KEYBOARD
Unlike previous Sinclair computers there is no single keyword entry on the QL. However, various keys and groups of keys have special meanings:
The ENTER key is used to indicate to the computer that you want it to do something.
Perhaps you have typed in a command and want the computer to execute it, or you may want to tell the computer that you have finished typing In data.
The keyboard has two SHIFT keys which perform the same function. Pressing SHIFT and an alphabetic key together will generate capital letters (upper case characters). On non-alphabetic keys SHIFT Will cause the upper engraved character to be generated.
For example:
I
SHIFT
I
&
[§]
will give %
Enter
Shift
Pressing the CAPS LOCK key once will force alphabetic keys to generate capital letters regardless of whether the SHIFT key is pressed. This will remain in effect until CAPS
LOCK is pressed again.
Caps Lock
Hold down the CTRL key and then press the
B key. The character to the leK ot the
Delete
cursor will disappear and the cursor will move to the left. Hold down CTRL and press the
G key. The cursor will not move; the character it was on will disappear and text to the right will move to fill the gap.
The QL screen may be divided into different areas, or windows, at will. Once you have switched on (or reset) and pressd F1 or F2, the screen will look like this:
THE SCREEN
o to 511 o to 511
2 & 2 o to
256 o o
Monitor Television
12/84 5
The long thin window at the bottom IS used to display commands typed Into the computer and Initially will display the flashing cursor. When the cursor is visible the OL is ready to accept commands or data; it disappears when the computer is busy.
ki you type, the cursor will move along the line showing where the next character to be typed will appear.
If the machine ever fails to respond correctly or you want to force a SuperBASIC program to stop, hold down the CTRL key and press the space bar.
The computer should then display its cursor If this doesn't work remove any M,crodrlve cartridges and then press reset.
The message Bad Line appearing In the command window means that the computer doesn't understand a command that you have typed In. Delete or correct the line uSing the cursor keys.
MICRODRIVES
The two OL Microdrlves are called mdv1_ on the left and mdv2_ on the right.
Cartridges must be placed correctly into the Microdrlves. Hold the cartridge by the ribbed plastic handle and remove it from its protective cover. The cartridge's name label, or the recess for its stick-on label, should face upwards.
•
•
6
Cartridges should always be treated with care. You should never turn the OL on or off with a cartridge in the Microdrives. Take care when Inserting or removing cartridges; wait until the Microdrive lights have gone out before removing the cartridge, be gentle but firm. Never touch the tape in the cartridge and always return the cartridge to its protective cover.
Before a blank cartridge can be used it must go through a process called formatting.
This process erases any data or programs on a cartridge so always be sure that all cartridges are clearly labelled with their contents and check that cartridges to be formatted contain no useful data. Instructions for formatting cartridges are conlained in the Information section.
All magnetic storage media including Microdrive cartridges eventually suffer from wear.
Hence it is strongly recommended that all important programs and data should be stored on at least two cartridges, that is 'backed up'. This means that If a cartridge is damaged and the data lost then at least part of the data can be recovered from the relevant back up cartridge. If you are continually adding data to a cartridge it must be backed up often; unless you do so you will lose everything that was added since the last backup if the main cartridge is damaged. Instructions for backing up cartridges are contained In the Information section.
STARTING WORK
There are several ways of using your computer and the User GUide. You can use ready made programs such as those supplied With the OL, or you can write your own programs in SuperBASIC.
To use the OL programs, first read the Introduction to the OL Programs later In this
Introduction and then the relevant section for each program concerned.
If you are a newcomer to computing and wish to write your own programs, you should read the Beginners Guide. If you are familiar With BASIC programming, you may prefer to read from Chapter 8 In the Beginners Guide From BASIC to SuperBASIC This chapter deSCribes the mafOr differences between BASICs you may already be familiar with and OL SuperBASIC. Alternatively, If you are feeling confident. the Keywords and
Concepts sections should be useful.
•
•
12/84
•
•
•
Introduction
If you have a problem using your OL or OL programs, then:
1 Refer to the appropriate sections in the OL User Guide.
2 Consider JOining the OL Users' Bureau for assistance on the OL programs. Full details of the services offered by OLUB and instructions for Joining are contained
In the Information sedon of the OL User Guide under the heading QLUB
3 Refer to books published about the OL if your problems persist and you think they may be caused by a fault In either your OL or in the OL program cartridges then refer to the Guarantee details in the Information section of the OL User Guide.
IF YOU HAVE
APROBLEM
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844·351694
FAX: 01844·352554
12.184
7
8
INTRODUCTION
TO THE QL
PROGRAMS
This Introduction outlines the four programs supplied with the QL and describes their common features.
The four programs are:
QL Quill - a word processor
QL Abacus - A spreadsheet
QL Archive - a database
QL Easel - a graphics program
Individual sections in this guide describe each of the four programs In detail. Don't Just read them - tryout the examples and experiment with each new idea.
MICRODRIVES
Before you use any of the QL programs you should make at least one backup on a blank cartridge and use this copy only. Keep he original program cartridge in a safe place, and use It only for making copies. Any accidents will not then cause permanent loss of your programs.
Each QL program has a bUilt In duplicating routine which IS used as follows:
• Place the master cartridge In Mlcrodrive 2
• Place the blank cartridge, or one containing nothing that you Wish to keep, In
Microdrlve 1.
Type l run mdv2 cLone
•
• Press the ENTER key and the screen will display the message
FORMAT mdv1_ type space to continue
Press the space bar only when you are sure that the cartridge contains nothing that you Wish to keep, as everything on it will be erased. The computer will tormat the cartridge and will then copy the program in sections, displaying the name of each one as it does so.
• Walt until the Microdrive lights go out betore removing the master cartridge from Microdrive 1.
LOADING
You should never use any of the original program cartridges except when making a copy onto a blank cartridge.
All the programs are loaded similarly. There are two ways of dOing this:
Without cartridges In the Microdrives, press reset. Place your copy of the program cartridge in Microdrive 1, and then press either F1 or F2 as prompted. Mlcrodrive 1 will automatically run and after a short pause a title display will appear on the screen to confirm that the program is being loaded. Once the program is loaded into the computer the program will start up by itself.
When you become more tamiliar with the programs and when using a printer or the network, you will sometimes find that commands need to be given to the computer before the programs start. You cannot switch off or reset the computer in this instance because your commands would be lost. Instead place the program cartridge in Mlcrodrive 1 and type lrun mdv1 boot press ENTER and loading will proceed as before.
In both cases the program will occasionally need to load extra intormation trom the
Microdrive so keep the program cartridge in the Mlcrodrive slot until the program has finished.
SCREEN LAYOUT
The control area at the top of the screen will guide you through each program by displaying the options that you will need most often and prompting you further if necessary. In many cases the program will suggest a suitable answer when it asks for information. Press ENTER to accept this suggestion or simply type in your own answer and the computer's suggestion will disappear
•
•
•
•
12/84
•
•
•
SHIFT & ~
SHIFT & ~
CTRL & ~
CTRL &
CTRL & i
CTRL & t
SHIFT & CTRL & ~
SHIFT & CTRL & ~
Introduction
Pressing F2 will remove this area and will make the central area larger Pressing F2 again will restore the control area.
The central area of the screen shows the intormatlon that you are working on, for example, the text at a document, the contents ot a card Index, a graph, or financial forecast It is shown in the style most sUitable for the particular application.
The bottom of the screen shows the input line where, for example, commands that you type In are displayed.
Below this is the
status area
which reports on the current state of work. It displays things like the name of the data or document on which you are working, how much unused memory remains, etc.
Three of the five function keys have the same meaning In all the OL programs. These are
FUNCTION KEYS
Key Function
F1
F2
F3 request help remove or restore the control area call up the commands for selection
The remaining two function keys are used for actions particular to each program.
The first option, displayed at the top left of the control area, indicates that help is available by pressing F1.
When you ask for HELP there will be a short pause before the display changes to show the Help information.
Help will suggest other topics for which help is available. Type the name of fhe tOPiC and press ENTER. You do not need to type in the whole name, just enough characters for it to be distinguished from the other topics. You can repeat this as many times as necessary.
Pressing ENTER without selecting a topic will take you out to the prevIous level. ESC will take you right out of HELP and back into the program.
Help is always available, provided that the program cartridge is in Microdrive 1.
Press
F1 and the most appropriate Help information will be displayed.
You can use the line editor to change or correct a line of text that you have typed in.
All the OL programs use the same line editor, but each program uses it In a way most suitable for that application. In OL Oill you use the line editor, for example, for editing the text in commands and OL Archive uses the editor extensively for editing database programs.
The line editor uses the four cursor keys, together with the CTRL and SHIFT keys.
HELP
THE LINE EDITOR
Keys Action
Move the cursor one character to the left
Move the cursor one character to the right
Move the cursor one word to the left
Move the cursor one word to the right
Delete the character to the left of the cursor
Delete the character under the cursor
Delete the line to the left of the cursor
Delete the line to the right of the cursor
Delete the word to the left of the cursor
Delete the word to the right of the cursor
12/84
9
IntroductIOn
10
The & symbol indicates that the first key should be held down while the second is pressed.
When SHIFT and CTRL are used together then hold them both down before pressing the cursor key.
MICRODRIVE USE
The program is loaded from the cartndge In Microdnve. You must always make sure that before using Help or uSing a print command that this cartndge is In Microdnve 1.
Otherwise you can remove the cartndge at any time.
Use a cartndge in Microdnve 2 - and in additional Mlcrodnves - for stonng information, for example, OUIII documents, Archive data files, etc.
FILE NAMES
Information can be stored on a cartndge In a 1ile: The file must be given a file name to distinguish it from others on the cartndge. Use a file name of not more than eight characters long, without spaces. It IS a good idea to use a name which descnbes the contents of a file; for Instance, 'sales' is obviously a better name for a file of sales figures than 1red:
File saving and loading will use a data cartridge which IS assumed to be In Mlcrodrive
2 unless a different dnve number IS given The simplest way of replying to a file name request is Just to type in the name by itself; for example: saLes which automatically accesses Mlcrodnve 2. If you wanted to access Mlcrodrive 1, you would type: mdv1 saLes
There is a third component of a file name which you do not usually see, because it is automatically added by the program. This is an extension, three letters long which identifies which program saved the file. The extensions used are:
OL Ouill
OL Abacus
OL Easel
OL Archive (data file)
OL Archive (program file)
OL Archive (screen layout)
~doc
_aba
_grf
_dbf
_prg or _pro
_scn
If ycu want to transfer information between programs, a special file is generated with the extension _exp (for export). All the programs will recognise this extension. More
Information on this process is contained In the Information section under the heading
QL Program-Import and Export.
You can direct pnnter output to a file instead of to a printer, so that you can pnnt the text later ThiS file has the extension _lis.
LISTING FILES
In all the programs except Archive you can request a list of the file names on a cartridge whenever a command needs a file name. ThiS is useful if you cannot remember the exact name that you gave to the file when you first saved It
Every time the program IS waiting for you to type In a file name, you have the following options:
Press ENTER to accept the name the program suggests
Type In the file name followed by ENTER
Press? followed by ENTER for a list of the files on Microdrive 2
If you type in a question mark ( and ENTER) instead of the file name, the program displays mdv2 suggesting that it should list the files on Microdrive 2. You can accept this suggestion or you can edit the drive specifier to refer to a different Microdnve (mdv1_) and then press ENTER to list the files. When the list IS complete the program asks you to type in the file name.
ArChive does not use this method. Instead there is a command (dir) which lists the files.
It allows you to type in mdv1_, mdv2_ and so on, to specify the drive for which the list of files IS needed.
12/84
•
•
•
•
•
•
•
Introductbn
In general, ESC cancels the current action and will restore you to a sensible pOint In the program. You can also use ESC to cancel any numbers or text that you have typed into the input line or abort a partially completed command.
ESCAPE
Data can be loaded and saved on other devices besides a Mlcrodrive. The device is specitied in the standard SuperBASIC way except that the device name is preceded by an underscore (_). See the devices entry in the Concept Reference Guide.
For example, to load and save via the network:
Before loading a OL program, each computer on the network must be given a station number Switch the computer on but do not insert a program cartridges; press F1 or
F2 when prompted.
To set the station number type the command NET followed by the station number of your choice. For example, to set the OL to station 5 type the command
NET 5 I ENTER I
Place the program cartridge in Microdnve 1 and load the program by typing
1 run mdv1_boot [ENTERI
Once the program is running, you can receive data sent along the network by typing the load command in the normal way. If the data was being sent by station 12, you would enter
LOAD net; 12
This must be done before station 12 starts sednlng.
To send data, type in the save command. Assuming you were sending to station 23, you would enter
SAVE net a 23
Station 23 must be ready to receive before you press ENTER
OTHER DEVICES
FOR SERVICE MANUALS
CONTACT;
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844 ·351694
FAX; 01844 . 352554
12184 11
•
•
•
© SINCLAIR RESEARCH LIMITED by Roy Atherton (Bulmershe College Computer Centre)
Eiinclair
QL
Beginner's Guide
Your OL should be connected to a monitor screen or TV set and switched on. Press a few keys, say abc, and the screen should appear as shown below The small flashing light is called the cursor.
CHAPTER
1
STARTING
COMPUTING
THE SCREEN
Monitor TeleviSion
If your screen does not look like this read the section entitled Introduction. This should enable you to solve any difficulties
The OL IS a versatile and powerful computer, so there are features of the keyboard which you do not need yet. For the present we will explain Just those Items which you need for this and the next six chapters.
THE KEYBOARD
This enables you to 'break' out of situations you do not like. For example; a line which you have decided to abandon something wrong which you do not understand a running program which has ceased to be of interest any other problem
Because BREAK is so powerful it has been made difficult to type accidentally
Hold down
I
CTRL
I
and then press
I
SPACE
I
If nothing was added or removed from a program while it was halted with BREAK then it can be restarted by typing:
CONTI NUE
BREAK
This is not a key but a small push button on the right hand side of the OL It is placed here deliberately, out of the way, because its effects are more dramatic than the break keys. If you cannot achieve what you need With the break keys then press the RESET button. This is almost the same as switching the computer off and on again. You get a clean re-start.
RESET
SHIFT
12/84
2
CAPITALS LOCK
There are two SHIFT keys because they are used frequently and need to be available to either hand.
Hold down one SHIFT key and type some letter keys. You will get upper case
(capital) letters.
Hold down one SHIFT key and type some other key, not a letter You will get a symbol in an upper position on the key.
Without a SHIFT key you get lower case (small) letters or a symbol In a lower position on a key.
•
SPACE BAR
This key works like a switch. Just press It once and only the letter keys will be 'locked' into a particular mode upper case or lower case.
Type some letter keys.
Type the CAPS LOCK key once
Type some letter keys.
You will see that the mode changes and remains until you type the CAPS LOCK key again.
•
RUBBING OUT
The long key at the bottom ot the keyboard gives spaces. This is a very important key in SuperBASIC as you will see In chapter two.
•
The left cursor together with the CTRL key acts like a rubber. You must hold down the
CfRL key while you press the cursor
key.
Each time you then both together the previous
character is deleted.
12/84
•
ENTER
•
The system needs to know when you have typed a complete message or instruction.
When you have typed something complete such as RUN you type the ENTER key to enter It Into the system for action.
Because this key is needed so often we have used a speCial symbol for It:
•
We shall use thiS for convenience, better presentation, and to save space. Test the ."
(ENTER) key by typing:
PRINT "Correct".."
If you made no mistakes the system will respond with:
Correct multiply
Q add c:J
[J
underscore
D quotes
D comma
D semi colon c=J backslash
0 left bracket c:J becomes equal to (used in LET)
D apostrophe
0
exclamation
0 ampersand
• D colon
D decimal point or full stop
0
dollar
[2]
right bracket
OTHER KEYBOARD
SYMBOLS OF
IMMEDIATE USE
SuperBASIC recognises commands (keywords) whether they are In upper or lower case.
For example the SuperBASIC command to clear the screen IS CLS and can be typed
In as:
CLS"'II
C ls"" c1S"'11
These are all correct and have the same effect. Some keywords are displayed partly in upper case to show allowed abbreviations. Where a keyword cannot be abbreviated it is displayed completely in upper case.
The usual use of quotes is to define a word or sentence - a string of characters. Try:
PRINT "Th; s works"..."
The computer will respond with:
This works
UPPER AND LOWER
CASE
USE OF QUOTES
3
12184
4
Starting Computing
The quotes are not printed but they indicate that some text is to be printed and they define exactly what it It is - everything between the opening and closing quote marks.
If you wish to use the quote symbol itself in a string of characters then the apostrophe symbol can be used instead. For example:
PRINT 'The quote symboL is
II I will work and will print
The quote symboL; s "
COMMON TYPING
ERRORS
The zero key IS with the other numeric digits at the top of the keyboard. and is slightly thinner.
The letter '0' key is amongst the other letters. Be careful to use the right symbol.
Similarly avoid confusion between one, amongst the digits, and the letter 'I' amongst the letters.
KEEP SHIFT DOWN
When using a SHIFT key hold It down while you type the other key so that the SHIFT key makes contact before the other key and also remains in contact until after the other key has lifted.
The same rule applies to the control CTRL and alternate ALT keys which are used in conjunction with others but you do not need those at present
Type the two simple Instructions:
CLS.II
PRINT 'HeLLo'."
Strictly speaking these constitute a computer program, however, it is the stored program that IS important in computing. The above instructions are executed instantly as you type
.." (ENTER).
Now type the program with line numbers:
10 CLS."
20 PRINT 'HELLO'."
This time nothing happens externally except that the program appears In the upper part of the screen. ThiS means that it is accepted as correct grammar or syntax. It conforms to the rules of SuperBASIC, but it has not yet been executed, merely stored. To make it work, type:
RUN_I
The distinction between direct commands for immediate action and a stored sequence of instructions is discussed in the next chapter. For the present you can experiment with the above ideas and two more: causes an internally stored program to be displayed (listed) on the screen or elsewhere.
causes an internally stored program to be deleted so that you can type in a NEW one.
•
•
•
12184
•
•
•
•
6.
7.
4.
5.
2.
3.
You can score a maximum of 16 points from the following test Check your score with the answers on page 105.
1.
In what circumstances might you use the BREAK sequence?
Where is the RESET button?
What is the effect of the RESET button?
Name two differences between a SHIFT key and the CAPS LOCK key.
How can you delete a wrong character WhiCh you have Just typed?
What is the purpose of the ENTER key?
What symbol do we use for the ENTER key?
What is the effect of the commands in questions 8 to 11
8.
C LS"'II
9.
RUN ..."
10.
LIST."
11.
NEW."
12.
Do keywords have the proper effect if you type them in lower case?
13.
What is the significance of the parts of keywords which the OL displays in upper case?
SELF TEST ON
CHAPTER 1
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL 01844·351694
FAX: 01844·352554
12184
5
6
CHAPTER 2
INSTRUCTING
THE
COMPUTER
Computers need to store data such as numbers. The storage can be imagined as pigeon holes.
D D D
Though you cannot see them, you do need to give names to particular pigeon holes.
Suppose you want to do the tollowing simple calculation.
A dog breeder has 9 dogs to feed for 28 days, each at the rate of one tin of 'Beefo per day. Make the computer print (display on the screen) the required number of tins
One way of solving thiS problem would require three pigeon holes for: oom~ct~ number of days total number of
tins
SuperBASIC allows you to choose sensible names for pigeon holes and you may choose as shown:
D days
D tins
D dogs
You can make the computer set up a pigeon hole, name it, and store a number in it with a single instruction or statement such' as:
LET dogs
=
9.-,
This will set up an internal pigeon hole, named dogs, and place in it the number 9 thus:
D dogs
The word LET has a special meaning to SuperBASIG It is called a keyword. SuperBASIC has many other keywords which you will see later. You must be careful about the space after LET and other keywords. Because SuperBASIC allows you to choose pigeon hole names with great freedom LETdogs would be a valid pigeon hole name.
The LET keyword is optional in SuperBASIC and because of this statements like:
LETdogs
=
9.." are valid. This would refer to a pigeon hole called LETdogs.
Just as, in English, names, numbers and keywords should be separated from each other by spaces if they are not separated by special characters.
Even if it were not necessary, a program line without proper spacing is bad st>"e.
Machines with small memory size may force programmers into it, but that is not a problem with the OL.
You can check that a pigeon hole exists internally by typing:
PRINT dogs.-,
The screen should display what IS in the pigeon hole:
9
Again, be careful to put a space after PRINT.
12/84
•
•
•
•
•
•
•
To solve the problem we can write a program which IS a sequence of instrucllons or statements. You can now understand the first two:
LET dogs
LET days
=
9."
= 28."
These cause two pigeon holes to be set up, named, and given numbers or values.
2.
1.
The next instruction must perform a multiplication, for which the computer's symbol is
*, and place the result in a new pigeon hole called tins thus:
LET t; ns
= dogs
*
days,,11
The computer gets the values, 9 and 28, from the two pigeon holes named dogs and days.
The number 9 is multiplied by 28.
3.
4.
A new pigeon hole IS set up and named tins.
The result of the multiplication becomes the value in the pigeon hole named tins.
All this may seem elaborate but you need to understand the Ideas, which are very important.
The only remaining task is to make the computer print the result which can be done by typing:
PRINT tins"l1 which will cause the output:
252 to be displayed on the screen.
In summary, the program:
LET dogs
=
9..,
LET days
LET tins
= 28..,
= dogs
* days." tins.1I
causes the internal effects best imagined as three named pigeon holes containing numbers: x d a y s 0 and the output on the screen:
252
Of course, you could achieve this result more easily with a calculator or a pencil and paper You could do it quickly with the OL by typing:
PRINT 9 * 28"11
1.
2.
which would give the answer on the screen. However, the ideas we have discussed are the essential starting points of programming in SuperBASIC. They are so essential that they occur in many computer languages and have been given special names.
Names such as dogs, days and tins are called identifiers.
A single instruction such as:
LET dogs
=
9." is called a statement:
3.
The arrangement of name and associated pigeon hole is called a variable. The execution of the above statement stores the value 9 in the pigeon hole 'identified' by the identifier dogs.
12/84
Instructing theCcmputer
7
8
Instructing llle Computer
A statement such as:
LET dogs
=
9.." is an Instruction for a highly dynamic Internal process but the printed text is static and it uses the = sign borrowed from mathematics. It is better to think or say (but not type):
LET dogs become 9 and to think of the process having a right to left direction (do not type this): dogs <?
9
The use of
= in a LET statement is not the same as the use of
For example, if another dog turns up you may wish to write: in mathematics.
LET dogs:: dogs + 1.11
Mathematically, this is not very sensible but in terms of computer operations it is simple.
If the value of dogs before the operation was 9 then the value after the operation would be 10. Test this by typing:
LET dog s = 9.."
PRINT dogs.1I
LET dogs = dogs + 1.."
PRINT dogs.."
The output should be:
9
10 proving that the final value in the pigeon hole is as shown: d09S[:]
A good way to understand what is happening to the pigeon holes, or variables, is to do what is called a 'dry run: You simply examine each instruction in turn and write down the values which result from each instruction to show how the pigeon holes are set up and given values, and how they retain their values as the program is executed.
LET dogs = 9.."
LET days = 28.."
LET tins:: dogs
PRINT tins_II
*
days.11
The output should be:
252
You may notice that so far a variable name has always been used first on the left hand side of a LET statement Once the pigeon hole IS set up and has a value, the corresponding variable name can be used on the right hand side of a LET statement.
Now suppose you wish to encourage a small child to save money. You might give two bars of chocolate for every pound saved. Suppose you try to compute this as follows:
LET bars:: pounds
PRINT bars.1I
*
2.,
You cannot do a dry run as the program stands because you do not know how many pounds have been saved.
We have made a deliberate error here in using pounds on the right of a LET statement without it having been set up and given some value. Your OL will search internally for the variable pounds. It will not find it so it concludes that there is an error in the program and gives an error message. If we had tried to print out the value of pounds, the OL would have printed a
* to indicate that pounds was undefined, We say that the variable
pounds has not been initialised (given an initial value). The program works properly if you do this first:
12/84
•
•
•
•
•
•
•
LET pounds
=
7"1'
LET bars
= pounds * 2"11
The program works properly and gives the output
14
Typing statements without line numbers may produce the desired result but there are two reasons why this method, as used so far, is not satisfactory except as a first introduction.
1.
The program can only execute as fast as you can type, This is not very Impressive for a machine that can do millions of operations per second.
2.
The individual instructions are not stored after execution so you cannot run the program again or correct an error without re-typing the whole thing.
Charles Babbage, a nineteenth century computer pioneer, knew that a successful computer needed to store instructions as well as data in internal pigeon holes. These
Instructions would then be executed rapidly in sequence without further human intervention.
The program instructions will be stored but not executed if you use line numbers, Try this:
10 LET price
=
15.."
20 LET pens = 7.."
30 LET cost = pri ce
40 PRINT cost_II
*
pens-'II
Nothing happens externally yet, but the whole program IS stored Internally. You make it work by typing:
ASTORED
PROGRAM
Instructing the Computer and the output
105 should appear,
The advantage of this arrangement is that you can edit or add to the program with minimal extra typing,
Later, you will see the full editing features of SuperBASIC but even at this early stage you can do three things easily: replace a line insert a new line delete a line
EDITING A
PROGRAM
Replace a line
Suppose you wish to alter the previous program because the price has changed to
20p for a pen. Simply re-type line 10.
10 LET price = 20.."
This line will replace the previous line 10. Assuming the other lines are still stored, test the program by typing:
RUN., and the new answer, 140, should appear.
Insert a new line
Suppose you wish to insert a line just before the last one, to print the words Total Cost:
This situation often arises so we usually choose line numbers 10, 20, 30 ... to allow space to Insert extra lines.
To put In the extra line type:
35 PRINT "Total Cost""11
9
12/84
Instructing the Computer and it will be Inserted just before line 40. The system allows line numbers in the range
1 to 32768 to allow plenty of flexibility In choosing them. It is difficult to be quite sure in advance what changes may be needed.
Now type:
FOR SERVICE MANUALS
CONTACT: and the new output should be:
Tota L cost
140
MAURITRON TECHNICAL SERVICES www.maurilron.co.Uk
TEl: 01844 - 351694
FAX: 01844 - 352554
Delete line
You can delete line 35 by typing:
•
II IS as though an empty line has replaced the previous one.
OUTPUT-PRINT
Note how useful the PRINT statement is You can PRINT text by using quotes or apostrophes:
PRINT "Chocolate bars".11
You can print the values of variables (contents of pigeon holes) by typing statements such as:
PRINT bars." without using quotes.
You will see later how very versatile the PRINT statement can be in SuperBASIG. It Will enable you to place text or other output on the screen exactly where you want it. But for the present these two faCilities are useful enough: printing of text printing values of variables (contents of pigeon holes).
INPUT- INPUT, READ
A carpet-making machine needs wool as input. It then makes carpets according to the
AND DATA
current design.
design wool
,
1
Carpet
Machine
I'.
carpets program
1
----,---,--,--';>
~
?
input data
~ output data
"
If the wool is changed you may get a different carpet.
The same sort of relations exist in a computer.
However, if the data is input into pigeon holes by means of LET there are two disadvantages when you get beyond very trivial programs: writing LET statements is laborious changing such input is also laborious
You can arrange for data to be given to a program as it runs. The INPUT statement will cause the program to pause and wait for you to type in something at the keyboard.
First type: so that the previous stored program (if it is still there) will be erased ready for this new one. Now type:
10 LET price
=
15."
20 PRINT "How many pens?"
.11
30 INPUT pens ."
40 LET cost
=
prj ce
50 PRINT cost ."
* pens ."
RUN ."
12/84
10
•
•
•
Instructing the Computer
•
••
•
The program pauses at line 30 and you should type the number of pens you want, say
Do not forget the ENTER key. The output will be:
60
The INPUT statement needs a variable name so that the system knows where to put the data which comes in from your typing at the keyboard. The effect of line 30 with your typing is the same as a LET statements effect. It IS more convenient for some purposes when Interaction between computer and user is desirable. However, the LET statement and the INPUT statement are useful only for modest amounts of data. We need something else to handle larger amounts at data without pauses in the execution of the program.
SuperBASIC, like most BASICs, provides another method of Input known as READing from DATA statements. We can retype the above program In a new form to give the same effects without any pauses. Try this:
NEW.."
10 READ price, pens.."
20 LET cost
= price
*
penS_Ill
30 PRINT cosh",
40 DATA 15,4.."
RUN_II
The output should be:
60 as before.
Each time the program is run, SuperBASIC needs to be told where to start reading DATA from. This can either be done by typing RESTORE followed by the DATA line number or by typing CLEAR. Both these commands can also be inserted at the start of the programs.
When line 10 is executed the system searches the program for a DATA statement. It then uses the values ,n the DATA statement for the variables In the READ statement in exactly the same order. We usually place DATA statements at the end of a program. They are used by the program but they are not executed in the sense that every other line is executed In turn. DATA statements can go anywhere In a program but they are best at the end, out of the way. Think of them as necessary to, but not really part of, the active program. The rules about READ and DATA are as follows:
1.
All DATA statements are considered to be a single long sequence of Items. So far these items have been numbers but they could be words or letters.
2.
3.
Every time a READ statement is executed the necessary Items are copied from the DATA statement into the variables named in the READ statement.
The system keeps track of which items have been READ by means of an internal record. If a program attempts to READ more items than exist in all the DATA statements an error will be signalled.
You have used names for 'pigeon holes' such as like these according to certain rules: dogs, bars.
You may choose words
A name cannot include spaces.
A name must start with a letter.
A name must be made up from letters, digits, $, %, _(underscore)
The symbols $, % have special purposes, to be explained later, but you can use the underscore to make names such as: dog_food month_wage_total more readable.
IDENTIFIERS
(NAMES)
12/84
11
12
SuperBASIC does not distinguish between upper and lower case letters, so names like TINS and tins are the same.
The maximum number of characters In a name IS 255.
Names which are constructed according to these rules are called identifiers. Identifiers are used for other purposes in SuperBASIC and you need to understand them The rules allow great freedom in choice of names so you can make your programs easier to understand. Names like total, count, pens are more helpful than names like Z,
R
Q.
SELF TEST ON
CHAPTER 2
3.
4.
5.
You can score a maximum of on page 106.
21 pOints from this test. Check your score with the answers
1.
2.
How should you Imagine an Internal number store?
State two ways of storing a value ,n an internal 'pigeon hole' to be created. (two pOints)
How can you find out the value of an internal 'pigeon hole?
What IS the usual technrcal name for a 'pigeon hole?
When does a pigeon hole get its first value?
6.
7.
A variable is so called because ItS value can vary as a program IS executed. What is the usual way of causing such a change?
The = sign in a LET statement does not mean equals' as In mathematics. What does it mean?
8.
What happens when you ENTER an un-numbered statement?
9.
What happens when you ENTER a numbered statement?
10.
What is fhe purpose of quotes in a PRINT statement?
11.
What happens when you do not use quotes In a PRINT statement?
12.
What does an INPUT statement do which a LET statement does not?
13.
What type of program statement is never executed?
14.
What IS the purpose of a DATA statement?
15.
What IS another word for the name of a pigeon hole (or variable)?
16.
Write down three valid identifiers which use letters, letters and digits, letters and underscore (three points)
17.
Why is the space bar especially important in SuperBASIC?
18.
Why are freely chosen identifiers important in programming?
I.
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www,mauritron,co,uk
TEL: 01844 - 351694
FAX: 01844 - 352554
•
12/84
•
•
•
7.
6.
3.
4.
5
1.
2.
Carry out a dry run to show the values of all variables as each line of fhe following program is executed:
10 LET hours
20 LET
30 LET
=
40.", rate = 3"111 wage
= hours
* rate"'ll
40 PRINT hours, rate, wage."
Write and test a program, similar to that of problem 1, which computes the area of a carpet which IS 3 metres In width and 4 metres in length. Use the variable names: width, length, area.
Re-wrlte the program of problem 1 so that It uses two INPUT statements Instead of LET statements.
Re-write the program of problem 1 so that the input data (40 and 3) appears in a DATA statement instead of a LET statement.
Re-write the program of problem 2 using a different method of data input. Use
READ and DATA If you originally used LET and vice-versa.
Bill and Ben agree to have a gamble. Each will take out of his wallet all the pound notes and give them to the other. Write a program to simulate this entirely with
LET and PRINT statements. Use a third person, Sue, to hold Bill's money while he accepts Ben's.
Re-write the program of problem 6 so that a DATA statement holds the two numbers to be exchanged.
PROBLEMS ON
CHAPTER 2
12/84 13
14
CHAPTER
3
DRAWING ON
THE SCREEN
In order to use either a television set or monitor with the OL, 'eNO different screen modes are available. MODE 8 permits eight colour displays with a graphics resolution of 256 by 256 pixels and large characters for display on a television set. MODE 4 allows four colours with a resolution of 512 by 256 pixels and a maximum of eighty character lines for which a monitor must be used for successful display However it would be unfortunate if a program was wntten to draw circles or squares in one mode and produced ellipses or rectangles in another mode (as some systems do). We therefore provide a system of scale graphics which avoids these problems. You simply choose a vertical scale and work to it. The other type of graphics (pixel oriented) is also available and is described fully in a later chapter.
Suppose, for example, that we choose a vertical scale of 100 and we wish to draw a line from position (50,60) to position (70,80).
100
L
(70 across.
80 uP)
(50 across, 60 up)
•
• a
Scale Graphics
A
COLOURED LINE
We need to specify three things
PAPER (background colour)
INK (drawing colour)
LINE (start and end POints)
The following program will draw a line as shown in the above figure In red (colour code
2) on a white (colour code 7) background.
NEW
41111
10 PAPER 7 : CLS .."
ZOINKZ."
30 LINE 50,60
RUN
.11
TO 70,80."
In line 10 the paper colour is selected first but it only comes into effect with a further command, such as CLS, meaning clear the screen to the current paper colour.
MODES AND
COLOURS
So far it does not matter which screen mode you are using but the range of colours is affected by the choice of mode
MODE 8 allows eight basic colours
MODE 4 allows four basic colours
Colours have codes as described below.
•
•
12f84
Drawing on the Screen
•
•
•
Code
8 colour
Effect
0
1 black blue red magenta
2
3
4 green cyan yellow white
5
6
7
4 colour black black red red green green white white
For example, INK 3 would give magenta In MODE 8 and red in MODE 4.
We will explain in a later chapter how the basic colours can be 'mixed' In various ways to produce a startling range of colours, shades and textures.
You can get some interesting effects with random numbers which can be generated with the RND function. For example:
PRINT RND(1 TO 6) .." will print a whole number in the range 1 to 6, like throwing an ordinary six-sided dice.
The following program will Illustrate thiS:
NEW"'II
10 LET die
20 PRINT
= RND(1 TO 6) .." die.'
RUN "'11
If you run the program several times you will get different numbers.
You can get random whole numbers in any range you like. For example:
RND(O TO 100) will produce a number which can be used In scale graphics. You can re-write the line program so that it produces a random colour. Where the range of random numbers starts from zero you can omit the first number and write:
RND(100)
NEW"'II
10 PAPER 7 : CLS .."
20 INK RND(S) .."
30 LINE 50,60 TO RND(10OJ,
RUN "'11
RND(100) .."
ThiS produces a line starting somewhere near the centre of the screen and finishing at some random point. The range of possible colours depends on which mode is selected. You will find that a range of numbers 'something TO something' occurs often in SuperBASIC.
RANDOM EFFECTS
The part of the screen in which you have drawn lines and create other output is called a window. Later you will see how you can change the size and position of a window or create other windows. For the present we shail be content to draw a border round the current window. The smallest area of light or colour you can plot on the screen is called a pixel. In mode 8, called low resolution mode, there are 256 possible pixel positions across the screen and 256 down. In mode 4, called high resolution mode, there are 512 pixels across the screen and 256 down. Thus the size of a pixel depends on the mode.
You can make a border round the inside edge of a window by typing for example:
BORDER 4,2 .."
This will create a border 4 pixels wide in colour red (code 2). The effective size of the window is reduced by the border This means that any subsequent printing or graphics will automatically fit Within the new Window size. The only exception to this is a further border which will overwrite the existing one.
BORDERS
15
12/84
Drawing on the Screen
ASIMPLE LOOP
Computers can do things very qUickly but it would not be possible to exploit this great power If every action had to be written as an Instruction. A building foreman has a similar problem. If he wants a workman to lay a hundred paving stones that is roughly what he says. He does not give a hundred separate Instructions.
A traditional way of achieving looping or repetition In BASIC is to use a GO TO (or they are the same) statement as follows:
GOTO,
NEW"II
10 PAPER 6 : CLS .."
20 BORDER 1,2 ..'
30 INK RND(5) ..',
40 LINE 50,60 TO RNDC10OJ, RND(100) ..,
50 GOTO 0 ..",
RUN
.11
You may prefer not to type in this program because SuperBASIC allows a better way of dOing repetition. Note certain things about each line.
~~ ~~~p~a~rt_'
-
~~=t
=-re-pe_at_ed'
I" - - - - - - - - - - ' - 1
~~ L~han~e
part_--: repeated.J
'I
~ntrols pr6gr~~~=
50
You can re-write the above program by omitting the GOTO statement and, instead, putting
REPeat and END REPeat around the part to be repeated.
NEW"II
10 PAPER 6 : CLS .."
20 BORDER 1 ,2 .."
30 REPEAT star .."
40
50
INK RND(5) .."
LINE 50,60 TO RND(100), RND(100) .."
60 END REPEAT
RUN
"It
star .."
We have give the
repeat structure
a name,
star.
The structure consists of the two lines:
REPeat star
END REPeat star and what lies between them is called the content of the structure The use of upper case letters Indicates that REP IS a valid abbreviation of REPeal.
This program should produce coloured lines Indefinitely to make a star as shown in the figure below.
•
•
•
16
The STAR program
You can stop it by pressing the break keys:
Hold down
I
CTRL
I and then press rl
-~S"'P"'1>."C"E~----'
12/84
•
Drawing on the Screen
•
•
SuperBASIC provides a consistent and versatile method of stopping repelltive processes.
Imagine running round and round Inside the program activating statements. How can you escape? The answer IS to use an EXIT statement. But there must be some reason for escaping. You might extend the choice of line colours by typing as an amendment to the program (do not type NEW)
40 INK RND (0 TO 6) .." so that if RND produces 6 the ink is the same colour as the paper and you will not see it. This could be the reason for terminating the repetition. We can re-arrange the program as follows:
NEW .....
10 PAPER 6 : CLS .."
20 BORDER 1 ,2 .."
30 REPeat star
"'11
40
50
LET cotour
IF cotour
=
RND(6) .."
=
6 THEN EXIT star .."
60 INK colour .."
70 LINE 50,60 TO RND(100), RND(100l .."
80 END REPeat star .."
The important thing to nOle here is that the program continues until colour becomes
6.
Control then escapes from the loop to the point Just after line 80.
Since there are no program lines after 80 the program stops.
Another important concept has been Introduced. It is the idea of a decIsion.
IF colour = 6 THEN EXIT star
This is another very useful structure because it is a choice of doing something or not; we call It a simple binary decision. Its general form is: fF condition THEN statement(s)
You will see later how the two concepts of repetition (or looping) and decision-making
(or selection) are the main structures for program control. You can stop the program by pressing the break keys: hold down CTRL and then press the space bar.
•
2
3.
1.
4.
You can score a maximum of 13 points from the following test. Check your score with the answers on page 107.
What IS a pixel?
How many pixels fit across the screen In the low resolution mode?
How many pixels fit from bottom to top in low resolution mode?
What are the two numbers which determine the 'address' or position of a graphics point on the screen?
FOR SERVICE MANUALS
How many colours are available in the low resolution mode?
CONTACT:
5
SELF TEST ON
CHAPTER 3
6.
Name the keywords which do the following: i.
draw a line ii.
select a colour for drawing iii.
select a background colour iv.
draw a border (5 points)
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
7.
8.
9.
What are the statements which open and close the REPeal loop?
When does an executing REPeat loop terminate?
Why do loops In SuperBASIC have names?
17
12/84
18
PROBLEMS ON
1.
CHAPTER 3
2.
3.
4.
5.
6.
Write a program to draw straight lines all over the screen. The lines should be of random length and direction. Each should start where the previous one finished and each should have a randomly chosen colour.
Write a program to draw lines randomly with the restriction that each line has a random start on the lett hand edge of the screen.
Write a program to draw lines randomly with the restriction that the lines start at the same point on the bottom edge of the screen
Write a program to produce Imes of random length, starting points and colour.
All lines must be horizontal.
As problem 4 but make the lines vertical.
Write a program to produce a square 'spiral' In such a way that each line makes a random colour
HINT First find the co-ordinates of some of the corners, then put them In groups of four. You should discover a pattern.
•
•
12/84
•
•
•
•
•
CHAPTER 4
CHARACTERS
AND
STRINGS
Teachers sometimes wish to assess the reading ability needed for particular books or classroom materials. Various tests are used and some of these compute the average lengths of words and sentences. We will introduce ideas about handling words or character strings by examining simple approaches to finding average word lengths.
We are talking about sequences of leners, digits or other symbols which mayor may nof be words. That is why the term character string' has been Invented. It is usually abbreviated to string. Strings are handled in ways similar to number handling but, of course, we do not do the same operations on them. We do not multiply or subtract strings.
We join them, separate them, search them and generally manipulate them as we need.
You can create pigeon holes for strings. You can put character strings into pigeon holes and use the Information Just as you do with numbers. If you Intend to store (not all at once) words such as:
FIRST SECOND THIRD and
JANUARY FEBRUARY MARCH you may choose to name two pigeon holes:
NAMES AND
PIGEON HOLES FOR
STRINGS
weekday$ D m o n t h $ D
Notice the dollar sign. Pigeon holes for strings are internally different from those for numbers and SuperBASIC needs to know which is which. All names of string pigeon holes must end with $. OtherWise the rules for choosing names are the same as the rules for the names of numeric pigeon holes.
You may pronounce: weekday$ as weekdaydollar month$ as monthdollar
The LET statement works in the same way as for numbers. If you type:
LET weekdayS
=
"FIRST"
" I I an internal pigeon hole, named weekday$, will be set up with the value FIRST in it thus: weekdaY$1 FIRST I
The quote marks are not stored. They are used in the LET statement to make it absolutely clear what is to be stored in the pigeon hole. You can check by typing:
PRINT weekday$ .." and the screen should display what is in the pigeon hole:
FIRST
You can use a pair of apostrophes instead of a pair of quote marks.
19 12/84
~)f )
Characters and Strings
LENGTHS OF
STRINGS
SuperBASIC makes It easy to find the length or number of characters of any string. You simply write, for example:
PRINT LENlweekday$) ••
If the pigeon hole, weekday$.
contains FIRST the number 5 will be displayed. You can see the effect in a simple program
NEW .."
10 LET weekday$ = "FIRST",-"
20 PRINT LEN(weekday$) .."
RUN
"'11
The screen should display:
5
LEN is a keyword of SuperBASIC.
An alternative method of achieving the same result uses both a string pigeon hole and a numeric pigeon hole.
NEW...."
10 LET weekday$ :::: IIFIRST".II
20 LET Length; LENlweekday$) .."
30 PRINT tength.."
RUN.-II
The screen should display:
5 as before, and two internal pigeon holes contain the values shown:
D weekdayS
I
FIRST
I
length
Let us return to the problem of average lengths of words.
Write a program to find the average length of the three words:
FIRST, OF, FEBRUARY
PROGRAM DESIGN
When problems get beyond what you regard as very trivial, It is a good idea to construct a program design before writing the program itself.
3.
4.
1.
Store the three words in pigeon holes.
2.
Compute the lengths and store them.
Compute the average.
Print the result.
NEW'-II
10 LET weekday$ :::: "FIRST II "II
20 LET word$ :::: "0F
II
'-1I
30
LET month$ :: IIFEBRUARY"'-II
40 LET length1 LENlweekday$) ...
50 LET length2 ; LEN (word$) .."
60 LET Length3 ; LENlmonth$) .."
70 LET sum; length1 + Length2 + Length3.."
80 LET ave rage:::: sum/3.11
90 PRINT average,-"
RUN'-II
The symbol! means divided by.
The output or result of running the program is simply:
5 •
•
•
•
12/84
•
• and there are eight Internal pigeon holes Involved: weekday$
EJ length1 word$ month$
~
length2
IFEBRUARYI length3 sum average
D
D
D
G
D
If you think that IS a lot of fuss for a fairly simple problem you can certainly shorten it.
The shortest version would be a single line but It would be less easy to read. A reasonable compromise uses the symbol & which stands for the operation:
Join
Now type: two strings
NEW
10 LET weekday$ ;;; "FIRST".II
20 LET word$ ;;; "OF".IIL
30 LET month$
=
"FEBRUARY"""
40 LET phrase$
50 LET length
= weekday$ & word$ & month$.."
=
LEN(phrase$)."
60 PRINT length/3."
RUN"II
The output is 5 as before but there are some different internal effects: weekday$ FIRST
G length
• word$ OF month FEBRUARY phrase$ FIRSmFFEBRUARY
There is one more reasonable simplification which is to use READ and DATA Instead of the first three LET statements. Type:
NEW.II
10 READ weekday$, word$, month$.."
20 LET phrase$
30 LET length
= weekday$ & word$ & month$."
=
LEN(phrase$)."
40 PRINT length/3."
50 DATA "FIRST","OF","FEBRUARY""II
RUN"II
The internal effects of this version are exactly the same as those of the prevIous one.
READ causes the setting up of internal pigeon holes wilh values in them In a similar way to LET.
12/84
Characters and Strings
21
22
IDENTIFIERS AND
STRING VARIABLES
Names of pigeon holes, such as: weekday$ word$ month$ phrase$ are called string identifiers. The dollar signs Imply that the pigeon holes are for character strings. The dollar must always be at the end.
Pigeon holes of this kind are called string variables because they contain only character strings which may vary as a program runs.
The contents of such pigeon holes are called values. Thus words like 'FIRST' and 'OF' may be values of string variables named weekday$ and +word$.
RANDOM
CHARACTERS
You can use character codes (see Concept Reference GUide) to generate random letters.
The upper case letters A to Z have the codes 65 to 90. The function CHR$ converts these codes into letters. The following program will print a letter B.
NEW.II
10 LET Lettereode ; 66."
20 PRINT CHR$(Lettereode) ..'
RUN..,
The following program will generate trios of letters A, B, or C until the word CAB is spelled accidentally.
NEW.II
10 REPeat taxi
20 LET first$ ; CHR$(RND(65 TO 67))
30 LET seeond$; CHR$(RND(65 TO 67))
40 LET third$; CHR$(RND(65 TO 67))
50 LET word$ ; fi rst$ & seeond$ & thi rd$
60 PRINT
1 word$
1
70 IF word$; "CAB" THEN EXIT taxi
80 END REPeat taxi
Random characters, like random numbers or random points are useful for learning to program. You can easily get interesting effects for program examples and exercises
Note the effect the 1 . . 1 have on the spacing
at
the output
SELF TEST ON
CHAPTER 4
7.
8.
5.
6.
You can score a maximum of 10 points from the following test Check your score with the answers on page 107.
1.
What is a character string?
2.
What is the usual abbreviation of the term, character string?
3.
4.
What distinguishes the name of a string variable?
How do some people pronounce a word such as wordS?
What keyword is used to find the number of characters in a string?
What symbol is used to join two strings?
Spaces can be part of a string. How are the limits of a string defined?
When a statement such as:
LET meatS = "steak" is executed, are the quotes stored?
9.
10.
What function will turn a suitable code number into a letter"
How can you generate random upper case letters?
•
•
•
12/84
•
•
•
1
3.
2.
Store the words 'Good' and day' In two separate variables. Use a LET statement to Join the values of the two variables In a third variable. Print the result.
Store the following words in four separate pigeon holes: light Let be there
Join the words to make a sentence adding spaces and a full stop. Store the whole sentence in a vanable, sent$, and print the sentence and the total number of characters it contains.
Write a program which uses the keywords:
CHR$RNO(65 TO 90)) to generate one hundred random three letter words. See if you have accidentally generated any real English words. Test the effects of: a) ; at the end of a PRINT statement.
b) ! on either side of item printed .
PROBLEMS ON
CHAPTER 4
FOR SERVICE MANUALS
CONTACT;
MAURITFlON TECHNICAL SERVICES www.mllJllttllfi.CO.uk
TEl.. 01 M-I ' 35 1 694
FAX: 01M4" 352554
12/84
23
CHAPTER
KNOWN
GOOD
PRACTICE
5
You have already begun to work effectively with short programs. You may have found the following practices are helpful:
1.
Use of lower case for Identifiers: names of variables (pigeon holes) or repeat structures, etc.
2.
Indenting of statements to show the content of a repeat structure.
3.
Well chosen identifiers reflecting what a variable or repeat structure is used for.
4.
Editing a program by: replaCing a line inserting a line deleting a line
PROGRAMS AS
EXAMPLES
You have reached the stage where it is helpful to be able to study programs to learn from them and to try to understand what they do. The mechanics of actually running them should now be well understood and in the following chapters we will dispense with the constant repetition of:
NEW before each program
.", at the end of each line
RUN to start each program
You will understand that you should use all these features when you Wish to enter and run a program. But their omission in the text will enable you to see the other details more clearly as you try to imagine what the program will do when it runs.
If we dispense with the above details we may use and understand programs more easily
Without the technical clutter. For example, the following program generates random upper case letters until a Z appears. It does not show the words NEW or RUN or the ENTER symbol but you still need to use these.
10 REPeat letters
20 LET lettereode
30 eap$ =
= RND(65 TO 90)
CHR$(lettereode)
40
50
PRINT eap$
IF eap$ = "Z" THEN EXIT letters
60 END REPeat letters
In thiS and subsequent chapters programs will be shown without ENTER symbols. Dlfect commands will also be shown without ENTER symbols. But you must use these keys as usual. You must also remember to use NEW and RUN as necessary.
AUTOMATIC LINE
NUMBERING
It is tedious to enter line numbers manually. Instead you can type:
AUTO before you start programming and the OL will reply with a line number:
100
Continue typing lines unlll you have finished your program when the screen will show:
100 PRINT "F; rst"
110 PRINT IlSecond"
120 PRINT "End"
To finish the automatic production of line numbers use the BREAK sequence:
Hold down the CTRL and press the SPACE bar. This will produce the message:
130 not complete and line 130 will not be Included in your program.
12/84
•
•
•
•
•
Known Good Practice
If you make a mistake which does not cause a break from automatic numberrng, you can continue and EDIT the line later. If you want to start at some particular line number, say 600, and use an Increment other than 10 you can type, for an Increment of 5:
AUTO 600,5 lines will then be numbered 600, 605, 610, etc
To cancel AUTO, press CTRL and the space bar at the same time,
To edit a line simply type EDIT followed by the line number for example:
EDIT 110
The line will then be displayed with the cursor at the end thus:
110 PRINT "Second"
You can move the cursor using:
<?
"'?
one place left one place right
To delete a character to the left use:
CTRL with <?
To delete the character In the cursor position type:
CTR L with "'?
and the character to the right of the cursor will move up to close the gap,
EDITING ALINE
Before using a new Microdrive cartridge it must be formatted. Follow the instructions in the Introduction The choice of name for the cartridge follows the same rules as
SuperBASIC identlfers, etc. but limited to only 10 characters. It IS a good Idea to wrrte the name of the cartridge on the cartridge itself using one of the supplied sticky labels,
You should always keep at least one back-up copy of any program or data. Follow the instructions in the Information section of the User Guide.
USING MICRODRIVE
CARTRIDGES
•
The following program sets borders, 8 pixels wide, in red (code 2), In three windows designated #0, #1, #2.
100 REMark Border
110 FOR k = 0 TO 2 : BORDER #k,8,2
You can save it on a microdrive by Inserting a cartridge and typing:
SAVE mdv1 bord
The program will be saved in a Microdrrve file called bard,
SAVING PROGRAMS
If you want to know what programs or data files are on a particular cartridge place it in Microdrive 1 and type: orR mdv1
The directory will be displayed on the screen, if the cartrrdge is in Microdrrve 2 then type Instead:
OrR mdv2
CHECKING A
CARTRIDGE
25
12/84
26
Known Good Practice
COPYING
PROGRAMS AND
FILES
Once a program IS stored as a file on a M,crodrlve cartridge It can be copied to other files. This Is one way of making a backup copy of a Mlcrodrlve cartridge. You might copy all the previous programs, and similar commands for other programs, onto another cartridge In Mlcrodrive 2 by typing:
COPY mdv1 bord TO mdv2 bord
DELETING A
CARTRIDGE FILE
A file IS anything, such as a program or dafa, stored on a cartridge. To delete a program called prog you type:
DELETE mdv1 prog
LOADING
PROGRAMS
A program can be loaded from a M,crodrlve cartridge by typing:
LOAD mdv2 bord
If the program loads correctly It will prove that both copies are good. You can test the program by using:
LIST to list It.
RUN to run It.
Instead of uSing LOAD followed by RUN you can combine the two operations In one command.
LRUN mdv2 bord
The program will load and execute immediately.
MERGING
PROGRAMS
Suppose that you have two programs saved on Microdrlve 1 as progl and prog2:
100 PRINT IlFirst"
110 PRINT "Secondfl
If you type:
LOAD mdv1 prog1 followed by:
MERGE mdv1_prog2
The two programs will be merged into one. To verify this, type LIST and you should see:
100 PRINT "First fl
110 PRINT "Second"
If you MERGE a program make sure that all ItS line numbers are different from the program already In main memory. Otherwise It will overwrite some of the lines of the first program. This facility becomes very valuable as you become proficient in handling procedures. It is then qUite natural to bUild a program up by adding procedures or functions to it.
GENERAL
Be careful and methodical with cartridges. Always keep one back-up copy and If you suspect any problem with a cartridge or microdrive keep a second back-up copy.
Computer professionals very rarely lose data. They know that even the best machines or devices will be occasional faults and they allow for this.
If you want to call a program by a particular name, say, square, It may be a good idea to use names like sql, sq2...
for preliminary versions. When the program is in its final form take at least two copies called square and the others may be deleted by re-formatting or by some more selective method.
•
•
•
•
12/84
•
•
8.
9.
6.
7.
3.
4.
You can score a maximum of 14 points from the following test. Check your score with the answers on page 108.
1.
Why are lower case letters preferred for program words which you choose?
2.
What
IS the purpose of indenting?
What should normally guide your choice of identifiers for variables and loops?
Name three ways of editing a program in the computer's main memory (three points).
5.
What should you remember to type at the end of every command or program line when you enter it?
What should you normally type before you enter a program at the keyboard?
What must be at the beginning of every line to be stored as part of a program?
What must you remember to type to make a program execute?
What keyword enables you to put into a program information which has no effect on the execution?
10.
Which two keywords help you to store programs on and retrieve from cartridges?
(two pOints).
SELF TEST ON
CHAPTER 5
•
2
3.
1.
Re-write the following program using lower case letters to give a better presentation.
Add the words NEW and RUN. Use line numbers and the ENTER symbol Just as you would to enter and run a program. Use REMark to give the program a name.
LET TWO$
LET FOUR$
LET SIX$
=
"TWO"
=
"FOUR"
=
TWO$ & FOUR$
PRINT LEN(six$)
Explain how two and four can produce 7.
Use indenting, lower case letters, NEW, RUN, line numbers and the ENTER symbol to show how you would actually enter and run the following program:
REPEAT LOOP
LETTER CODE
LET LETTERS$
=
RND (65 TO 90)
= CHR$(LETTER CODE)
PRINT LETTER$
IF LETTER$
=
'z' THEN EXIT LOOP
END REPEAT LOOP
Re-write the following program in better style using meaningful variable names and good presentation. Write the program as you would enter it:
LET S
=
0
REPeat TOTAL
LET N = RND(1 TO 6)
PR I NT
I
N
I
LET S
IF n
=
S + N
=
6 THEN EXIT TOTAL
END REPeat TOTAL
PRINT S
Decide what the program does and then enter and run it to check your decision.
PROBLEMS ON
CHAPTER 5
12/84
28
CHAPTER 6
ARRAYS AND
FOR LOOPS
WHAT IS AN ARRAY
You know that numbers or character strings can become values of variables. You can picture this as numbers or words gOing Into internal pigeon holes or houses. Suppose for example that four employees of a company are to be sent to a small village, perhaps because all has been discovered. The village IS one of the few places where the houses only have names and there are four available for rent All the house names end with a dollar symbol.
West/ea$ Lakes/de$ Rose/awn$ Oaktree$
The four employees are called:
Program 1
Program 2
They can be placed in the houses by one of two methods:
100 LET west lea$ = "VAL"
110 LET Lakeside$
120 LET roselawn$
= "HAL"
= I'MEL"
130 LET oakt ree$
140 PRINT
= "DEL"
I westLea$ I Lakeside$ I roseLawn$ I oaktree$
100 READ
110 PRINT westlea$, Lakeside$, roseLawn$, oaktree$
I westLea$ I Lakeside$ I roseLawn$ I oaktree$
120 DATA "VALli, IIHALI!, "MEL", "DELli westlea$
I
VAL lakeside$
I
HAL roselawn$
I
MEL oaktree$
.
I
DEL
As the amount of data gets larger the advantages of READ and DATA over LET become greater. But when the data gets really numerous the problem of finding names for houses gets as difficult as finding vacant houses in a small village.
The solution to this and many other problems of handling data lies in a new type of pigeon hole or variable in which many may share a Single name. However, they must be distinct so each variable also has a number like numbered houses in the same street
Suppose that you need four vacant houses in High Street numbered 1 to 4. In
SuperBASIC we say there IS an array of four houses. The name of the array is high_st$ and the four houses are to be numbered 1 to 4.
But you cannot Just use these array variables as you can ordinary (simple) variables.
You have to declare the dimensions (or size) of the array first The computer allocates space internally and It needs to know how many string variables there are In the array and also the maximum length of each string variable. You use a DIM statement thus:
DIM high_st$(4,3)
11maximum length of string
L number of string variables
After the DIM statement has been executed the variables are available for use. It is as though the houses have been bUilt but are still empty. The four 'houses' share a common nam~ hlgh-st$, but each has its own number and each can hold up to three characters:
•
•
•
12/84
•
•
•
•
There are five programs below which all do the same thing: they cause the four 'houses' to be bccupled' and they PRINT to show that the 'occupation' has really worked. The final method uses only four lines but the other four lead up to It in a way which moves all the time from known ideas to new ones or new uses of old ones. The movement is also towards greater economy.
If you understand the first two or three methods perfectly well you may prefer to move straight onto methods 4 and 5. But If you are in any doubt. methods 1, 2 and 3 will help to clarify things.
100 DIM high st$(4,3)
110 LET high-st$(1)
120 LET high-st$(2)
"VAL"
=
"HAL"
130 LET high-st$(3)
140 LET high-st$(4)
"MEL"
=
"DEL"
150 PRINT' high st$(1l
I high st$(2)
I
160 PRINT' high=st$(3)
I high=st$(4)
I
100 DIM high st$(4,3)
110 READ high st$(1l,high st$(2),high st$(3),high st$(4)
120 PRINT
I high st$(1l
I high st(2) , -
130 PRINT' high-st$(3)
I high st(4)
I
140 DATA "VAL", .....HAlll, "MEL", 'j"j'""OEL"
This shows how to economise on variable names but the constant repeating of high_st$ is both tedious and the cause of the cluttered appearance of the programs. We can, again, use a known technique - the REPeat loop - to Improve things further. We set up a counter, number, which increases by one as the REPeat loop proceeds.
100 RESTORE 190
110 DIM high st$(4,3)
120 LET number
=
0
130 REPeat houses
140 LET number
= number + 1
150 READ high st$(number)
160 IF num = 4THEN EXIT houses
170 END REPeat houses
180 PRINT hi gh St<1l1 hi gh st (2)
I hi gh st (3)
I hi gh st(4)
190 DATA "VAL"-;- "HAL", "MEl", "DEL"
This special type of loop, In which something has to be done a certain number of times, is well known. A special structure, called a FOR loop, has been invented for it. In such a loop the count from 1 to 4 is handled automatically. So is the eXit when all four items have been handled.
100 RESTORE 160
110 DIM high st$(4,3)
120 FOR number
=
1 TO 4
130 READ high st$(number)
140 PRINT
I high st$(number)
I
150 END FOR number-
160 DATA IIVAL","HAL","MEl'l,"DEL"
Program 1
Program 2
,
Program 3
Program 4
Arrays and For Loops
12/84
The output from all four programs is the same:
VAL HAL MEL DEL
Which proves that the data is properly stored internally in the four array variables:
G
1 a
2 a
3 a
4
29
Arrays and For Loops
30
Method 4 is clearly the best so far, because it can deal equally well with 4 or 40 or
400 items by Just changing the number 4 and adding more DATA Items. You can use as many DATA statements as you need.
In its simplest form the FOR loop is rather like the simplest form of REPeal loop. The two can be compared:
100 REPeat greeting
110 PRINT "HeLLo"
120 END REPeat greeting
100 FOR greeting
=
1 TO 40
110 PRINT "HeLLo"
120 END FOR greeting
Both these loops would work. The REPeal loop would print 'Hello' endlessly (stop it with the BREAK sequence) and the FOR loop would print 'Hello' Just forty times.
Notice that the name of the FOR loop is also a variable, greeting, whose value varies from 1 to 40 in the course of running the program. This variable
IS sometimes called the loop variable or the control variable of the loop.
Note the structure of both loops takes the form:
Opening statement
Content
Closing statement
However, certain structures have allowable short forms for use when there are only one or a few statements in the content of the loop. Short forms of the FOR loop are allowed so we could write the program in the most economical form of all.
Program 5
100 RESTORE 140 : CLS
110 DIM high st$(4.3)
120 FOR number = 1 TO 4 : READ high_st$(number)
130 FOR number = 1 TO 4: PRINT
1 high st$(number)
1
140 DATA "VAL", "HAL", "MEL", "DELli
Colons serve as end-of-statement symbols instead of ENTER and the ENTER symbols of lines 120 and 130 serve as END FOR statements.
There is an even shorter way of writing the above program. To print out the contents of the array high_st$ we can replace line 130 by:
130 PRINT
I high_st$
I
This uses an array slicer which we will discuss later in chapter 13.
We have introduced the concept of an array of string variables so that the only numbers involved would be the subscripts in each variable name. Arrays may be string or numeric, and the following examples illustrate the numeric array.
Program 1
Simulate the thrOWing of a pair of dice four hundred times. Keep a record of the number of occurrences of each possible score from 2 to 12.
100 REMark DICEl
110 LET two = O:three = O:four = O:five = O:six = 0
120 LET seven = O:eight = O:nine = O:ten = O:eLeven
=
O:twelve
=
0
130 FOR throw = 1 TO 400
140 LET diel
=
RND(l TO 6)
150 LET die2
=
RND(l TO 6)
160 LET score = di el + di e2
170
180
190
200
210
220
230
240
250
260
270
IF score = 2 THEN LET two = two + 1
IF score
=
3 THEN LET three
= three +
IF score = 4 THEN LET four = four + 1
IF score
=
5 THEN LET five
= five + 1
IF score
IF score
I F score
=
6 THEN LET six
= six + 1
= 7 THEN LET seven = seven +
=
8 THEN LET ei ght
= ei ght +
IF score = 9 THEN LET nine = nine + 1
I F score
=
10 THEN LET ten
= ten + 1
IF score
IF score
=
11 THEN LET eleven
= eLeven + 1
=
12 THEN LET twelve
=
twelve + 1
280 END FOR throw
290 PRINT! two! three! four! five! six
300 PRINT! seven! eight! nine! ten! eLeven
I tweLve
12/84
•
•
•
•
•
•
Arraysand For Loops
In the above program we establish eleven simple variables to store the tally of the scores.
If you plot the tallies printed at the end you find that the bar chart is roughly triangular
The higher tallies are for scores six, seven, eight and the lower tallies are for two and twelve. As every dice player knows this reflects the frequency of the middle range of scores (six,seven,eight) and the rarity of twos or twelves.
100 REMark Dice2
110 DIM talLy(12)
120 FOR thraw
=
1 TO 400
130 LET die 1
=
RND(1 TO 6)
140 LET die-2
150 LET scare
= RND(1 TO 6)
= die 1 + die 2
160 LET taLLy(scare; = taLLY(scare) + 1
170 END FOR thraw
180 FOR number = 2 ta 12: PRINT taLLy(number)
In the first FOR loop, using throw, the subscript of the array variable IS score. This means that the correct array subscript is automatically chosen for an Increase in the tally after each throw. You can think of the array, tally, as a set of pigeon-holes numbered 2 to
12.
Each time a particular score occurs the tally of that score is increased by throwing a stone into the corresponding pigeon-hole.
In the second (short form) FOR loop the subscript is number. As the value of number changes from 2 to 12 all the values of the tallies are printed.
Notice that in the DIM statement for a numeric array you need only declare the number of variables required. There is no question of maximum length as there is in a string array.
If you have used other versions of BASIC you may wonder what has happened to the
NEXT statement All SuperBASIC structures end with END something. That is consistent and sensible but the NEXT statement has a part to playas you Will see in later chapters.
Program 2
3.
4.
You can score a maximum of 16 points from the following test Check your score with the answers on page 109.
1.
Mention two difficulties which arise when the data needed for a program becomes numerous and you try to handle it without arrays. (two points)
2.
If, in an array, ten variables have the same name then how do you know which is which?
What must you do normally in a program, before you can use an array variable?
5.
What IS another word for the number which distinguishes a particular variable of an array from the other variables which share its name?
Can you think of two Ideas in ordinary life which correspond to the concept of an array in programming? (two points)
6.
7.
8
9.
10.
In a REPeat loop, the process ends when some condition causes an EXIT statement to be executed. What causes the process in a FOR loop to terminate?
A REPeal loop needs a name so that you can EXIT to its END properly. A FOR loop also has a name but what other function does a FOR loop's name have?
What are the two phrases which are used to describe the variable which is also the name of a FOR loop?
(two points)
The values of a loop variable change automatically as a FOR loop is executed.
Name one possible important use of these values.
a b c d
Which of the following do the long form of REPeal loops and the long form of
FOR loops have in common? For each of the four Items either say that both have it or which type of loop has it
An opening keyword or statement
A closing keyword or statement
A loop name.
A loop variable or control variable (four points)
SELF TEST ON
CHAPTER 6
31 12/84
32
PROBLEMS ON
CHAPTER 6
1.
2.
3.
4.
Use a FOR loop to place one of four numbers 1,2,3,4 randomly in five array variables' card(1), card(2), card(3), card(4), card(5).
It does not matter If some of the four numbers are repeated. Use a second FOR loop to output the values of the five card variables.
Imagine that the four numbers 1,2,3,4 represent 'Hearts; Clubs: 'DIamondS: Spades
What extra program lines would need to be inserted to get output in the form of these words Instead of numbers?
Use a FOR loop to place five random numbers In the range 1 to 13 in an array of five variables: card(1), card(2), card(3), CfJrd(4) and card(5).
Use a second FOR loop to output fhe values of the five card variables.
Imagine that the random numbers generated in problem 1 represent cards. Write down the extra statements that would cause the following output:
Number
1
2 to 10
11
12
13
Output the word 'Ace the actual number the word :Jack' the word 'Queen' the word 'King'
•
•
•
12/84
•
•
•
•
If you were to try to write computer programs to solve complex problems you might find it difficult to keep track of things. A methodical problem solver therefore divides a large or complex job into smaller sections or tasks, and then divides these tasks again into smaller tasks, and so on until each can be be easily tackled.
This is similar to the arrangement of complex human affarrs. Successful government depends on a delegation of responsibility. The Pllme Minister divides the work amongst ministers, who divide it further through the Civil Service until tasks can be done by individuals without further division. There are complicating features such as common services and interplay between the same and different levels, but the hierarchical structure is the dominant one.
A good programmer will also work in this way and a modern language like SuperBASIC which allows properly named, well defined procedures will be much more helpful than older versions which do not have such features.
The idea is that a separately named block of code should be written for a particular task. It doesn't matter where the block of code is In the program. If It is there somewhere, the use of Its name will : activate the code return control to the pOint in the program Immediately after that use.
If a procedure, square, draws a square the scheme is as shown below:
CHAPTER
7
SIMPLE
PROCEDURES
procedure definition
DEFine PROCedure square
REMark Code to draw square
END DEFine
1 draws a square procedure call
0 ( - - - - square
In practice the separate tasks within a Job can be identified and named before the definition code IS wlltten. The' name is all that is needed In calling the procedure so the main outline of the program can be written before all the tasks are defined.
Alternatively if it is preferred, the tasks can be written first and tested. If It works you can then forget the details and just remember the name and what the procedure does.
The following example could qUite easily be written without procedures but it shows how they can be used in a reasonably simple context. Almost any task can be broken down in a similar fashion which means that you never have to worry about more than, say, five to thirty lines at anyone time. If you can wllte thirty-line programs well and handle procedures, then you have the capability to write three-hundred-line programs.
You can produce ready made buzz phrases for politicians or others who wish to give an impression of technological fluency without actually knowing anything. Store the following words in three arrays and then produce ten random buzz phrases.
Example
adjec1$
Full
Systematic
Intelligent
Controlled
Automated
Synchronised
Functional
Optional
Positive
Balanced
Integrated
Coordinated
Sophisticated adjec2$ fifth-generation knowledge-based compatible cybernetic user-friendly parallel learning adaptable modular structured logic-oriented file-oriented standardised nounS systems machines computers feedback transputers micro-chips capability programming packages databases spreadsheets word-processors objectives
12/84
33
Smple Procedures
34
ANALYSIS
We will write a program to produce ten buzzv.ord phrases. The stages of the program are:
Store the words In three string arrays.
2
3
4
Choose three random numbers which will be the subscripts of the array variables.
Print the phrase.
Repeat 2 and 3 ten times.
DESIGN
VARIABLES
We identify three arrays of which the first two will contain adjectives or words used as adjectives - describing words. The third array will hold the nouns. There are 13 words in each section and the longest word has 16 characters including a hyphen.
Array adjec1$(13,12) adJec2$(13,16) noun$(13,15)
Purpose first adjectives second adjectives nouns
PROCEDURES
We use three procedures to match the jobs Identified
store_data stores the three sets of thirteen words geL random gets three random numbers In range 1 to 13.
make_phrase prints a phrase.
MAIN PROGRAM
This is very simple because the main work is done by the procedures.
Declare (DIM) the arrays
Store_data
FOR ten phrases geLrandom make_phrase
END
Program
1DO REMa rk
110 REMark
************
*
Buzzword
*
120 REMark ************
130 DIM adjecl$(13,12), adjec2$(13,16),noun$(13,15)
140 store data
150 FOR phrase = 1 TO 10
160 . get random
170 make phrase
180 END FORphrase
190 REMark **************************
200 REMark
*
Procedure Definitions
*
210 REMark **************************
220 DEFine PROCedure store data
230
240
250
260
REMark *** procedure-to store the buzzword data ***
RESTORE 420
FORitem=1T013
READ adjecl$(item), adjec2$(item),noun$(item)
270 END FOR item
280 END DEFi ne
290 DEFine PROCedure get random
300
310
REMark *** procedure to select the phrase
LET adl = RND(l TO 13)
***
320
330
LET ad2 = RND(l TO 13)
LET n = RND(l TO 13)
340 END DEFine
350 DEFine PROCedure make phrase
360
370
REMark *** procedure to print out the phrase ***
I adjec1$(ad1l
I adjec2$(ad2)
I noun$(n)
•
•
•
•
12/84
Smple Procedures
•
•
•
380 END DEFine
390 REMark
400 REMark
****************
*
Program Data
*
410 REMa rk
****************
420 DATA "Full", "fifth-generation", "systems"
430 DATA "Systematic", "knowledge-based", "machines"
440 DATA "InteLLigent", "compatibLe", "computers"
450 DATA "ControLled", "cybernetic", "feedback"
460 DATA "Automated", "user-friendly", "transputers"
470 DATA "Synchronised", "paralleL", "micro-chips"
480 DATA "Functional", "Learning", "capabi
490 DATA "Optional", "adaptabLe", lity"
"programming"
500 DATA "Positive", "moduLar", "packages"
510 DATA "BaLanced", "structured", "databasesll
520 DATA "Integrated", Illogic-oriented", "spreadsheets"
530 DATA "Coordinated",
"f;
Le-oriented", "word-processors"
540 DATA "Sophisticated", "standardised", "objectives
ll
Automated fifth-generation capabiLity
Functional Learning packages
FuLL paraLLeL objectives
Positive user-friendly spreadsheets
Intelligent file-oriented capability
Synchronised cybernetic transputers
Functional Logic-oriented micro-chips
Positive paraLLeL feedback
BaLanced learning databases
Controlled cybernetic objectives
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL 01844 - 351694
FAX: 01844 - 352554
Suppose we wish to draw squares of various sizes and various colours in various positions on the scale graphics screen.
If we define a procedure, square, to do this it will require four Items of information: length of one side colour (colour code) position (across and up)
The square's flosition is determined by giving two values, across and up, which fix the bottom left hand corner of the square as shown below
PASSING
INFORMATION TO
PROCEDURES ac+side,up+side ac+side,up
up ac
The colour of the square IS easily fixed but the square itself uses the values of side and ac and up as follows.
200 DEFine PROCedure square(side,ac,up)
210
220
LINE ac,up TO ac+side,up
LINE TO ac+side,up+side
230 LINE TO aC,up+side TO ac,up
240 END DEFine
In order to make this procedure work values of side,ae and up must be provided. These values are provided when the procedure is called. For example you could add the following main program to get one green square of side 20.
35
12/84
Smple Proce6Jres
36
100 PAPER 7: CLS
110 INK 4
120 square 20,SO,SO
The numbers 20,50,50 are called parameters and they are passed to the variables named
In the procedure definition thus: sq uare 20,50,50
I
J.,/.
DEFine PROCedure square(side,ac,up)
The numbers 20,50,50 are called actual parameters, They are numbers in this case but they could be variables or expressions, The variables slde,ae,up are called formal parameters. They must be variables because the 'receIVE' values.
A more interesting main program uses the same procedure to create a random pattern of coloured pairs of squares. Each pair of squares is obtained by offsetting the second one across and up by one-fifth of the side length thus:
Assuming that the procedure square is still present at line 200 then the following program will have the claSSical effect
100 REMark Squares Pattern
110 PAPER 7 : CLS
120 FOR pa i r = 1 TO 20
130 INK RND(S)
140
1S0
160
LET side = RND(10 TO 20)
LET ac = RND (SOl : up = RND (70l square side,ac,up
170
180
LET ac=ac+side/S : up = up+side/S square side,ac,up
190 END FOR pai r
The advantage of procedures are:
1.
You can use the same code more than once in the same program or in others.
2.
You can break down a task into sub-tasks and write procedures for each sub-task.
This helps the analysis and design.
3.
4.
Procedures can be tested separately. ThiS helps the testing and debugging.
Meaningful procedure names and clearly defined beginnings and ends help to make a program readable.
When you get used to properly named procedures With good parameter facilities, you should find that your problem-solving and programming powers are greatly enhanced.
•
•
•
12/84
•
3
4.
You can score a maximum of 14 pOints from the following test. Check your score with the answers on page 11G.
1.
How do we normally tackle the problem of great Size and complexity in human affairs?
2.
How can this principle be applied in programming?
What are the two most obvious features of a simple procedure definition? (two pOints)
5.
What are the two main effects of using a procedure name to tall' the procedure?
(two points)
What is the advantage of uSing procedure names in a main program before the procedure definitions are written?
6.
'1
8
9.
10.
11.
SELF TEST ON
CHAPTER 7
What is the advantage of Writing a procedure definition before uSing itS name in a main program?
How can the use of procedures help a thirty·line·programmer' to write much bigger programs?
Some programs use more memory in defining procedures, but in what circumstances do procedures save memory space?
Name two ways by which information can be passed from a main program to a procedure. (two points)
What is an actual parameter?
What is a formal parameter?
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844 . 351694
FAX: 01844 - 352554
3.
4.
5.
6
1.
2.
Write a procedure WhiCh outputs one of the four suits: 'Hearts: 'Clubs: 'Diamonds: or 'Spades: Call the procedure five times to get five random suits.
Write another program for problem 1 using a number in the range 1 to 4 as a parameter to determine the output word.
If you have already done thiS, then try writing the program Without parameters.
Write a procedure which will output the value of a card that is a number in the range 2 to 10 or one of the words 'Ace: ~ack: 'Queen: 'King'.
Write a program which calls this procedure five times so that five random values are output.
Write the program of problem 3 again USing a number In the range 1 to 13 as a parameter to be passed to the procedure. If this was the method you used first time, then try writing the program without parameters.
Write the most elegant program you can, using procedures, to output four hands of five cards each. Do not worry about duplicate cards. You can take elegance to mean an appropriate mixture of readability, shortness and efficiency. Different people and/or different circumstances will place different importance on these three qualities which sometimes work against each other.
PROBLEMS ON
CHAPTER 7
1//84
37
38
CHAPTER
FROM BASIC
TO
SUPERBASIC
8
If you are familiar with one of the earlier versions of BASIC you may find it possible to omit the first seven chapters and use this chapter instead as a bridge between what you know already and the remaining chapters. If you do this and still find areas of difficulty
It may be helpful to backtrack a little into some of the earlier chapters.
If you have worked through the earlier chapters this one should be easy reading. You may find that, as well as introducing some new ideas, it gives an interesting slant on the way BASIC is developing. Apart from its program structuring facilities SuperBASIC also pushes forward the frontiers of good screen presentation, editing, operating facilities and graphics. In short It is a combination of user-friendliness and computing power which has not eXisted before.
So, when you make the transition from BASIC to SuperBASIC you are moving not only to a more powertul, more helpful language, you are also moving into a rer1)arkably advanced computing environment.
We will now discuss some of the main features of SuperBASIC and some of the features which distinguish it from other BASICs.
ALPHABETIC
COMPARISONS
The usual simple arithmetic comparisons are possible. You can write:
LET pet1$ ;: "CAT"
LET pet2$ = "DOG"
IF petl$
<
pet2$ THEN PRINT "Meow"
The output will be Meow because in this context the symbol
< means: earlier (nearer to A in the alphabet)
SuperBASIC makes comparisons sensible. For example you would expect: tat' to come before 'DOG' and
'ERD98L: to come before 'ERD746L:
A simplistic approach, blindly using internal character coding, would give the wrong' result in both the above cases but try the following program which finds the earliest' of two character strings.
100 INPUT item1$. item2$
110 IF item1$
120 IF item1$
130 IF item1$
<
item2$ THEN PRINT iteml$
= item2$ THEN PRINT "EquaL"
>
item 2$ THEN PRINT item2$ cat cat
ERD98L
ABC
INPUT dog
DOG
ERD746L abc
OUTPUT cat cat
ERD98L
ABC
The Concept Reference Guide section will give full details about the way comparisons of strings are made in SuperBASIG
•
•
•
•
12/84
From Basic toSuperBASIC
•
•
•
Most BASICs have numeric and string variables. As in other BASICs the distinguishing feature of a string variable name In SuperBASIC IS the dollar sign on the end. Thus: numeric: count sum total string: word$ high_st$ day_of_week$
You may not have met such meaningful variable names before though some of the more recent BASICs do allow them. The rules for Identifiers In SuperBASIC are given In the
Concept Reference Guide. The maximum length of an identifier is 255 characters. Your choice of identifiers is a personal one. Somefimes the longer ones are more helpful in conveYing to the human reader what a program should do. But they have to be typed and, as in ordinary English, spade is more sensible than horticultural earth-turning
implement Shorter words are preferred If they convey the meaning but very short words or single letters should be used sparingly. Variable names like X,Z'p3,Q2 introduce a level of abstraction which most people find unhelpful.
SuperBASIC allows integer variables which take only whole-number values. We dlstin.9uish
these with a percentage sign thus: count% number% nearesLpound%
There are now two kinds of numeric variable. We call the other type, which can take whole or fractional values, floating point. Thus you can write:
LET pri ce = 9
LET cost = 7.31
LET countr.
=
13
But If you write:
LET countX
=
5.43
the value of count% will become 5. On the other hand:
LET countX = 5.73
will cause the value of counfOAJ to be 6. You can see that SuperBASIC does the best it can, rounding off to the nearest whole number
The principle of always trying to be intelligently helpful, rather than give an error message or do something obviously unwanted, is carried further For example, if a string variable
mark$ has the value
164' then:
LET score
= markS will produce a numeric value of 64 for score. Other versions of BASIC would be likely to halt and say something like:
Type mis-match' or 'Nonsense in BASIC'
If the string cannot be converted then an error is reported.
VARIABLES AND
NAMES -
IDENTIFIERS
INTEGER VARIABLES
COERCION
There is one other type of variable in SuperBASIC, or rather the SuperBASIC system makes it seem so. Consider the SuperBASIC statement:
IF windy THEN fly_kite
In other BASICs you might write:
IF w=1 THEN GOSUB 300
LOGICAL VARIABLES
AND SIMPLE
PROCEDURES
12/84 39
From Basic to SuperBAS1C
40
In this case
w=1
is a condition or logical expression which is either true or false If it is true then a subroutine starting at line 300 would be executed. This subroutine may deal with kite flying but you cannot tell from the above line. A careful programmer would write:
IF w=l THEN GOSUB 300 : REM fly_ki te to make it more readable. But the SuperBASIC statement is readable as it stands. The identifier windy is interpreted as true or false though it is actually a floating point van able.
A value of 1 or any non-zero value is taken as true.
Zero is taken as false. Thus the single word, windy, has the same effect as a condition of logical expression.
The other word,
GOSUB 300.
fly_kite, IS a procedure. It does a job similar to, but rather better than,
The following program Will convey the idea of logical variables and the simplest type of named procedure.
100 INPUT wi ndy
110 IF windy THEN fly kite
120 IF NOT windy THEN-tidy shed
130 DEFine PROCedure fly kite
140 PRINT "See it in the air."
150 END DEFine
160 DEFine PROCedure tidy shed
170 PRINT "Sort out rubbish."
180 END DEFine
INPUT a
-2
1
2
OUTPUT
Sort out rubbish.
See it
See it
See it in the air intheair in the air
You can see that only zero is taken as meaning false. You would not normally write procedures with only one action statement but the program illustrates the idea and syntax in a very simple context. More is said about procedures later in this chapter.
LET STATEMENTS
In SuperBASIC LET is optional but we use it in thiS manual so that there will be less chance of confusion caused by the two possible uses of =.
The meanings of = in:
LET count = 3 and in
IF count = 3 THEN EXIT are different and the LET helps to emphasise this. However, if there are two or a few
LET statements dOing some simple job such as setting initial values, an exception may be made.
For example:
100 LET fi rst =
110 LET second =
120 LET t h i rd = a a a may be re-written as:
100 LET first = 0 : second = 0 : third = a without loss of clarity or style. It is also consistent With the general concept of allOWing short forms of other constructions where they are used in simple ways.
The colon: is a valid statement terminator and may
LET.
be used with other statements besides •
•
•
•
12/84
From Basic to SuperBASIC
•
•
•
In a later chapter we will explain how other graphics facilities, such as drawing circles, can be handled but here we outline the pixel-oriented features, There are two modes which may be activated by any of the follOWing:
THE BASIC SCREEN
Low resolution
8 Colour Mode
256 pixels across, 256 down
MODE 256
MODE 8
High resolution
4 Colour Mode
512 pixels across, 256 down
MODE 512
MODE 4
In both modes pixels are addressed by the range of numbers: o -
511 across and 0 - 255 down
Since mode 8 has only half the number of pixels across the screen as mode 4, mode
8 pixels are twice as wide as mode 4 pixels and sc in mode 8 each pixel can be specified by two coordinates. For example: o or 1 2 or 3 510 or 511
It also means that you use the same range of numbers for addreSSing pixels Irrespective of the mode, Always think 0-511 across and 0-255 down,
If you are using a television then not all the pixels may be visible.
The colours available are:
COLOURS
MODE 256 black blue red magenta green cyan yellow white
Code
2
3
0
1
6
7
4
5
MODE 512 black red green white
You may find the following mnemonic helpful in remembering the codes:
Bonny Babies Really Make Good Children, You Wonder
In the hlgh-resolulion mode each colour can be selected by one of two codes, You will see later how a startling range of colour and stipple (texture) effects can be produced if you have a goad quality colour mOnitor.
Some of the screen presentation keywords are as fallows:
INK colour foreground colour
BORDER width, colour draw border at edge of screen or window background colour PAPER colour
BLOCK Width, height, across, down, colour colour a rectangle which has its top left hand corner at position across, down
12184
From Base to SuperBASIC
42
SCREEN
ORGANISATION
When you switch on your Ol the screen display is split Into three areas called windows as shown below Note than In order to fit these windows into the area covered by a television screen, some pixels around the border are not used in Television mode.
o to 511
,
o to 511
#1 #2 #1 & #2 o to
255 o to
255
1
Monitor
0
1
Television o
The windows are identified by # 0, # 1 and # 2 so that you can relate various effects to particular windows. For example:
CLS will clear window # you must type:
1 (the system chooses) so if you want the left hand area cleared
CLS #2
If you want a different paper (background colour) type for green:
PAPER 4 : CLS or
PAPER #2,4 : CLS #2 if you want to clear window # 2 to the background colour green.
The numbers # 0, # 1, # 2 are called channel numbers.
In this particular case they enable you to direct certain effects to the window of your choice. You will discover later that channel numbers have many other uses but for the moment note that all of the following statements may have a channel number The third column shows the default channel - the one chosen by the system if you do not specify one.
Note that windows may overlap. If you use a windows # listings.
TV screen the system automatically overlaps
1 and # 2 so that more character positions per line are available for program
Keyword Effect Default
AT
BLOCK
BORDER
ClS
CSIZE
CURSOR
FLASH
INK
OVER
PAN
PAPER
RECOl
SCROll
STRIP
UNDER
WINDOW
LIST
DIR
INPUT
Character Position
Draws block
Draw border
Clear screen
Character size
Position cursor
Causes/cancels flashing
Foreground colour
Effect of printing and graphics
Moves screen sideways
Background colour
Changes colour
Moves screen vertically
Background for printing
Underlines
Changes existing window
Lists program
Lists directory
Prints characters
Takes keyboard input
#1
#1
#2
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
#1
Statements or direct commands appear in window # O.
For more detail about the syntax or use of these key'Mlrds see other parts of the manual.
12/84
•
•
•
•
From Basic to SuperBASIC
•
•
•
The program below draws a green rectangle In 256 mode on red paper with a yellow border one pixel wide. The rectangle has its top left corner at pixel co-ordinates 100,100
(see OL Concepts).
Its Width is 80 units across (40 pixels) and Its height is 20 units down
(20 pixels).
100 REMark RectangLe
110 MODE 256
120 BORDER 1,6
130 PAPER 2 : CLS
140 BLOCK 80,20,100,100,4
You have to be a bit caretul In mode 256 because across values range from 0 to 511 even though there are only 256 pixels. We cannot say that the block produced by the above program is 80 pixels wide so we say 80 Units.
RECTANGLES AND
LINES
SuperBASIC has the usual LET, INPUT, READ and DATA statements for input The
PRINT statement handles most text output In the usual way with the separators:
INPUT AND OUTPUT
tabulates output
Just separates - no formatting effect forces new line normally provides a space but not at the start of line. If an item will not fit at the end of a line it performs a new line operation.
10 Allows tabulation to a deSignated column position.
You will be familiar With two types of repetitive loop exemplified as follows:
LOOPS
(a) Simulate 6 throws of an ordinary six-sided die.
100 FOR throw = 1 TO 6
110 PRINT RND(1 TO 6)
120 NEXT throw
(b) Simulate throws of a die until a six appears.
100 die = RND(1 TO 6)
110PRINTdie
120 IF die <> 6 THEN GOTO 10
Both of these programs will work in SuperBASIC but we recommend the following instead.
They do exactly the same jobs. Although program (b) is a little more complex there are good reasons for preferring it
(a) 100 FOR throw = 1 TO 6
110 PRINT RNO(1 TO 6)
120 END FOR throw
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVlCEf www.maurilron.co.uk
(b) 100 REPeat throws
110 die=RND(1T06)
120 PRINT die
130 IF die = 6 THEN EXIT throws
140 END REPeat throws
TEL: 01844 - 351694
FAX: 01844 - 352554
It is logical to provide a structure for a loop which terminates on a condition (REPeat loops) as well as those which are controlled by a count
The fundamental REPeat structure is:
REPeal identifier statements
END REPeat identifier
The EXIT statement can be placed anywhere in the structure but it must be followed by an identifier to tell SuperBASIC which loop to exit; for example:
EXIT throws would transfer control to the statement after
END REPeat throws.
This may seem like a uSing a sledgehammer to crack the nut of the simple problem illustrated. However the REPeat structure is very powerful. It will take you a long way.
43
12/84
44
From Basic to SuperBASIC
Ii.
If you know other languages you may see that it will do the Jobs of both REPEAT and
WHILE structures and also cope with other, more awkward, situations.
The SuperBASIC REPeal loop is named so that a correct clear exit is made. The FOR loop, like all SuperBASIC structures, ends with END, and its name is given for reasons which will become clear later.
You will also see later how these loop structures can be used in simple or complex situations to match exactly what you need to do. We will mention only three more features of loops at this stage. They will be familiar if you are an experienced user of BASIC.
The increment of the control variable of a FOR loop IS normally 1 but you can make
It other values by using the STEP keyword. As the examples show
100 FOR even = 2 TO 10 STEP 2
110 PRINT
I even
I
120 END FOR even output is 2 4 6 8 10
100 FOR backwards
=
9 TO 1 STEP-1
110 PRINT
I backwards
I
120 END FOR backwards output is 9 8 7 6 5 4 3 2
The second feature IS that loops can be nested. You may be familiar with nested FOR loops. For example the following program outputs four rows of ten crosses.
100 REMark Crosses
110 FOR row
=
1 TO 4
120 PRINT 'Row number'l row
130
140
150
FOR cross = 1 TO 10
PR I NT
I '
X '
I
END FOR cross
160 PRINT
170 PRINT \ 'End of row number'
I row
180 END FOR row output is
Row number 1
X X X X X X X X X X
End of row number 1
Row number 2
X X X X X X X X X X
End of row number 2
Row number 3
X X X X X X X X X X
End of row number 3
Row number 4
X X X X X X X X X X
End of row number 4
A big advantage of SuperBASIC is that it has structures for all purposes, not Just FOR loops, and lhey can all be nested one inside the other relfecling the needs of a task.
We can put a REPeat loop in a FOR loop. The program below produces scores of two dice in each row until a seven occurs, instead of crosses.
100 REMark Dice rows
110 FOR row = 1 TO 4
120
130
140
150
160
170
180
190
I
Row number
'.1
row
REPeat throws
LET die1
=
RND(1 TO 6)
LET die2
LET score
= RND(1 TO 6)
= die 1 + die2
I score
I
IF score
=
7 THEN EXIT throws
END REPeat throws
200 PRINT \'End of row' I row
210 END FOR row
12/84
•
•
•
•
From Basic to SuperBASIC
•
•
• sample output:
Row numbe r 1
811637
End of row numbe r
Row number 2
462945127
End of row number 2
Row numbe r 3
7
End of row number 3
Row number 4
624997
End of row number 4
The third feature of loops in SuperBASIC allows more flexibility in providing the range of values In a FOR loop. The following program illustrates this by printing all the divisible numbers from 1 to 20. (A divisible number is divisible evenly by a number other than itself or 1.)
100 REMark Divisible numbers
110 FOR num
=
4,6,8, TO 10,12,14 TO 16,18,20
120 PRINT I num
I
130 END FOR num
More will be said about handling repetition in a later chapter but the features described above will handle all but a few uncommon or advanced situations.
You will have noticed the simple type of decision:
IF die = 6 THEN EXIT throws
This is available in most BASICs but SuperBASIC offers extensions of thiS structure and a completely new one for handling situations with more than two alternative courses of action.
However you may find the following long forms of IF ... THEN useful. They should explain themselves.
100 REMark Long form IF ... END IF
110 LET sunny
=
RND (Q TO 1)
120 I F sunny THEN
130
140
PRINT 'Wear sunglasses'
PRINT 'Go for waLk'
150 END IF ii.
100 REMark Long form IF ..• ELSE ... END IF
110 LET sunny
=
RND(O TO 1)
120 I F sunny THEN
130 PRINT 'Wear sunglasses'
140 PRINT 'Go for waLk'
150 ELSE
160 PRINT 'Wear coat'
170 PRINT 'Go to cinema'
180 END IF
The separator THEN, IS optional in long forms or it can be replaced by a colon in short forms. The long decision structures have the same status as loops. You can nest them or put other structures into them. When a single variable appears where you expect a condition the value zero will be taken as false and other values as true.
DECISION MAKING
Most BASICs have a GOSUB statement which may be used to activate particular blocks of code called subroutines. The GOSUB statement is unsatisfactory In a number of ways and SuperBASIC offers properly named procedures With some very useful features.
Consider the following programs both of which draw a green 'square' of side length
50 pixel screen units at a position 200 across 100 down on a red background.
SUBROUTINES AND
PROCEDURES
45
12/84
46
From Basic to SuperBASIC
(a) USing GOSUB
100 LET coLour
110 LET across
=
4 : background
=
2
=
20
120 LET down = 100
130 LET side = 50
140 GOSUB 170
150 PRINT' END'
160 STOP
170 REMark Subroutine to draw square
180 PAPER background: CLS
190 BLOCK side, side, across, down, coLour
200 RETu rn
(b) Using a procedure with parameters
100 square 4, 50, 20, 100, 2
110 PRINT 'END'
120 DEFine PROCedure square<coLour,side,across,down,background)
130 PAPER background: CLS
140 BLOCK side, side, across, down, coLour
150 END DEFine
In the first program the values of coloue across, down, Side are fixed by LET statements before the GOSUB statement activates lines 180 and 190. Control is then sent back by the RETURN statement.
In the second program the values are given in the first line as parameters in the procedure call, square, which activates the procedure and at the same time provides the values
It needs.
In its simplest form a procedure has no parameters. It merely separates a particular piece of code, though even in thiS simpler use the procedure has the advantage over GOSUB because it is properly named and properly isolated Into a self-contained unit.
The power and simplifying effects of procedures are more obvious as programs get larger. What procedures do, as programs get larger is not so much make programming easier as prevent It from getting harder With increasing program size. The above example
Just illustrates the way they work in a simple context.
Examples
The follOWing examples Indicate the range of vocabulary and syntax of SuperBASIC which has been covered in this and earlier chapters, and will form a foundation on which the second part of this manual will bUild.
The letters of a palindrome are given as single items in DATA statements. The terminating item IS an asterisk and you assume no knowledge of the number of letters in the palindrome READ the letters into an array and pnnt them backwards. Some palindromes such as 'MADAM I'M ADAM' only work If spaces and punctuation are ignored. The one used here works properly.
100 REMark Pa Li ndromes
110 DIM text$(30)
120 LET textS
=
FILL$ (' ',30)
130 LET count
=
30
140 REPeat get letters
150
160
170
READ cha--;:acter$
IF characterS
= '.'
THEN EXIT get Letters
LET count = count-1 -
180 LET text$(countJ = characterS
190 END REPeat get Letters
200 PRINT textS -
210 DATA 'A','B','L','E' ,'W','A','S' ,'I' ,'E','R'
220 DATA 'E I ,'I' ,'S','A','W' ,'E','Lt,'B','A','*'
The following program accepts as input numbers in the range 1 to 3999 and converts them into the equivalent In Roman numerals. It does not generate the most elegant form.
It produces 1111 rather than IV
•
•
•
•
12/84
•
From Basic toSuperBASIC
•
•
100 REMark Roman numbers
110 INPUT number
120 RESTORE 210
130 FOR type = 1 TO 7
140 READ letter$, value
150
160
170
REPeat output
IF number
<
value: EXIT output
PRINT letter$;
180
190
LET number = number - va Lue
END REPeat output
200 END FOR type
210 DATA 'M',1000,'D',500,'C',100,'L ' ,SO,'X',10,'V ' ,5,'I',1
You should study the above examples carefully using dry runs if necessary until you are sure that you understand them.
In SuperBASIC full structuring features are provided so that program elements either follow in sequence or fit into one another neatly All structures must be identified to the system and named. There are many unifying and simplifying features and many extra facilities.
Most of these are explained and illustrated in the remaining chapters of this manual, which should be easier to read than the Keyword and Concept Reference sections.
However, it is easier to read because it does not give every technical detail and exhaust every topic which it treats. There may, therefore, be a few occasions when you need to consult the reference sections. On the other hand some major advances are discussed in the following chapters. Few readers will need to use all of them and you may find
It helpful to omit certain parts, at least on first reading.
CONCLUSION
47
12184
48
CHAPTER 9
DATA TYPES
VARIABLES
AND
IDENTIFIERS
You will have noticed that a program (a sequence of statements) usually gets some data to work on (input) and produces some kind of results (output). You will also have understood that there are Internal arrangements for storing this data. In order to avoid unnecessary technical explanations we have suggested that you imagine pigeon holes and that you choose meaningful names for the pigeon holes. For example, if it is necessary to store a number which represents the score from simulated dice-throws you imagine a pigeon hole named score which might contain a number such as 8.
Internally the pigeon holes are numbered and the system maintains a dictionary which connects particular names with particular numbered pigeon holes. We say that the name,
score,
points to its particular pigeon-hole (by means of fhe Internal dictionary).
score~"~J
The whole arrangement is called a variabfe.
What you see is the word
score.
We say that this word,
score
IS an identifier. It is what we see and It identifies the concept we need, In this case the result, 8, of throwing a pair of dice. Because the identifier IS what we see it becomes the thing we talk or write or think about. We write about score and its value at any particular moment.
There are four simple data types called floating point, integer string and logical and these are explained below. We talk about data types rather than variable types because data can occur on its own, for example 3.4 or 'Blue hat' as the value of a variable. But if you understand the different types of variables, you must also understand the different types of data.
IDENTIFIERS AND
1.
VARIABLES
A SuperBASfC identifier must begin with a letter and is a sequence of: upper or lower case letters digits or underscore
2.
An Identifier may be up to 255 characters in length so there is no effective limit in practice.
3.
An identifier cannot be the same as a keyword of SuperBASIC
6.
7.
4.
An integer variable name is an identifier with % on the end.
5.
A string variable name is an identifier with $ on the end.
No other identifiers must use the symbols % and $.
An identifier should usually be chosen so that it means something to a human reader but for SuperBASIC it does not have any particular meaning other than that It Identifies certain things.
FLOATING POINT
VARIABLES
Examples of the use of floating point variables are:
100 LET
110 LET
120 LET
130 days = 24 sales
=
3649.84
sales per day = saLes/days
sa Les_per_day
•
•
•
•
12/84
Data Types. Variables and Identifiers
•
•
•
The value of a floating point variable may be anything In the range:
+ 10
-"5 to + 10'6'5 With 8 Significant figures.
-
Suppose In the above program sales were, exceptionally, only 3p. Change line 110 to:
110 LET sales = 0.03
This system will change this to:
110 LET sales = 3E-2
To Interpret this, start with 3 or 3.0 and move the decimal pOint -2 places, i.e. two places left This shows that:
3E-2 is the same as 0.03
After running the program, the average daily sales are:
1.25E-3 which is the same as 0.00125
Numbers with an E are said to be ,n exponent form:
(mantissa) E (exponent) ~ (mantissa) x 10 to the power (exponent)
Integer variables can have only whole number values in the range -32678 to 32768 The following are examples of valid Integer variable names which must end With %.
LET count%
=
10
LET six tally%
=
RNO(10)
LET number 3% = 3
The only disadvantage of integer variables, when whole numbers are required, IS the slightly misleading % symbol on the end of the identifier. It has nothing to do With the concept of percentage. It is just a convenient symbol tagged on to show that the variable is an integer
INTEGER VARIABLES
Using a function is a bit like making an omelette. You put in an egg which is processed according to certain rules (the recipe) and get out an omelette. For example the function
INT takes any number as input and outputs the whole number part. Anything which is input to a function is called a parameter or argument INT is a function which gives the integer part of an expression. You may write:
PRINT INTC5.6) and 5 would be the output We say that 5.6 is the parameter and the function returns the value 5. A function may have more than one parameter. You have already met:
RNO (1 TO 6) which is a function with two parameters. But functions always return exactly one value.
ThiS must be so because you can put functions into expressions. For example:
PRINT 2
*
INTC5.6) would produce the output 10. It is an important property of functions that you can use them in expressions. It follows that they must return a single value which is then used in the expression. INT and RND are system functions; they come with the system, but later you will see how to write your own.
The following examples show common uses of the INT function.
100 REMark Rounding
110 INPUT decimaL
120 PRINT INTCdecimaL + 0.5)
In the example you input a decimal fraction and the output IS rounded. Thus 4.7 would become 5 but 4.3 would become 4.
You can achieve the same result using an Integer variable and coercion.
Trigonometrical functions will be dealt with in a later section but other common numeric functions are given In the list below
NUMERIC
FUNCTIONS
49 12/84
Data Types, Variables and Identifiers
50
Function
ASS
INT
SORT
Effect
Absolute or unsigned value
Integer part of a floating pOint number
Square root
Examples
ABS(7)
ABS(-4.3)
INT(2A)
INT(O.4)
INT(-2.7)
SORT(2)
SORT(16)
SORT(2.6)
Returned values
7
4.3
2
0
-3
1.414214
4
1.612452
There is a way of computing square roots which is easy to understand. To compute the square root of 8 first make a guess. It doesn't matter how bad the guess maybe.
Suppose you simply take halt of 8 as the first guess which is 4.
Because 4 is greater than the square root of 8 then 8/4 must be less than it The reverse is also true. If you had guessed 2 which is less than the square root then 8 / 2 must be greater than it
It follows that if we take any guess and compute number / guess we have two numbers, one too small and one too big. We take the average of these numbers as our next approximation and thus get closer to the correct answer.
We repeat this process until successive approximations are so close as to make little difference.
100 REMark Square Roots
110 LET number = 8
120 LET approx
= number/2
130 REPeat root
140 LET newvaL = (approx + number/approx) /2
150
160
IF newvaL == approx THEN EXIT root
LET approx
= newva 1
170 END REPeat root
1
180 PRINT 'Square root of !
number
I ';SI
!
newvaL sample output
Square root of 8 is 2.828427
Notice that the conditional EXIT from the loop must be in the middle. The traditional structures do not cope with this situation as well as SuperBASIC does.
The
== sign in line 150 means "approximately equal of the values being compared.
td: that is equal to within .0000001
NUMERIC
OPERATIONS
SuperBASIC allows the usual mathematical operations. You may notice that they are like functions with exactly two operands each. It is also conventional in these cases to put an operand on each side of the symbol. Sometimes the operation is denoted by a familiar symbol such as
+
or *.
Sometimes the operation is denoted by a keyword like DIV or MOD but there IS no real difference. Numeric operations have an order of priority.
For example, the result of:
PRINT 7 + 3*2 is 13 because the multiplication has a higher priOrity. However:
PRINT (7 + 3)*2 will output 20, because brackets over-ride the usual priority.
As you Will see later so many things can be done with SuperBASIC expressions that a full statement about priority cannot be made at this stage (see the Concept Reference Guide if you wish) but the operations we now deal With have the follOWing order of priority: highest raising to a power multiplication and division (including DIV, MOD) lowest add and subtract
12/84
•
•
•
•
Data Types, Vanables and ldentihers
•
•
The symbols + and are also used with only one operand which simply denotes positive or negative. Symbols used in this way have the highest prionty of all and can only be over-ndden by the use of brackets.
Finally if two symbols have equal priority the leftmost operation is performed first so that:
PRINT 7-2 + 5 will cause the subtraction before the addition. ThiS might be important If you should ever deal with very large or very small numbers.
Operation Symbol Examples
Add
+ 7+6.6.
7-66 Subtract
Multiply
* 3 *2.1
2.1 *(-3)
Divide
Integer divide
7/2
-17/5 •
Raise to power " 4"1.5
8
35
-34
Modulus
DIV
MOD
-8 DIV 2
7 DIV 2
13 MOD 5
-4
3
3
21 MOD 7
-17 MOD 8
0
7
6.3
-6.3
04
13.6
Results Note
Do not diVide by zero
Integers only
Do not divide by zero
Modulus returns the remainder part of a diVision. Any attempt to divide by zero will generate an error and terminate program exection.
Stnctly speaking, a numeric expression is an expression which evaluates to a number and there are more possibilities than we need to discuss here. SuperBASIC allows you to do complex things if you want to but it also allows you to do simple things in simple ways. In thiS section we concentrate on those usual straighrtorward uses of mathematical features.
Basically numeric expressions in SuperBASIC are the same as those of mathematics but you must put the whole expression In the form of a sequence.
5
+
3
6 - 4 becomes in SuperBASIC (or other BASIC):
(5
+
3)/(6 4)
In secondary school algebra there is an expression for one solution of a quadratic equation: ax'+bx+c=O
One solution ,n mathematical notation is: x = -b + j b' -4ac
2a
If we start with the equation:
2x'-3x+1=0
The following program will find one solution.
100 READ a,b,C
110 PRINT 'Root is' I (-b +SQRT<b A
120 DATA 2,-3,1
2 - 4*a*c))/(2*a)
NUMERIC
EXPRESSIONS
Example 1
51
12/84
'52
0,11<1 Types, Variables and Identifiers
Example 2
In problems which need to simulate the dealing of cards you can make cards correspond to the numbers 1 to 52 as follows:
1 to 13
14 to 26
27 to 39
40 to 52 ke, two ke, two ke, two ke, two king of hearts king of clubs king of diamonds king of spades
A particular card can be Identified as follows:
100 REM Card identification
110 LET card
120 LET suit
= 23
=
(card-1) DIV 13
130 LET vaLue
140 IF vaLue
150 IF vaLue
160 IF vaLue
= card MOD 13
=
0 THEN LET vaLue
=
13
=
1 THEN PRINT "Ace of ";
>=
2 AND vaLue
<=
10 THEN PRINT vaLue
I
"of ";
170 IF vaLue
180 IF value
190 IF value
200 IF suit
= 11 THEN PRINT "Jack of ";
=
12 THEN PRINT "Queen of ";
= 13 THEN PRINT "King of ";
= 0 THEN PRINT "hearts"
210 IF suit = 1 THEN PRINT "clubs"
220 IF suit
230 IF suit
= 2 THEN PRINT "diamonds"
=
3 THEN PRINT "spades"
There are new ideas In this program. They are In line 160. The meaning is clearly that the number is actually printed only if two logical statements are true. These are: value is greater than or equal to 2 AND value is less than or equal to 10
Cards outside this range are either aces or court cards' and must be treated differently.
Note also the use of !
in the PRINT statement to provide a space and; to ensure that output continues on the same line.
There are two groups of mathematical functions which we have not discussed here. They are the trigonometric and logarithmic. You may need the former In organising screen displays. Types of functions are also fully defined in the reference section.
LOGICAL VARIABLES
Stnctly speaking, SuperBASIC does not allow logical variables but it allows you to use other vanables as logical ones. For example you can run the following program:
100 REMark Logical VariabLe
110 LET hungry = 1
120 IF hungry THEN PRINT "Have a bun"
You expect a logical expression in line 120 but the numeric variable, hungry, is there on its own. The system Interprets the value, 1, of hungry as true and the output is:
Have a bun
If line 110 read:
LET hungry = 0 there would be no output. The system Interprets zero as false and all other values as true. That is useful but you can disguise the numeric quality ot hungry by writing:
100 REMark LogicaL VariabLe
110 LET true =
120 LET hung ry
1 : faLse
= true
= 0
130 IF hungry THEN PRINT "Have a bun"
STRING VARIABLES
There is much to be said about handling stnngs and string variables and this is left to a separate chapter.
•
•
•
•
12f84
•
•
•
2
3.
4.
5.
1.
A rich oil dealer gambles by tos3ing a cOin irl the following way. If It comes down heads he gets 1. If it comes down tails he throws again but the possible reward is doubled. This is repeated so that the rewards are as shown.
THROW 1 2 3 4 5 6
REWARDS 1 2 4 8 16 32 64
7
By Simulating the game try to decide what would be a falC initial payment for each such game:
(a) if the player IS limited to a maximum of seven throws per game
(b) If there is no maximum number of throws.
Bill and Ben agree to gamble as follows. At a given signal each divides his money into two halves and passes one half to the other player. Each then divides his new total and passes half to the other. Show what happens as the game proceeds if Bill starts with 16p and Ben starts With 64p.
What happens If the game IS changed so that each hands over an amount equal to half of what the other possesses?
Write a program which forms random three-letter words chosen from A,B,C,D and prints them until 'BAD' appears.
Modify the last program so that It terminates when any real three letter word appears.
PROBLEMS ON
CHAPTER 9
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVlCEf www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
12/84
53
54
CHAPTER 10
LOGIC
If you have read previous chapters you will probably agree that repetition, decision making and breaking tasks into sub-tasks are majOr concepts In problem analysis, program design and encoding programs. Two of these concepts, repetition and decision making, need logical expressions such as those in the following program lines:
IF score
IF suit
=
7 THEN EXIT throws
=
3 THEN PRINT "spades"
The first enables EXIT from a REPeat loop. The second is simply a decision to do something or not. A mathematical expression evaluates to one of millions of possible numeric values. Similarly, a string expression can evaluate to millions of possible strings of characters. You may find it strange that logical expressions, for which great importance is claimed, can evaluate to one of only two pOSSIble values: true or fatse.
In the case of: score:::; 7 this is obviously correct. Either score equals 7 or It doesn't I The expression musf be true or false - assuming that it's not meaningless. It may be that you do not krow the value at some time, but that will be put right in due course.
You have to be a bit more careful of expressions involving words such as OR, AND,
NOT but they are well worth investigating indeed, they are essential to good programming. They Will become even more important with the trend towards other kinds of languages based more on precise descriptions of what you require rather than what the computer must do.
AND
The word AND In SuperBASIC is like the word 'and' In ordinary English. Consider the following program.
100 REMa rk AND
110 PRINT "Enter two vaLues" \ "1 for TRUE or 0 for FALSE"
120 INPUT raining, hate in roof
130 IF raining AND hole'=:-in'=:-roof THEN PRINT "Get wet"
As in real life, you Will only get wet if it IS raining and there is a hole in the roof. If one
(or both) of the simple logical variables raining hale_in_roaf is false then the compound logical expression
raining AND hole_in_roof is also false. It takes two true values to make the whole expression true. This can be seen from the rules below. Only when the compound expression is true do you get wet.
raining
FALSE
FALSE
TRUE
TRUE
FALSE
TRUE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE effect
DRY
DRY
DRY
WET
Rules for AND
OR
In everyday life the word be' is used In two ways. We can illustrate the inclusive use of
OR by thinking of a cricket captain looking for players. He might ask "Can you bat or bowr'" He would be pleased if a player could do just one thing well but he would also be pleased if someone could do both. So it is in programming: a compound expression uSing OR is true if either or both of the simple statements or variables are true. Try the following program.
100 REMark OR test
110 PRINT "Enter two vaLues" \ "1 for TRUE or 0 for FALSE"
120 INPUT "Can you bat?", batsman
130 INPUT "Can you bowl?", bowLer
140 IF batsman OR bowler THEN PRINT "In the team"
12/84
•
•
•
•
•
•
•
•
You can see the effects of different combinations if answers In the rules below: batsman
FALSE
FALSE
TRUE
TRUE bowler
FALSE
TRUE
FALSE
TRUE batsman OR bowler
FALSE
TRUE
TRUE
TRUE effect not In feam in the team
In the team in the team
Rules for OR
When the inclusive OR is used a true value in either of the simple statements will produce a true value in the compound expression. If Ian Botham, the England all-rounder, were to answer the questions both as a bowler and as a batsman, both simple statements would be true and so would the compound expression. He would be in the team.
If you write 0 for false and 1 for true you will get all the possible combinations by counting in binary numbers:
00
01
10
11
The word NOT has the obvious meaning.
NOT true is the same as false
NOT false is the same as true
However you need to be careful. Suppose you hold a red triangle and say that it is:
NOT red AND square
In English this may be ambiguouS.
If you mean:
(NOT red) AND square then for a red triangle the expression is false.
If you mean:
NOT (red AND square) then for a red triangle the whole expression is true. There must be a rule in programming to make it clear what is meant. The rule is that NOT takes precedence over AND so the interpretation:
(NOT red) AND square is the correct one. This is the same as:
NOT red AND square
To get the other interpretation you must use brackets. If you need to use a complex logical expression it is best to use brackets and NOT if their usage naturally reflects what you want. But you can if you wish always remove brackets by using the following laws
(attributed to Augustus De Morgan)
NOT (a AND b)
NOT (a OR b)
For example: is the same as is the same as
NOT a OR NOT b
NOT a AND NOT b
NOT (tall AND fair) is the same as
NOT tall OR NOT fair
NOT (hungry OR thirsty) is the same as
NOT hungry AND NOT thirsty
NOT
12/84 55
Log",
Logic
S6
Test this by entering:
100 REMark NOT and brackets
110 PRINT "Enter two values"\"1 for TRUE or 0 for FALSE"
120 INPUT "tall"; tall
130 INPUT "fa; r"; fa; r
140 IF NOT <taLL AND fair) THEN PRINT "FIRST"
150 IF NOT tat L OR NOT fai r THEN PRINT "SECOND"
Whatever combination of numbers you give as Inpu\, the output will always be either two words or none, never one. This will suggest that the two compound logical expresSions are equivalent.
XOR-Exclusive
OR
Suppose a golf professional wanted an assistant who could either run the shop or give golf lessons. If an applicant turned up with both abilities he might not get the job because the golf professional might fear that such an able assistant would try to take over He would accept a good golfer who could not run the shop. He would also accept a poor golfer who could run the shop. This IS an exclusive OR situation: either is acceptable but not both. The follOWing program would test applicants:
100 REMark XOR test
110 PRINT "Enter 1 for yes or 0 for no."
120 INPUT "Can you run a shop?", shop
130 INPUT "Can you teach goLf?", golf
140 IF shop XOR goLf THEN PRINT "SuitabLe"
The only combinations of answers that will cause the output ''Suitable'' are (0 and 1) or (1 and 0). The rules for XOR are given below.
Able to run shop
FALSE
FALSE
TRUE
TRUE
Able to teach
FALSE
TRUE
FALSE
TRUE
Shop XOR teach
FALSE
TRUE
TRUE
FALSE effect no Job gets the job gets the job no Job rules for XOR
PRIORITIES
The order of priority for the logical operators IS (highest first):
NOT
AND
OR,XOR
For example the expression
nch OR tall AND fair means the same as:
rich OR (tall AND fair)
The AND operation
IS performed first. To prove that the two logical expressions have identical effects run the following program:
100 REMark Priorities
110 PRINT llEnter three valuesll\"Type 1 for Yes and 0 for NO"I
120 INPUT rich,tall,fair
130 IF ri ch OR taL LAND fai r THEN PRINT "YES"
140 IF ri ch OR <taL LAND fai r) THEN PRINT "AYE"
Whatever combination of three zeroes or ones you input at line 120 the output will be either nothing or:
YES
AYE
You can make sure that you test all pOSSibilities by entenng data which forms eight threedigit binary numbers 000 to 111:
000 001 010 011 100 101 110 111
12/84
•
•
•
•
•
•
4.
5.
1.
2.
3.
Place ten numbers in a than 20 then print It.
DATA
statement.
READ
each number and If it is greater
Test all the numbers from 1 to 100 and print only those which are perfect squares or divisible by 7
Toys are described as Safe (S), or Unsafe (U), Expensive (E) or Cheap (C), and either for Girls (G), Boys (B) or Anyone (A). A tno of letters encodes the qualities of each toy. Place five such trios in a
DATA
statement and then search it printing only those which are safe and suitable for girls.
Modify program 3 to print those which are expensive and not safe.
Modify program 3 to print those which are safe, not expensive and suitable for anyone.
PROBLEMS ON
CHAPTER 10
12/84
57
58
CHAPTER 11
HANDLING
TEXT
STRINGS
You have used string variables to store character strings and you know that the rules for manipulating string variables or string constants are not the same as those for numeric variables or numeric constants SuperBASIC offers a full range of facilities for manipulating character strings effectively. In particular the concept of string-slicing both extends and simplifies the business of handling substrings or slices of a string.
ASSIGNING
STRINGS
Storage for string variables is allocated as it is required by a program. For example, the lines: .
100 LET words$
110 LET words$
=
"LONG"
=
"LONGER"
120 PRINT words$ would cause the six letter word, LONGER, to be printed. The first line would cause space for four letters to be allocated but this allocation would be overruled by the second line which requires space for six characters.
It is, however, possible to dimension (i.e. reserve space for) a string variable, in which case the maximum length becomes defined, and the variable behaves as an array.
JOINING STRINGS
You may wish to construct records in data processing from a number of sources. Suppose, for example, that you are a teacher and you want to store a set of three marks for each student in Literature, History, and Geography. The marks are held in variables as shown:
0
l i l $ 0 h i s t $ 0 geog$
As part of student record keeping you may wish to combine the three string values Into one six-character string called mark$.
You simply write:
LET mark$ = l i t$ & hi st$ & geog$
You have created a further variable as shown: mark$!625671
I
But remember that you are dealing with a character string which happens to contain number characters rather than an actual number. Note that in SuperBASIC the & symbol is used to jOin strings together, whereas In some other BASICs, the + symbol IS used for that pu rpose
COpy ASTRING
SLICE
A string slice is part of a string.
It may be anything from a single character to the whole string. In order to identify the string slice you need to know the positions of the required characters.
Suppose you are constructing a children\> game in which they have to recognise a word hidden in a jumble of letters. Each letter has an internal number an index corresponding to its position in the string. Suppose the whole string is stored in the variable
iumble$,
and the clue is Big cat jumble$ A P Q sIring slice a
L L
I a
N
A T S
U
Z
2 3 4 5 6 7 8 9 10 11 12 13 14
12/84
•
•
•
•
Handing Text
•
•
•
You can see that the answer is defined by the numbers 6 to 9 which Indicate where it is. You can abstract the answer as shown:
100 j umb Le$
110 LET an$
120 PRINT an$
=
"APQOLLIONATSUZ"
= jumbLe$(6 TO 9)
Now suppose that you wish to change the hidden animal into a bull. You can write extra lines: two
130 LET jumble$(6 TO 9)
140 PRINT jumbLe$
=
"BULL"
The output from the whole five-line program is:
LION
APQOLBULLATSUZ
All string variables are initially empty, they have length zero. If you attempt to copy a string into a string-slice which has insufficient length then the assignment may not be recognised by SuperBASIC.
If you wish to copy a string into a string-slice then it IS best to ensure the destination string is long enough by padding it first with spaces.
100 LET subject$
110 LET student$
=
"ENGLISH MATHS COMPUTING"
="
120 LET student$(9 TO 13)
= subject$(9 TO 13)
We say that "BULL' is a slice of the string ':A,POOLBULLATSUZ': The defining phrase:
(6 TO 9) is called a slicer. It has other uses. Notice how the same notation may be used on both sides of the LET statement. If you want to refer to a single character it would be clumsy to write: jumbLe$(6 TO 6) just to pick out the "B" (possibly as a clue) so you can write instead : jumbLe$(6) to refer to a single character.
Suppose you have a variable,
markS
holding a record of examination marks. The slice giving the history mark may be extracted and scaled up, perhaps because the history teacher has been too strict in the marking. The following lines will extract the history mark:
100 LET mark$
110 LET hi st$
=
"625671"
= mark$(3 TO 4)
The problem now is that the value "56" of the variable, hist$ is a string of characters not numeric data. If you want to scale it up by multiplying by, say, 1.125, the value .of
hist$ must be converted to numeric data first, SuperBASIC will do this conversion automatically when we type:
120 LET num
=
1.125
* hist$
Line 120 converts the string "56" to the number 56 and multiplies it by 1.125 giving 63.
Now we should replace the old mark by the new mark but now the new mark is still the number 63 and before it can be inserted back into the original string it must be converted back to the string
'63:
Again SuperBASIC will convert the number automatically when we type:
130 LET mark$(3 TO 4)
140 PRINT mark$
= num
The output from the whole program is:
626371 which shows the history mark increased to 63.
REPLACE ASTRING
SLICE
COERCION
12184 59
Handling Text
Strictly speaking It is Illegal to mix data types in a LET statement. It would be silly to write:
LET num
=
"LION" and you would get an error message If you tried, but if you write:
LET num
=
"65 11 the system will conclude that you want the number 65 to become the value of num and do that. The complete program is:
100 LET mark$
=
"625671"
110 LET hist$
120 LET num
= mark$(3 TO 4)
=
1.125 * hist$
130 LET mark$<3 TO 4)
= num
140 PRINT mark$
Again the output is the same!
In line 120 a string value was converted Into numeric form so that it could be multiplied;
In line 130 a number was converted Into string form. ThiS converting of data types is known as type coercion.
You can write the program more economically if you understand both string-slicing and coercion now:
100 LET mark$ = "625671"
110 LET mark$<3 TO 4)
=
1.125 * mark$<3 TO 4)
120 PRINT mark$
If you have worked with other BASICs you will appreciate the simplicity and power of string-slicing and coercion.
SEARCHING A
STRING
You can search a string for a given substring. The follOWing program displays a jumble of letters and invites you to spot the animal.
100 REM Animal Spotting
110 LET jumbLe$
=
"SYNDICATE"
120 PRINT jumbLe$
130 INPUT IIWhat ;s the animaL?"
!
an$
140 IF an$ INSTR jumble$ AND an$(l)
=
"C"
150 PRINT "Correct"
150 ELSE
170 PRINT "Not correct"
180 END IF
The operator INSTR, returns zero if the guess is Incorrect. If the guess is correct INSTR returns the number which is the starting pOSition of the string-slice, in this case 6.
Because the expression: an$ INSTR jumbLe$ can be treated as a logical expression the position of the string in a successful search can be regarded as true, while in an unsuccessful search it can be regarded as false.
OTHER STRING
FUNCTIONS
You have already met LEN which returns the length (number of characters) of a string.
You may wish to repeat a particular string or character several times. For example, if you wish to output a row of asterisks, rather than actually enter forty asterisks in a PRINT statement or organise a loop you can simply write:
PRINT FILL$ ("*".40l
Finally it is possible to use the function CHR$ to convert internal codes into string characters. For example:
PRINT CHR$(65) would output A.
12/84
•
•
•
A great deal of computing is concerned with organising data so that it can be searched qUickly. Sometimes it is necessary to sort it in to alphabetical order. The basis of various sorting processes is the facility for comparing two strings to see which comes fllst
Because the letters AB,C... are internally coded as 65,66,67. .. It is natural to regard as correct the following statements:
A is less than B
B is less than C
COMPARING
STRINGS
and because internal character by character comparison is automatically provided:
CAT is less than DOG
CAN is less than CAT
You can write, for example:
IF "CAT" < "DOG" THEN PRINT "MEOW" and the output would be:
MEOW
Similarly:
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www,mauritron,co,uk
TEL: 01844·
3~1694
FAX: 01844 352554
IF "DOG" > "CAT" THEN PRINT "WOOF" would give the output:
WOOF
We use the comparison symbols of mathematics for string comparisons, All the following logical statements expressions are both permissible and true,
"ALF"
IlK!T"
"PAT"
< "BEN"
> "BEN"
"KIT" <= "LEN"
IIK!T" >= "KIT"
"PAT" >= "LEN"
"LEN" <: "LEN"
<> "PET"
So far, comparisons based simply on internal codes make sense, but data is not always conveniently restricted to upper case letters. We would like, for example:
Cat to be less than COT and K2 N to be less than K27.N
A simple character by character comparison based on internal codes would not give these results, so SuperBASIC behaves in a more intelligent way, The following program, with suggested input and the output that will result, illustrates the rules for comparison of strings,
100 REMark comparisons
110 REPeat camp
120 INPUT "input a string" !
fi rst$
130
140
INPUT "input another string"
!
secondS
IF fi rst$
<
secondS THEN PRINT "Less"
150
160
IF fi rst$
IF first$
>
secondS THEN PRINT "Greater"
= secondS THEN PRINT "EquaL"
17.0 END REPeat camp input output
CAT
CAT car
Greater
CAT Equal
Less PET PETE
K6
K66
K7.
K7.
K12N K6N
Less
Greater
Greater
Log"
62
LGgIC
>
Greater than - Case dependent compaflsion, numbers compared In numerical order.
<
Less than - Case dependent, numbers compared in numerical order
=
Equals - Case dependent, stflngs must be the same
-Equivalent String must be 'almost" the same, Case independent, numbers compared in numerical order.
>
= Greater than or equal to - Case dependent, numbers compared in numerical order
<=
Less than or equal to - Case dependent, numbers compared in numerical order.
PROBLEMS ON
CHAPTER 11
1.
Place 12 letters, all different, in a string variable and another SIX letters in a second string variable. Search the first string for each of the six letters in turn saying in each case whether it is found or not found.
2.
Repeat using single character arrays instead of strings. Place twenty random upper case letters in a string and list those which are repeated.
3.
Write a program to read a sample of text all in upper case letters. Count the frequency of each letter and print the results.
4.
5.
"GOVERNMENT IS A TRUST, AND THE OFFICERS OF THE
GOVERNMENT ARE TRUSTEES; AND BOfH THE TRUST AND THE
TRUSTEES ARE CREATED FOR THE BENEFIT OF THE PEOPLE. -
HENRY CLAY, 1829."
Write a program to count the number of words in the following text. A word is recognised because it starts with a letter and is followed by a space, full stop or other punctuation character.
"THE REPORTS OF MY DEATH ARE GREATLY EXAGGERATED. -
CABLE FROM MARK TWAIN 10 THE ASSOCIATED PRESS, LONDON
1896:'
Rewrite the last program illustrating the use of logical variables and procedures.
•
•
•
12/84
•
•
•
•
CHAPTER 12
SCREEN
OUTPUT
SuperBASIC has so extended the scope and variety of facilities for screen presentation that we describe the features In two sections: Simple Printing and Screen.
The first section describes the output of ordinary text Here we explain the minimal well established methods of displaying messages, text, or numerical output. Even in thiS mundane section there IS innovation in the concept of the 'intelligent' space - an example of combining ease of use with very useful effects.
The second section is much bigger because it has a great deal to say. The wide range of features actually makes things easier For example, you can draw a circle by simply writing the word CIRCLE followed by a few details to define such things as its position and size. Many other SyStems recuire you to understand some geometry and trigonometry in order to do what is, in concept, simple.
Each keyword has been carefully chosen to relect the effect it causes. WINDOW defines an area of the screen; BORDER puts a border round it; PAPER defines the background colour; INK determines the colour of what you put on the paper
If you work through this chapter and get a little practice you will easily remember which keyword causes which effect. You will add that extra quality to your programming fairly easily. With experience you may see why computer graphics is becoming a new art form.
The keyword PRINT can be followed by a sequence of print items. A print item may be any of: text such as: "This is text" variables such as: num, wordS expressions such as: 3
*
num, dayS & weekS
Print items may be mixed in any print statement but there must be one or more print separators between each pair Print separators may be any of:
No effect it just separates print items.
Normally inserts a space between output items. If an item will not fit on the current line it behaves as a new line symbol. If the item is at the start of line a space is not generated.
\
A tabulator causes the output to be tabulated in columns of 8 characters
A new line symbol will force a new line.
10 Allows tabbing.
The numbers 1,2,3 of print separators are legitimate print items and are convenient for illustrating the effects
SIMPLE PRINTING
Statement
100 PRINT 1,2,3
100 print 1'2!3'
100 PRINT 1 \2\3
100 PRINT 1 ;2;3
100 PRINT "This is text"
100 LET word$
=
II II
110 PR I NT wo rd$
100 LET num = 13
110 PRINT num
100 LET an$
110 PRINT "I
=
"yes" say"
I an$
110 PRINT "Sum ;5" , 4 + 2
Effect
2
2 3
1
2
3
123
This ; s text moves print position
3
13
I say yes
Sum is 6
63 12/84
54
Screen Output
You can position print output anywhere on the screen with the AT command.
For example:
AT 10,15 : PRINT "This is on row 10 at coLumn 15"
The CURSOR command can be used to pOSition the print output anywhere on the screen's scale system. For example:
CURSOR 100,150: PRINT "this is 100 pixel grid units across and
150 down"
If you read the Keyword Reference Guide you may find It difficult to reconcile the section on PRINT with the above description. Two at the difficulties disappear if you understand that:
Text in quotes, vanables and numbers are all strictly speaking, expressions; they are the simplest (degenerate) forms of expressions.
Print separators are strictly classified as print items.
SCREEN
This section introduces general effects which apply whether you wish to output text or graphics. The statement: '
MODE 8 or MODE 256 will select MODE 8 in which there are:
256 pixels across numbered 0-511 (two numbers per pixel)
256 pixels down numbered 0-255
8 colours
A pixel is the smallest area of colour which can be displayed. We use the term, solid colour because these start with ordinary solid-looking colours of which there are only eight. However, by uSing various effects a variety of shades and textures can be achieved.
If you are using your OL with an ordinary television set then the television set Will not be able to reproduce any of these extra effects.
The statement:
MODE 4 or MODE 512 will select MODE 4 in which there are:
512 pixels across numbered 0 to 511
256 pixels down numbered 0 to 255
4 colours
COLOUR
You can select a colour by using the follOWing code in combination with suitable keywords such as PAPER, INK etc Note that the numbers by themselves mean nothing. The numbers are only interpreted as colours when they are used with PAPER and INK, etc.
8 Colour Mode Code 4 Colour Mode black blue red magenta green cyan yellow white
0
1
2
3
4
5
6
7 black black red red green green white white
Colour Codes
For example INK 3 would give magenta in MODE 8.
STIPPLES
You can if you wish specify two colours in a suitable statement. For example 2,4 would give a chequerboard stipple as shown. In each group of four pixels two would be red
(code 2) corresponding to the colour selected first. The other two pixels would be a contrast. It is not really pOSSible to display this effect on a domestic televiSion set.
12/84
•
•
•
•
•
• red contrast
If you write:
INK 2,4 the miX colour is formed from the two codes 2 and 4. We will call these choices colour and contrast'
INK colour, contrast
You can find out what the stipple effects are by trying them but we give more technical details below.
100 REMark CoLour/Contrast
110 FOR coLour = 0 TO 7 STEP 2
120
140
150
PAPER coLour: CLS
FOR cant rast = 0 TO 7 STEP 2
BLOCK 100,50,40,50,coLour,contrast
160
170
PAUSE 50
END FOR contrast
180 END FOR coLour
If you wish to try different stipples you can add a third code number to the colour specification. For example:
INK 2,4,1 would specify a red and green horizontal stripe effect A block of four pixels would be:
•
The possible effects are shown using red and contrast
D.
Effect Code Name
0 Single pixel of contrast
Horizontal Stripes
2
3
Vertical Stripes
Chequerboard
~
Stipple Patterns
12/84
SCreen Output
65
COLOUR
PARAMETERS
66
PAPER 2
PAPER 2,4
PAPER 2,4,1
Ired]
[red/green chequerboardJ
[red/green horizontal strlpesJ
The colour will not be visible until something else IS done, for example, the screen is cleared by typing CLS.
INK
INK followed by one, two or three numbers specifies the colour for printing characters, lines or other graphics. The colour and stipple effects are the same as for PAPER. For example:
INK
INK
INK
2
2,4
2,4,1
[red ink]
[red/green chequerboard ink 3J
Ired/green horizontal striped inkl
The ink Will be changed for all subsequent output
CLS
CLS means clear the window to the current paper colour like a teacher cleaning a blackboard, except that it IS electronic and multi-coloured.
FLASHING
You can make the ink colour flash in mode 8 only. To turn flash on you might type:
FLASH 1 and to turn It off:
FLASH 0
Allowing flashing characters to overlap can produce alarming results.
FILES
You will have used Microdrives for storing programs and you Will have used the commands LOAD and SAVE Cartridges can be used for storing data as well as programs. The word file usually means a sequence of data records, a record being some set of related information such as name, address and telephone number
Two of the most widely used types of file are serial and direct access files. Items In a serial file are usually read in sequence starting with the first If you want the fiftieth record you have to read the first forty-nine in order to find it On the other hand the fiftieth record in a direct access file can be found quickly because the system does not need to work through the earlier records to get it Pop music on a cassette is like a serial file but eight pieces on a long playing record form a direct access file, You can move the pick up arm directly onto any of the eight tracks.
The simplest possible type of file is just a sequence of numbers. To illustrate the idea we will place the numbers 1 to 100 in a file called numbers.
However, the complete file name is made up of two parts: device name appended information
12/84
•
•
•
•
SCreen Output
•
•
•
Suppose that we wish to create the file, numbers, on a cartridge in Microdrlve 1. The device name is: mdv1 and the appended information is Just the name of the file: numbers
So the complete file name IS: mdv1 numbers
It is possible for a program to use several files at once, but it IS more convenient to refer to a file by an associated channel number This can be any Integer in the range 0 to
15. A file is associated with a channel number by using the OPEN statement or, if it
IS a new file, OPEN_NEW. For example you may choose channel 7 for the numbers file and write:
OPEN NEW #7 ,mdv1 numbers 1-
~flle
-
I device channel number
1 ---------~ keyword
CHANNELS
You can now refer to the file just by quoting the number # 7. The complete program is:
100 REMark SimpLe fi Le
110 OPEN NEW #7, mdv1 numbers
120 FOR number = 1 to 100
130 PRINT #7, number
140 EN D FOR numbe r
150 CLOSE #7
The PRINT statement causes the numbers to be 'printed' on the cartridge file because
# 7 has been associated with It. The CLOSE # 7 statement is necessary because the system has some internal work to do when the file has been used. It also releases channel
7 for other possible uses. After the program has executed type:
DIR mdv1 and the dICectory should show that the file numbers exists on the cartridge In Mlcrodrive rndv1_.
You also need to know that the file IS correct and you can only be certain of this if the file is read and checked. The necessary keyword IS OPEN_IN, otherwise the program for reading data from a file is similar to the prevIous one.
100 REMark Reading a fi Le
110 OPEN IN #6, mdv1 numbers
120 FOR item
=
1 TO 100
130 INPUT #, number
140 PRINT
I number I
150 END FOR item
160 CLOSE #6
The program should output the numbers 1 to 100, but only If the cartridge containing the file numbers IS still in Microdrive mdv1_.
You have seen one example of a device, a file of data on a Microdrive. We may say, loosely, that a file has been opened but strictly we mean that a device has been associated with a particular channel. Any further necessary information has also been provided.
Certain deVices have channels permanently associated with them by the system:
DEVICES AND
CHANNELS
channel
#0
#1
#2 use
OUTPUT command window
INPUT keyboard
OUTPUT print window
LIST list output
12184
67
Screen Output
WINDOWS
You can create a window of any size anywhere on the screen. The device name for a window is: scr and the appended information is, for example: down value across value height width
The following program creates a window with the channel number 5 and fills it with green (code 4) and then closes it:
100 REMark Create a window
110 OPEN #5, ser 400x200a20x50
120 PAPER #5,4 :-CLS #5
130 CLOSE #5
Notice that each window can have its own features such as paper, ink, etc. The fact that a window has been opened does not mean that it is the current default window.
You can change the position or shape of an opened window without closing it and reopening it Try adding two lines to the previous program:
124 WINDOW #5,300,100,110,65
126 PAPER #5,2 : CLS #5
Re-run the program and you will find a red window within the original green one. This red window is now the one associated with channel 5, see figure.
•
•
68
BORDER
You can place a border round the edge of the screen or a window. For example:
BORDER #5,6 would create a border round the channel # 5 window. It would be 6 units thick and the size of the window would be correspondingly reduced. The border would be transparent, protecting anything that was under it: You can speCify a coloured border by the usual method.
BORDER #5,6,2 would produce a red border You can make a border of other colours and textures by the usual methods. For example,
BORDER 10 will add a 10 pixel thick transparent border to the current window (transparent because no colour was specified) and .
BORDER 2,0,7,0 will add a 2 pixel thick black and white stipple border
•
•
12/84
Screen Output
•
•
•
You can specify a block's size, pOSition and colour with a single statement It is placed in the pixel co-ordinate system relative to the current window or screen. For example:
BLOCK #5,10,20,50,100,2 would create a block in the # 5 window at a position 50 units across and 100 units down. It would be 10 units wide and 20 units high. Its colour would be red.
It is worth noting that WINDOW and BLOCK statements work without alteration In 4 and 8 colour mode (though the colours may vary) because the across values are always on a 0 to 511 scale and there are always 256 pixel positions down_
BLOCK
You can alter the size of characters. For example:
CSIZE3,1
Will give the largest possible characters and:
CSIZE 0,0 will give the smallest. The first number must be 0,1,2 or 3 and determines the width.
The second must be 0 or 1 and determines the height. The normal sizes are:
MODE 4 CSIZE 0,0
MODE 8 CSIZE 2,0
SPECIAL PRINTING
CSIZE
The number of lines and columns available for each character size is dependent on whether the output is viewed on a monitor or on a television set; the row and column sizes given are for a monitor; those for a television set will be smaller and also Will vary between different televisions.
If you are using low resolution mode the OL will not allow you to select a character size smaller than default size.
You can provide a special background for characters to make them stand out. For example:
STR I P 7 will give a white strip while
STRIP 2,4,2 will give a red/green vertical striped strip. All the normal colour combinations are possible.
STRIP
OVER
Normally printing occurs on the current paper colour You can alter this by using strip.
You can make further effects by using:
OVER 1
OVER -1
1 prints in ink on a transparent strip
-1 prints in ink over existing display on screen
To revert to normal printing on current strip use:
OVER 0
UNDER
You can underline characters.
UNDER 1
UNDER 0 underlines all subsequent output in the current ink
SWitches off underling.
SCALE GRAPHICS
If you wish to draw reasonably true geometric figures on a 1V or video screen you cannot easily use a pixel-based system. If you use scale graphics then the system will do the necessary work to ensure that you can fairly easily draw reasonable crrcles, squares and other shapes.
,
The default scale of the graphics coordinate system is 100 in the vertical direction and whatever is needed in the across direction to ensure that shapes drawn with the special graphics keywords (PLOT, DRAW, CIRCLE,) are true.
The graphics origin is not the same as the pixel origin which is used to define the position of windows and blocks The graphics origin is at the bottom left hand corner of the current screen or window
12/84 69
POINTS AND LINES
It is easy to draw points and lines uSing scale graphics. Using a vertical scale of 100 a point near the centre of the window can be plotted With:
POINT 60,50
The point (60 units across and 50 units up) Will be plotted in the current ink colour.
Similarly a line may be drawn with the statement:
LINE 60,50 TO 80,90
Further elements can be added. For example, the follOWing will draw a square:
LINE 60,50 TO 70,50 TO 70,60 TO 60,60 TO 60,50
•
70
____
~~~c~~~~
,
,
,
,
I
,
,
,
,
,
, c=J up 50
RELATIVE· MODE
Pair of coordinates such as across, up normally define a point relative to the origin 0,0 in the bottom left hand corner of a window
(or elsewhere if you choose). It is sometimes more convenient to define points relative to the current cursor position. For example the square above may be plotted in another way using the L1NE_R statement which means:
"Make all pairs of coordinates relative to the current cursor position:'
POINT 60,50
LINE_R 0,0 TO 10,0 TO 0,10 TO -10,0 TO 0,-10
First the point 60,50 becomes the origin, then, as lines are drawn, the end of a line becomes the origin for the next one.
The following program will plot a pattern of randomly placed coloured squares.
100 REMark Coloured Squares
110 PAPER 7 : CLS
120 FOR sq
=
1 TO 100
130 INK RND (1 TO 6)
140
150
POINT RND(90), RND(90)
LINE R 0,0 TO 10,0 TO 0,10 TO -10,0 TO 0,-10
160 END FOR sq
The same result could be achieved entirely with absolute graphics but it would require a little more effort.
CIRCLES AND
ELLIPSES
If you want to draw a circle you need to specify: position say 50,50 radius say 40
The statement
CIRCLE 50,50,40 will draw a circle with the centre at position 50,50 and radius (or height) 40 units, see figure:
•
•
•
12/84
•
40
-
---------'
(50,50)
•
A circle
If you add two more parameters: e,g, CIRCLE 50,50,40,.5
You will get an ellipse, The keywords CIRCLE and ELLIPSE are interchangeable
•
An ellipse
The height of the ellipse is 40 as before but the horizontal 'radius' is now only 0.5
of the height The number 0.5
is called the eccentricity, If the eccentricity is 1 you get a circle if it is less than 1 and greater than zero you get an ellipse, If you want to tilt an ellipse you can change the fith parameter for example:
CIRCLE 50,50,40,.5,1
This will tilt the ellipse anti-clockwise by one radian, about 57 degrees, as shown in figure
Screen Output
Ellipse at angle one radian
A straight angle IS 180 degrees or PI radians, so you can make a pattern of ellipses with the program:
100 FOR rot
=
0 TO 2*PI STEP PII6
110 CIRCLE 50,50,40,0.5, rot
120 END FOR rot
12184
71
Screen Output
T2
The order of the parameters for a circle or ellipse is: centre_across, centre_up, height, [eccentricity, angle]
The last two parameters are optional and this is indicated by putting them inside square brackets ( [ J ).
Example
Write a program which does the following:
1.
Open a window 100xl00 at (100,50)
4.
5.
6.
2.
Scale 100 in mode 8
3.
Select black paper and clear window
Make green border 2 units wide
Draw a pattern of
Close the window.
SIX coloured cl/cles.
100 REMark pattern
110 MODE 8
120 OPEN #7, scr 100xl00a 100x50
130 SCALE #7,100-;-0,0
140 PAPER #7,0 : CLS #7
150 BORDER #7,2,4
160 FOR colour = 1 TO 6
170 INK #7, colour
180 LET rot = 2*PI!caLaur
190 CIRCLE #7,50,50,30,O.5,rat
200 END FOR cataur
210 CLOSE #7
You can get some interesting effects by altering the program. For example try the amendments:
160 FOR coLour = 1 TO 100
180 LET rot
= calaur*PI/50
ARCS
If you want to draw an arc you need to decide: starting point end point amount of curvature.
The first two items are straightforward but the amount of curvature is not so easy. You can do it by drawing accurately or by trial and error but you must decide what angle the arc subtends and then specify the angle in radians. An angle of 1.5 radians would give a sharp bend and a small angle would give a very gentle curvature Try, for example:
ARC 10,50 TO 50,90,1 which gives a moderate curvature in the current INK colour.
•
•
• o
:
,- - - - - - - (50.90) angle
(10,50)
•
12/84
•
•
•
You can fill a closed shape with the current INK colour by simply writing:
FILL 1 before the shape is drawn. The following program produces a green Circle.
INK 4
F ILL 1
CIRCLE 50,50,30
The FILL command works by drawing touching horizontal lines between suitable points.
The statement:
FILL 0 will tum off the FILL effect:
FILL
You can scroll or pan the display in a window like a film cameraman. You arrange scrolling in terms ot pixels. A positive number of pixels indicates upwards scrolling, thus
SCROLL 10 moves the display in the current window or screen 10 pixels downwards.
SCROLL -8
Moves the display 8 pixels up. You can add a second parameter to induce part-scrolling.
SCROLL -8, 1
Will scroll the part above (not including) the cursor line and:
SCROLL -8,2 will scroll the part below (not including) the cursor line.
As scrolling occurs, the space left by movement of the display IS filled With the current paper colour A second parameter a has no effect:
You can PAN the display in the current window left or right: The PAN statement works in a similar manner to SCROLL but
PA N 40
PAN -40 moves display right moves display left
A second parameter gives a partial PAN a whole screen
3 - the whole of the line occupied by the cursor
4 - the right hand side of the line occupied by the cursor.
The area of the cursor is also Included.
If you are using stipples or are in 8 colour mode then windows must be panned or scrolled in multiples of 2 pixels.
SCROLLING AND
PANNING
1.
2.
Place the numbers 1 to 100 in the squares starting at the bottom left and place
F for finish in the last square.
3.
Write a program which draws a Snakes and Ladders' grid of ten rows of ten squares.
Draw a dartboard on the screen. It should consist of an outer ring which could hold numbers A 'doubles' ring and triples' ring as shown and a centre consisting of a 'bull's eye' and a ring around It:
PROBLEMS ON
CHAPTER 12
Screen Output
12/84 73
74
CHAPTER 13
ARRAYS
Suppose you are a prison governor and you have a new prison block which is called the West Block. It IS ready to receive 50 new pnsoners. You need to know which prisoner
(known by his number) is in which cell. You could give each cell a name but it is simpler to give them numbers 1 to 50.
In a computing simulation we will imagine just 5 prisoners with numbers which we can put in a DATA statement:
DATA 50, 37, 86, 41, 32
We set up an array of variables which share the name, west, and are distinguished by a number appended In brackets.
It m west(2)
II
west(l) west(3) west(4) west(5)
It is necessary to declare an array and give its dimensions with a DIM statement
DIM west(5)
This enables SuperBASIC to allocate space, which might be a large amount. After the
DIM statement has been executed the five variables can be used.
The convicts can be READ from the DATA statement into the five array variables:
FOR cell
=
1 TO 5: READ west(cell)
We can add another FOR loop with a PRINT statement to prove that the convicts are in the cells
•
• west (1) west(2) west(3) west(4) wes\(5)
The complete program is shown below:
100 REMark Prisoners
110 DIM west(5)
120 FOR cell
=
1 TO 5 : READ west(cell)
130 FOR cell
=
1 TO 5: PRINT cell
I west(celLJ
140 DATA 50, 37, 86, 41, 32
The output from the program is:
1 50
237
3 86
4 41
5 32
The numbers 1 to 5 are called subscripts of the array name, west The array, west, is a numeric array consisling of five numeric array elements.
You can replace line 130 by:
130 PRINT west
This will output the values only: o
50
37
86
41
32
The zero at the top of the list appears because subscripts range from zero to the declared number. We will show later how useful the zero elements in arrays can be.
Note also that when a numeric array is DIMensioned its elements are all given the value zero.
12/84
•
•
•
•
•
12/R4
String arrays are similar to numeric arrays but an extra dimension in the DIM statement speCities the length of each string variable In the array Suppose that ten of the top players at Royal Birkdale for the 1982 British Gol$'Championshlp were denoted by their first names and placed in DATA statements.
DATA "Tom", "Graham", IlS evvy ", "Jack ll
,
"Lee"
DATA "Nick", "Bernard", "Ben ll
,
"Gregg l
' ,
"Hal"
You would need ten different variable names, but If there were a hundred or a thousand players the job would become impossibly tedious. An array IS a set of variables designed to cope with problems of this kind. Each variable name consists of two parts: a name according to the usual rules a numeric part called a subSCript
Write the variable names as: flat$(1), flat$(2), fLat$(3) ...etc
Before you can use the array variables you must tell the system about the array and its dimensions:
DIM flat$(10,8)
This caUSes eleven (0 to 10) variables to be reserved for use in the program. Each string variable In the array may have up to eight characters. DIM statements should usually be placed all together near the beginning of the program. Once the array has been declared In a DIM statement all the elements of the array can be used. One important advantage is that you can give the numeric part (the subscript) as a numeriC variable.
You can write:
FOR number
=
1 TO 10: READ fLat$(number)
ThiS would place the golfers in their ilats:
Ilal$(1)
G
Ilal$(2)
I
Graham
I
Ilal$(3)
--~------------
0 lIal$(10)
Hal
You can refer to the variables in the usual way but remember to use the right subscript.
Suppose that Tom and Sevvy Wished to exchange flats. In computing terms one of them,
Tom say, would have to move into a temporary flat to allow Sevvy time to move. You can write:
LET temp$
= flat$(1J: REMark Tom into temporary
LET flat$(1)
= flat$(3): REMark Sevvy into flat$(1J
LET flat$(3)
= temp$: REMark Tom into flat$(3)
The following program places the ten golfers in an array named flat$ and prints the names of the occupants with their ilat numbers' (array subSCripts) to prove that they are in residence The occupants of flats 1 and 3 then change places. The list 01 occupants is then printed again to show that the exchange has occurred.
100 REMark Golfers' FLats
110 DIM flat$(10,8)
120 FOR number
=
1 TO 10: READ flat$(number)
130 printlist
140 exchange
150 printlist
160 REMark End of main program
170 DEFine PROCedure printList
180 FOR num = 1 TO 10 : PRINT num, flat$(num)
190 END DEFi ne
200 DEFine PROCedure exchange
210 LET temp$
= fLat$(1J
220
230
LET flat$(1) flat$(3)
LET f Lat$(3)
= temp$
240 END DEFine
250 DATA "Tom", "Graham", "Sevvy", IlJack", "Lee"
260 DATA "Nick", "Bernard", "Ben ll
,
"Greg", "HaL"
STRING ARRAYS
75
Arrays
output (line 130)
1 Tom
2 Graham
3 Sevvy
4 J ac k
5 Lee
6 N i c k
7 Bernard
8 Ben
9 Gregg
10 Ha L output (line 150)
1 Sevvy
2 Graham
3 Tom
4 J ac k
5 Lee
6 N i c k
7 Bernard
8 Ben
9 Gregg
10 Ha t
TWO DIMENSIONAL
ARRAYS
Sometimes the nature of a problem suggests two dimensions such as 3 floors of 10 flats rather than Just a single row of 30.
'
Suppose that 20 or more golfers need flats and there IS a block of 30 flats divided Into three floors of ten flats each. A realistic method of representing the block would be with a two-dimensional array. You can think of the thirty variables as shown below: flat$(2.Q) flat$(2,1) flat$(2,2) flat$(2,0)
D D =~~~~s~~~:~~~~~~~D flat$(1,0) flat$(1,1) f1at$(1,2) flat$(1,9)
D D =~~~~~~~S~(~)~~~~~~D flat$(O,O) flat$(0,1) flat$(0,2) flat$(0,9)
D D =~~~~~~~:~~~~~~~D
Assuming DATA statements with 30 names, a sUitable way to place the names In the flats is:
120 FOR floor = 0 TO 2
130 FOR num = 0 TO 9
140 READ fLats$(fLoor. num)
150 END FOR num
160 END FOR f toor
You also need a DIM statement:
20 DIM fLat$(2.9.8) which shows that the first subscript can be from 0 to 2 (floor number) and the second subscript can be from 0 to 9 (room number). The third number states the maximum number of characters in each array element
We add a print routine to show that the golfers are in the flats and we use letters to save space.
100 REMark 30 Golfers
110 DIM flat$(2,9,8)
120 FOR floor = 0 TO 2
130 FOR num = 0 TO 9
140
150
READ flat$(floor,num) REMark GoLfer goes in
END FOR num
160 END FOR fLoor
170 REMark End of input
180 FOR floor
=
0 TO 2
190 PRINT "FLoor number"
I fLoor
12/84
•
•
•
•
•
•
200
210
FOR num = 0 TO 9
PRINT 'FLat'
I num
I fLat$(floor,num)
220 END FOR num
230 END FOR fLoor
240 DATA "AII,"B","C",IID","E",IIF","G","H","I","JII
250 DATA "K","L","M","N","O","P","QII,"R","S",IlTII
260 DATA "U", "V", "W", "X'I, "yII, liZ", II@","£","$",'I%"
The output starts:
FLoor number 0
FLat 0 A
FLat 1 B
FLat 2 C and continues giving the thirty occupants.
You may find this section hard to read though It IS essentially the same concept as strlngslicing. You will probably need string-slicing if you get beyond the learning stage of programming. The need for array-slicing is much rarer and you may wish to omit this section particularly on a first reading.
We now use the golfers' flats to illustrate the concept of array sliCing. The flats will be numbered 0 to 9 to keep to single digits and names will be single characters for space reasons.
2,0 2,1 2,2 2,2 3,4 2,5 2,6 2,7 2,8 2,9 flat$0~G0[2]0[!]00~
1,0 1,1 1,2 1,3 1,4 1,5 1,6 1,7 1,8 1,9 flat$0~00G0000[2]
•
Given the above values the follOWing are array slices: fLat$(1,3) f Lat$ (1,1 TO 6)
Means a single array element with value N
Means six elements with values L M N 0 P Q
Array Element fLat$(1,1J fLat$(1,2) fLat$(1,3) flat$(1,4) flat$(1,5) flat$(1,6)
Value
0
P
Q
L
M
N flat$(1J
Means flat$ (1,0 TO 9) ten elements with values K L M N 0 P Q R S T
In these examples a range of values of a SUbscript can be given instead of a single value. If a subscript is missing completely the complete range is assumed. In the third example the second subscript is missing and it is assumed by the system to be a TO 9.
The techniques of array sliCing and string sliCing are similar though the latter is more widely applicable.
1?l84
77
Arrays
78
PROBLEMS ON
CHAPTER 13
1.
2.
3.
SORTING
Place ten numbers in an array by reading from a DATA statement Search the array to find the lowest number. Make this lowest number the value of the first elemenf of a new array. Replace it in fhe first array with a very large number. Repeat this process making the second lowest number the second value In the new array and so on until you have a sorted array of numbers which should then be printed.
SNAKES AND LADDERS
Represent a snakes and ladders game with a 100 element numeric array. Each element should contain either: zero or a number in the range 10 to 90 meaning that a player should transter to that number by going 'up a ladder' or down a snake: or the digits 1, 2, 3, etc. to denote a particular player's position.
Set up SIX snakes and six ladders by placing numbers In the array and simulate one 'solo' run by a single player to test the game.
CROSSWORD BLANKS columns row
2
3
4
5
4.
5.
6.
Crosswords usually have an odd number ot rows or columns in which the black squares have a symmetrical pattern. The pattern IS said to have rotational symmetry because rotation through 180 degrees would not change it
Note that after rotation through 180 degrees the square In row 4, column 1 could become the square in row 2, column 5. That IS row 4, column 1 becomes row
2, column 5 in a 5 X 5 grid.
Write a program to generate and display a symmetrical pattern of this kind.
Modify the crossword pattern so that there are no sequences, across or down, of less than four white squares.
CARD SHUFFLE
Cards are denoted by the numbers 1-52 stored in an array. They can be converted easily to actual card values when necessary. The cards should be 'shuffled' as follows.
Choose any position in range 1-51 e.g. 17.
Place the card in this position In a temporary store.
Shunt all the cards in positions 52 to 18 down to positions 51 to 17.
Place the chosen card from the temporary store to position 52.
Deal similarly With the ranges 1-50, 1-49 .. down to 1-2 so that the pack is well shuffled.
Output the result of the shuffle.
Set up six DATA statements each containing a surname, initials and a telephone number (dialling code and local number). Decide on a suitable structure of arrays to store this information and READ It into the arrays.
PRINT the data using a separate FOR loop and explain how the input format
(DATA), the Internal format (arrays) and output format are not necessarily all the same.
•
•
•
•
•
•
•
CHAPTER
14
PROGRAM
STRUCTURE
In this chapter we go again over the ground of program structure: loops and decisions or selection. We have tried to present things in as simple a way as possible but
SuperBASIC is designed to cope properly with the simple and the complex and all levels in between. Some parts of this chapter are difficult and if you are new to programming you may wish to omit parts . The topics covered are:
Loops
Nested loops
Binary decisions
Multiple decisions
The latter parts of the first section, Loops, get difficult as we show how SuperBASIC copes with problems that other languages simply ignore. Skip these parts If you feel so inclined but the other sections are more straightforward.
In this section we attempt to Illustrate the well-known problems of handling repetition with simulations of some Wild West scenes. The context may be contrived and trivial but it offers a simple basis for discussion and it illustrates difficulties which arise across the whole range of programming applications.
A bandit is holed up in the Old School House. The sheriff has six bullets in his gun
Simulate the firing of the six shots.
EXAMPLE
1
100 REMark Western FOR
110 FOR bul Lets
=
1 TO 6
120 PRINT "Take aim"
130 PRINT !IF; re shot"
140 END FOR buLLets
Program
1
100 REMark Western REPeat
110 LET buL Lets = 6
120 REPeat bandit
130 PRINT "Take aim"
140
150
160
PRINT "Fire shot"
LET bullets
= buLLets-
IF buL Lets = 0 THEN EXIT
170 END REPeat bandit
Program 2
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVlCEf www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
Both these programs produce the same output:
Take aim
Fi re a shot is printed six times.
If, In each program the 6 is changed to any number down to 1 both programs still work as you would expect. But what if the gun is empty before any shots have been fired?
Suppose that someone has secretly taken all the bullets out of the sheriff's gun. What happens if you simply change the 6 to 0 in each program?
100 REMark Western FOR Zero Case
110 FOR buLlets
=
1 to 0
120 PRINT "Take aim"
130 PRINT "Fi re a
140 END FOR buLLets shot ll
This works correctly. There is no output The zero case behaves properly in SuperBASIC
100 REMark Western REPeat Fai Ls
110 LET bullets = 0
120 REPeat bandit
130
140
PRINT "Take a;m ll
PRINT "Fi re shot"
150
160
LET buLLets
IF buLLets
= bullets - 1
=
0 THEN EXIT bandit
170 END REPeat bandit
LOOPS
EXAMPLE
2
Program
1
Program 2
79 12/84
on
Program Structure
Program 3
The program fails in two ways:
1.
Take aim
Fi re a shot is printed though there were never any bullets.
2.
By the time the variable, bullets, IS tested in line 160 It has the value ~ 1 and It never becomes zero afferwards The program loops indefinitely. You can cure the infinite looping by re-wntlng line 160 :
160 IF bullets
<
1 THEN EXIT bandit
There IS an inherent fault In the programming which does not allow for the possible zero case. This can be corrected by plaCing the conditional EXIT before the PRINT statements.
100 REMark Western REPeat Zero Case
110 LET buLLets = 0
120 REPeat Bandit
130
140
IF buL Lets
=
0 THEN EXIT Bandi t
PRINT "Take aim 'l
150
160
PRINT "Fire shot"
LET buLLets = buLLets-1
170 END REPeat Bandi t
This program now works properly whatever the Initial value of bullets as long as It is a positive whole number or zero. Method 2 corresponds to the REPEAT ... UNTIL loop of some languages Method 3 corresponds to the WHILE .... ENDWHILE loop of some languages. However, the REPeaL END REPeat with EXIT is more flexible than either or the combination of both.
If you have used other BASICs you may wonder what has happened to the NEXT statement. We will re-Introduce It soon but you Will see that both loops have a Similar structure and both are named.
FOR
name
~
(statements)
END FOR name
(opening keyword)
(content)
(closing keyword)
REPeat
name
(statements)
END REPeal
name
In addition the REPeal loop must normally have an EXIT amongst the statements or
It will never end.
Note also that the EXIT statement causes control to go to the statement which is immediately affer the END of the loop
A NEXT statement may be placed in a loop. It causes control to go to the statement which is just affer the opening keyword FOR or REPeal. It should be considered as a kind of opposite to the EXIT statement. By a curious cOincidence the two words, NEXT and EXIT, both contain EXT Think of an EXTenSion to loops and:
N means 'Now start again'
I means 'It's ended'
EXAMPLE 3
The situation IS the same as In example 1. The shenff has a gun loaded with six bullets and he IS to fire at the bandit but two more conditions apply:
1.
2.
If he hits the bandit he stops flnng and returns to Dodge City.
If he runs out of bullets before he hits the bandit, he tells his partner to watch the bandit while he (shenff) returns to Dodge City
Program 1
[
100 REMark Western FOR with Epi Logue
110 FOR buL Lets = 1 TO 6
120
130
140
150
170
PRINT "Take aim"
PRINT "FIRE A SHOT"
LET hit
=
RND(9)
IF hit = 7 THEN EXIT buLLets
J
160 NEXT buLLets
PRINT "Watch Bandit"
180 END FOR buLLets
190 PRINT "Return to Dodge Cityll
12/84
•
•
•
•
•
•
• in this case, the content between NEXT and END FOR IS a kind of epilogue which
IS only executed if the FOR loop runs ItS full course. If there is a premature EXIT the epilogue is not executed.
The same effect can be achieved with a REPeat loop though it is not necessarily the best way to do it However it IS worth looking at (perhaps at a second reading) if you want to understand structures which are Simple enough to use In simple ways and powerful enough to cope with awkward situations when they arise.
100 REMark Western REPeat with Epi Logue
110 LET buLLets
=
6
120 REPeat Bandit
130
140
150
160
170
180
PRINT "Take aim"
PRINT "Fire shot"
LET hit
=
RND(9)
IF hit = 7 THEN EXIT Bandit
LET buLLets
IF buLLets
= bulLets-l
<>
0 THEN NEXT Bandit
190 PRINT "Watch Bandit"
200 END REPeat Bandit
210 PRINT "Return to Dodge City"
The program works properly as long as the sheriff has at least one bullet at the start.
It fails if line 20 reads:
110 LET buLLets = 0
You might think that the sheriff would be a fool to start an enterprise of this kind if he had no bullets at all, and you would be right We are now discussing how to preserve good structure In the most complex type of situation. We have at least kept the problem context simple; we know what we are trying to do. Complex structural problems usually arise in contexts more difficult than Wild West simulations. But if you really want a solution to the problem which caters for a possible hit, running out of bullets and an epilogue, and also the zero case then add the following line to the above program:
125 IF bulLets = 0 THEN PRINT "Watch Bandit" : EXIT bandit
We can conceive of no more complex type of problem than thiS with a Single loop.
SuperBASIC can easily handle it if you want it to.
Consider the following FOR loop which PLOTS a row of points of various randomly chosen colours (not black).
100 REMark Row of pixels
110 PAPER 0 : CLS
120 LET up
=
50
130 FOR across = 20 TO 60
140 INK RND (2 TO 7)
150 POINT across, up
160 END FOR across
This program plots a row of points thus:
Program 2
NESTED LOOPS
If you want to get say 51 rows of points you must plot a row for values up from 30 to
8D. But ycu must always observe the rule that a structure can go completely within another or it can go properly around it It can also follow in sequence, but it cannot 'mesh' with another structure. Books about programming often show how FOR loops can be related with a diagram like
Program Structure
Right
(nested)
Right
(sequence)
Wrong
(Meshed)
81 12/84
Program Structure
82
In SuperBASIC the rule applies to all structures. You can solve all problems uSing them properly We therefore treat the FOR loop as an entity and design a new program:
FOR up = 30 TO 80
FOR across ~ 20 TO 60
INK RND(2 To 7)
POINT across, up
END FOR across
END FOR up
When we translate this into a program we are entitled not only to expect It to work but to know what It will do. It will plot a rectangle made up of rows of pixels.
100 REMark Rows of pixeLs
110 PAPER 0 : CLS
1Z0 FOR up = 30 TO 80
130 FOR across = ZO TO 60
140
150
INK RND (Z TO 7)
POINT across,Up
160 END FOR ac ross
170 END FOR up
Different structures may be nested. Suppose we replace the Inner FOR loop of the above program by a REPeal loop. We will terminate the REPeat loop when the zero colour code appears for a selection In the range 0 to 7.
100 REMark REPeat in FOR
110 PAPER 0: CLS
1Z0 FOR up = 30 TO 80
130 LET across = 19
140
150
160
170
REPeat dot s
LET co tour
=
RND (7)
INK coLour
LET across:::; across + 1
180
190
POINT across, up
IF coLour = 0 then EXIT dots
ZOO END REPeat dots
Z10 END FOR up
Much of the wisdom about program control and structure can be expressed In two rules:
1.
Construct your program uSing only the legitimate structures for loops and decisionmaking.
2.
Each structure should be properly related in sequence or wholly within another.
BINARY DECISIONS
The three types of binary decision can be illustrated easily in terms of what to do when it rains.
100 REMark Short form IF
110 LET rain
=
RND(O TO 1)
120 IF rain THEN PRINT "Open brotty" ii.
100 REMark Long form IF ••• END IF
110 LET rain
=
RND<O TO 1)
1Z0 IF rain THEN
130
140
150
PRINT "Wear coat"
PRINT "Open brotly"
PRINT "WaLk fast"
160 END IF iii.
100 REMark Long form IF ... ELSE ••• END IF
110 LET rain
=
RND(O TO 1)
1Z0 IF rain THEN
130 PRINT "Take a bus"
140 ELSE
150 PRINT "Walk"
160 END IF
•
•
•
•
12/84
•
•
•
All these are binary decisions. The first two examples are simple either something happens or it does not. The third is a general binary decision with two distinct possible courses of acfion, both of which must be defined.
You can omit THEN in the long forms if you wish. In the short form you can substitute
: for THEN.
Consider a more complex example In which it seems natural to nest binary decIsions.
ThiS type of nesting can be confusing and you should only do It If it seems the most natural thing to do. Careful attention to layout particularly indenting, is espeCially Important.
Analyse a piece of text to count the number of vowels, consonants and other characters.
Ignore spaces. For simplicity the text is all upper case.
"COMPUTER HISTORY WAS MADE IN 1984"
EXAMPLE
Data
Read in the data
FOR each character:
IF letter THEN
IF vowel increase vowel count
ELSE increase consonant count
END IF
ELSE
IF not space THEN increase other count
END IF
END FOR
PRINT results
100 REMark Character Counts
110 RESTORE 290
120 READ text$
130 LET voweLs
140 FOR nurn
=
0: cons
=
0 : others
=
0
=
1 TO LEN (text [)
150 LET ch$ = text$(nurn)
160 IF ch$ >= "A" AND ch$
<=
liZ"
170
180
190
IF ch$ INSTR "AEIOU"
LET voweLs = voweL +
ELSE
200
210
220
230
LET cons
END IF
ELSE
IF ch$ <> ..
=
II cons + 1
THEN others:::: others + 1
240 END IF
250 END FOR nurn
260 PRINT "Vowel count is" !
vowels
270 PRINT "Consonent count i 5 11
!
cons
280 PRINT "Other count ;s" !
others
290 DATA "COMPUTER HISTORY WAS MADE IN 1984"
Design
Program
Vowel count is 9
Consonant count is 15
Other count is 4
Output
Where there are three or more possible actions and none is dependant on a previous choice the natural structure to use is SElect which enables selection from any number of possibilities.
MULTIPLE
DECISIONS
- SELect
A magic snake grows without limit by adding a section to ItS front. Each section may be up to twenty units long and may be a new colour or it may remain the same. Each new section must grow in one of the directions North, South East or West. The snake starts from the centre of the window.
EXAMPLE
Program Structure
83
12/84
84
Method At any time while the snake IS still on the screen you choose a random length and Ink colour easily. The direction may be selected by a number 1,2,3 or 4 as shown:
North 1
•
West 4 East 2
South 3
Design Select PAPER
Set snake to centre of window
REPeal
Choose direction, colour, length of growth
FOR unit ~ 1 to growth
Make snake grow, north, south, east or west
IF snake IS off window THEN EXIT
END FOR
END REpeal
PRINT end message
Program 100 REMark Magi c Snake
110 PAPER 0 : CLS
120 LET aCross = 50 : up = 50
130 REPeat snake
140
150
LET di rection = RND(1 TO 4)
LET growth = RND(2 TO 20>
160
170
INK coLour
FOR unit = 1 TO growth coLour RND(2 TO 7)
180
190
200
210
220
230
240
250
260
270
SELect ON direction
ON direction = 1
LET up = up + 1
ON direction =2
LET across = across + 1
ONdirection=3
LET up = up - 1
ON di rection = 4
LET across = across - 1
END SELect
280
290
IF across<1 OR across>99 OR up<1 OR up>99 THEN EXIT snake
POINT across,up
300 END FOR unit
310 END REPeat snake
320 PRINT "Snake off edge"
The syntax of the SElect ON structure also allows for the possibility of selecting on a list of values such as
5,6,8,10 TO 13
It IS also possible fo allow for an action to be executed If none of the stated values is found. The full structure is of the form given below
12/84
•
•
•
SELect ON num
ON num ~ list of values statements
ON num ~ list of values statements
LONG FORM
•
•
•
ON num ~ REMAINDER statements
END SELect where num IS any numeric variable and the REMAINDER clause is optional.
There IS a short torm of the SELect structure. For example
100 INPUT num
110 SElect ON num
=
0 TO 9 : PRINT "digit" will perform as you would expect
SHORT FORM
2.
3.
4.
5.
1.
Store 10 numbers in an array and pertorm a 'bubble-sort: This IS done by comparing the first pair and exchanging, If necessary, the second pair (second and third numbers), up to the ninth pair (ninth and tenth numbers) The first run of nine comparisons and possible exchanges guarantees that the highest number will reach
ItS correct position Another eight runs will guarantee eight more correct positions leaving only the lowest number which must be In the only (correct) position left.
The simplest form of 'bubble sort' of ten numbers requires nine runs of nine comparisons.
Consider ways of speeding up bubblesort, but do not expect that It will ever be very efficient
An auctioneer wishes to sell an old clock and he has instructions to invite a first bid of £50. If no-one bids he can come down to £40, £30, £20, but no lower in an effort to start the bidding. If no-one bids, the clock is withdrawn from the sale.
When the bidding starts, he takes only £5 Increases until the final bid is made.
If the final bid is £35 (the 'reserve price) or more, the clock is sold. Otherwise It
IS withdrawn.
Simulate the auction using the equivalent of a six-sided die throw to start the bidding.
A 'six' at any of the starting prices will start it off.
When the bidding has started there should be a three out of four chance of a higher bid at each invitation.
In a wild west shoot-out the Sheriff has no ammunition and wishes to arrest a gunman camped In a forest He rides amongst the trees tempting the gunman to fire. He hopes that when six shots have been fired he can rush in and overpower the gunman as he tries to re-Ioad. Simulate the encounter giving the gunman a one-twentieth chance of hitting the Sheriff with each shot If the Sheriff has not been hit after SIX shots he will arrest the gunman.
The Sheriff's Instructions to his Deputy are:
"If the gun is empty then re-Ioad it and if it ain't then keep on firing until you hit the bandit or he surrenders. If MexIco Pete turns up, get out fast:'
Write a program which caters properly for all these situations:
Whatever happens, return to Dodge City.
If MexIco Pete turns up, return immediately.
If the gun is empty, reload it
If the gun is not empty, ask the bandit to surrender
If the bandit surrenders, arrest him.
If he doesn't surrender, fire a shot
If the bandit is hit, arrest him and fiX hiS wound.
Assume an unlimited supply of ammunition. Use a simulated 'twenty-sided die' and let a seven mean 'surrender' and a 'thirteen' mean the bandit IS hit
PROBLEMS ON
CHAPTER 14
12/84
85
86
CHAPTER 15
PROCEDURES
AND
FUNCTIONS
In the first part ot this chapter we explain the more stralghtlorward features of SuperBtlSIC's procedures and functions. We do this with very simple examples so that you can understand the working of each feature as it IS described. Though the examples are simple and contrived you will appreciate that once understood, the Ideas can be applied in more complex situations where they really matter
Aher the first part there IS a discussion which attempts to explain Why procedures' .
If you understand, more or less, up to that pOint you will be doing well and you should be able to use procedures and functions with Increasing effectiveness.
SuperBASIC first allows you to do the simpler things in simple ways and then offers you more If you want It. Extra facilities and some technical matters are explained in the second part of thiS chapter but you could Omit these, certainly at a first reading, and still be
In a stronger position than most users of older types of BASIC
VALUE
PARAMETERS
You have seen in previous chapters how a value can be passed to a procedure. Here is another example.
EXAMPLE
In 'Chans Chinese Take-Away" there are Just SIX Items on the menu.
Rice Dishes
1 prawns
2 chicken
3 special
Sweets
4 ice
5 fritter
6 Iychees
Program
Output
Chan has a simple way of computing prices. He works in pence and the pnces are: for a nce dish 300 + 10 times menu number for a sweet 12 times menu number
Thus a customer who ate special nce and an Ice would pay:
300
+
10
*
3
+
12
*
4 = 378 pence
A procedure, Item, accepts a menu number as a value parameter and prints the cost.
100 REMark Cost of Di sh
110 item 3
120 item 4
130 DEFine PROCedure item(num)
140 IF num
<=
3 THEN LET price
=
300 + 10*num
150
160
IF num >= 4 THEN LET pri ce = 12*num
I price
I
170 END DEFine
330 48
In the main program actual parameters 3 and 4 are used. The procedure definition has a formal parameter, num, which takes the value passed to it from the main program.
Note that the formal parameters must be in brackets, but that actual parameters need not be.
EXAMPLE
Now suppose the working variable, pnce, was also used In the main program, meaning something else, say the price of a glass of lager, 70p. The following program fails to give the deSired result.
•
•
•
•
12184
Procedures and Functions
•
•
•
•
100 REMark Global price
110 LET price
=
70
120 item 3
130item4
140 PRINT
I price
I
150 DEFine PROCedure item(num)
160
170
180
IF num
IF num
<= 3 THEN LET pri ce = 300 + 10*num
>= 4 THEN LET pri ce = 12*num
I price
I
190 END DEFine
330 48 48
The price of the lager has been altered by the procedure. We say that the vanable, price, is global because It can be used anywhere in the program.
Program
Output
EXAMPLE
Make the procedure vanable, price, LOCAL to the procedure. This means that
SuperBASIC will treat it as a special vanable accessible only within the procedure. The vanable, price, In the main program will be a different thing even though it has the same name.
100 REMark LOCAL price
110 LET price
=
70
120 item 3
130item4
140 PRINT
I price
I
150 DEFine PROCedure item(num)
160
170
180
190
LOCal price
IF num
IF num
<= 3 THEN LET pri ce = 300 + 10*num
>= 4 THEN LET pri ce = 12*num
I price
I
200 END DEF i ne
330 48 70
ThiS time everything works properly. Line 70 causes the procedure variable, price to be Internally marked as 'belonging' only to the procedure, item.
The other vanable, price is not affected.
You can see that local variables are usetul things.
Program
Output
Local variables are so useful that we automatically make procedure formal parameters local. Though we have not mentioned it before parameters such as
num
In the above programs cannot interfere with main program variables. To prove this we drop the LOCAL statement from the above program and use
num
for the price of lager Because
num
in the procedure is local everything works.
100 REMark LOCAL parameter
110 LET num = 70
120 item 3
130 item 4
140 PRINT
I num
I
150 DEFine PROCedure item(num)
160 IF num <= 3 THEN LET price = 300 + 10*num
170 IF num >= 4 THEN LET pri ce = 12*num
180 PRINT
I price
I
190 END DEFine
330 48 70
EXAMPLE
Program
Output
So far we have only used procedure parameters tor passing values to the procedure.
But suppose the main program wants the cost ot an item to be passed back so that it can compute the total bill. We can do this easily by providing another parameter in the procedure call. This must be a variable because it has to receive a value from the procedure. We therefore call it a vanable parameter and it must be matched by a corresponding variable parameter in the procedure definition.
VARIABLE
PARAMETERS
12/84
87
88
Procedures and Functions
EXAM PLE
Use actual variable parameters, cosL 1 and cosL2 to receive the values of the variable price from the procedure. Make the main program compute and print the total bill.
Program
100 REMark Vari able parameter
110 LET num = 70
120 item 3,cost_1
130 item 4,cost 2
140 LET bi It = num + cost_1 + cost 2
150PRINTbili
160 DEFi ne PROCedure i tem(num, pri ce)
170 IF num
<=
3 THEN LET price
=
300 + 10*num
180 IF num >= 4 THEN LET pri ce = 12*num
190 END DEFine
Output
448
The parameters num and price are both automatically local so there can be no problems.
The diagrams show how information passes from main program to procedure and back
Menu numbers
Main
Program
..
Procedure
Item prices
That IS enough about procedures and parameters for the present.
FUNCTIONS
You already know how a system function works. For example the function:
SQRT(9) computes the value, 3, which is the square root of 9. We say the function returns the value 3. A function, like a procedure, can have one or more parameters, but the distinguishing feature of a function is that it returns exactly one value. This means that you can use it in expressions that you already have. You can type:
PRINT 2*SQRT(9) and get the output 6. Thus a function behaves like a procedure with one or more value parameters and exactly one variable parameter holding the returned value; that variable parameter is the function name itself.
The parameters need not be numeric.
LEN("string")
has a string argument but it returns the numeric value 6.
EXAMPLE
Re-wrlte the program of the last section which used price as a variable parameter. Let price be the name of the function.
Program
The value to be returned
IS defined by the RETurn statement as shown.
100 REMark FuNction with RETurn
110 LET num
120 LET biLL
= 70
= num + price(3) + pr;ce(4)
130 PRINT biLl
140 DEFine FuNction price(num)
150
160
IF num
IF num
<=
3 THEN RETurn 300 + 10*num
>= 4 THEN RETurn 12*num
170 END DEFine
Output
448
Notice the simplification in the calling of functions as compared with procedure calls.
•
•
•
•
12/84
Procedures and Functions
•
•
•
The ultimate concept of a procedure IS that It should be a 'black box' which receives speCific information from outside' and performs certain operations which may include sending speCific Information back to the outside: The outside' may be the main program or another procedure.
The term 'black box' Implies that ItS internal workings are not Important; you only think about what goes In and what comes out It. for example, a procedure uses a variable, count.
and changes its value, that might affect a variable of the same name in the main program Think of a mail order company You send them an order and cash; they send you goods. Information IS sent to a procedure and It sends back action and/or new
Information.
WHY
PROCEDURES?
Order by cash
..........
-----
•
Order
Company
Information
.........
Action and/or
•
-----
Procedure
You do not want the mall order company to use your name and address or other
Information for other purposes. That would be an unwanted Side-effect Similarly you do not want a procedure to cause unplanned changes to values of variables used in the main program.
Of course you could make sure that there are no double uses of variable names in a program. That will work up to a point but we have shown in this chapter how to avoid trouble even if you forget what variables have been used in any particular procedure.
A second aim In uSing procedures IS to make a program modular. Rather than have one long main program you can break the JOb down into what Seymour Papert, the inventor of LOGO, calls 'MInd-Sized bites: These are the procedures, each one small enough to understand and control easily. They are linked together by the procedure calls in a sequence or hierarchy.
A third aim IS to avoid writing the same code tWice. Write It once as a procedure and call it tWice If necessary. Functions and procedures written tor one program can often be directly used, Without change, by other programs, and one might create a library of commonly used procedures and functions.
We give below another example which shows how procedures make a program modular
An order IS placed for six dishes at Chan's Take Away, where the menu IS:
EXAMPLE
Item Number
1
2
3
Dish
Prawns
Chicken
SpeCial
Price
3.50
280
3.30
Write procedures for the following tasks.
1.
Set up two three-element arrays shOWing menu, dishes and prices. Use a DATA statement
2.
Simulate an order for SIX randomly chosen dishes uSing a procedure, choose, and make a tally of the number of times each dish is chosen.
12184
89 -
90
Procedures and Functions
3.
Pass the three numbers to a procedure, walter, which passes back the cost of the order to the main program using a parameter cost.
Procedure waiter calls two other procedures, compute and cook, which compute the cost and simulate
'cooking':
4.
The procedure, cook, simply prints the number required and the name of each dish.
The main program should call procedures as necessary, get the total cost from procedure, walter, add 10% for a tip, and print the amount of the total bill.
Design
This program Illustrates parameter passing in a fairly complex way and we will explain the program step by step before putting it together
100 REMark Procedures
110 RESTORE 490
120 DIM item$(3, n, price(3),
130 REMark
140 LET tip
***
PROGRAM
***
=
0.1
150 set_up dish(3)
210 DEFine PROCedure set_up
220
230
240
FOR k = 1 TO 3
READ item$(k)
READ price(k)
250 END FOR k
260 END DEFine
490 DATA "Prawns ll
,
3.5, IlChicken", 2.8, "SpeciaL", 3.3
The names of menu items and their prices are placed in the arrays Item$ and price.
The next step is to choose a menu number for each of the SIX customers. The tally of the number of each dish required will be kePt in the array dish.
160 choose di sh
270 DEFine PROCedure choose(dish)
280 FOR pick
=
1 TO 6
290
300
LET number
=
RND (1 TO 3)
LET dish(number)
= dish(number) + 1
310 END FOR pick
320 END DEFine
Note that the formal parameter dish is both: local to procedure choose an array in main program
The three values are passed back to the global array also called dish. These values are then passed to the procedure waiter.
170 waiter dish, bi LL
•
•
•
330 DEFine PROCedure waiter(dish, cost)
340
350 compute dish, cook di sh cost
360 END DEFi ne
The walter passes the information about the number of each dish reqUired to the procedure, compute, which computes the cost and returns It
•
12/84
•
•
•
370 DEFine PROCedure compute(dish, total)
380
390
400
LET total = 0
FORk=1to3
LET total = total + dish(k)*price(k)
410 END FOR k
420 END DEFine
The walter also passes information to the cook who simply prints the number required for each menu item.
430 DEFine PROCedure cooUdish)
440
450
FOR c = 1 TO 3
I dish(C)
I item$(c)
I
460 END FOR c
470 END DEFine
Again, the array, dish in the procedure cook is local. It receives the information which the procedure uses in its PRINT statement
The complete program is listed below.
100 REMark Procedures
110 RESTORE 490
120 DIM item$<3,n, price(3), dish(3)
130 REMa rk *** PROGRAM ***
140 LET tip = 0.1
150 set up
160 choose dish
170 waiter dish, bi II
180 LET bill
= bill + t i p*b i II
190 PRINT "Total cost is £"; bill
200 REMark *** PROCEDURE DEFINITIONS ***
210 DEFi ne PROCedure set up
220 FOR k
=
1 TO 3 -
230 READ item$(k)
240 READ price(k)
250 END FOR k
260 END DEFine
270 DEFine PROCedure choose(dish)
280 FOR pic k
=
1 TO 6
290 LET number
=
RND(1 TO 3)
300 LET dish(number) = dish(number) + 1
310 END FOR pi ck
320 ENO DEFine
330 DEFine PROCedure waiter(dish, cost)
340 compute dish,cost
350 cook di sh
360 END DEFi ne
370 DEFine PROCedure compute(dish, total)
380
390
400
LET tota l
FOR k
= 0
=
1 TO 3
LET total = total + dish(k)*price(k)
410 END FOR k
420 END DEFine
430 DEFine PROCedure cook(dish)
440
450
FOR c = 1 TO 3
I dish(c)
I item$(C)
460 END FOR c
470 END DEFine
480 REMark *** PROGRAM DATA ***
490 DATA "Prawns", 3.5, "Chicken",2.8,"Special",3.3
The output depends on the random choice of dishes but the following choice Illustrates the pattern, and gives a sample of output.
3 Prawns
1 Chicken
2 Special
Total cost is £20.40
Pro@ram
Output
12/84
Procedures and Functions
91
Procedures and Functions
92
COMMENT
Obviously the use of procedures and parameters In such a simple program is not necessary but Imagine that each sub-task might be much more complex. In such a situation the use of procedures would allow a modular build-up of the program with testing at each stage. The above example merely illustrates the main notations and relationships of procedures.
Similarly the next example Illustrates the use of functions.
Note that in the previous example the procedures walter and compute both return exactly one value. Rewrite the procedures as functions and show any other changes necessary as a consequence
DEFine FuNction waiter(dish) cook dish
RETurn compute(dlsh)
END DEFine
DEFine FuNction compute(dish)
LET total
=
0
FOR k = 1 TO 3
LET total
= total + dish(k)
* pnce(k)
END FOR k
RETurn total
END DEFine
The function call to walter also takes a different form
LET bi IL ; waiter(dish)
This program works as before. Notice that there are fewer parameters though the program structure is similar That IS because the function names are also serving as parameters retuning Information to the source of the function call.
EXAMPLE
All the variables used as formal parameters in procedures or functions are 'safe' because they are automatically local. Which variables used in the procedures or functions are not locar What additional statements would be needed to make them locar
Program Changes
The variables k, pick and num are not local. The necessary changes to make them so are:
LOCAL k
LOCAL pick, num
TYPELESS
PARAMETERS
Program
Output
Formal parameters do not have any type. You may prefer that a variable which handles numbers has the appearance of a numenc vanable and which handles stnngs looks like a string variable, but however you write your parameters they are typeless. To prove it, try the follOWing program.
100 REMark Number or word
110 waiter 2
120 waiter "Chicken"
130 DEFine PROCedure waiter(item)
140 PRINT
I item
I
150 END DEFine
2 Chi eken
The type of the parameter is determined only when the procedure is called and an actual
parameter 'arrives:
SCOPE OF
VARIABLES
Consider the follOWing program and try to consider what two numbers will be output.
100 REMark scope
110 LET number; 1
120 test
130 DEFine PROCedure test
140 LOCa L number
150 LET number
=
2
160
170
PRINT number try
12/84
•
•
•
•
•
•
•
Procedures and Functions
180 END DEFine
190 DEFine PROCedure try
200 PRINT number
210 END DEFine
Obviously the first number to be printed will be 2 but is the variable number in line 200 global?
The answer is that the value of number in line 160 will be earned into the procedure try.
A variable which is local to a procedure will be the same variable in a second procedure called by the first
Equally if the procedure try is called by the main program, the variable number will be the same number In both the main program and procedure, try.
The implications may seem strange at first but they are logical.
1.
The variable number in line 110 is global.
2.
The variable number in procedure test is definitely local to the procedure.
3.
The variable number in procedure try 'belongs' to the part of the program which was the last call to it
We have covered many concepts in this chapter because SuperBASIC functions and procedures are very powerful. However, you should not expect to use all these features immediately. Use procedures and functions in simple ways at first They can be very effecllve and the power is there if you need it
2.
3.
4.
1.
Six employees are identified by their surnames only. Each employee has a particular pension fund rate expressed as a percentage. The following data represent the total salaries and pension fund rates of the six employees.
Benson
Hanson
Johnson
Robson
Thomson
Watson
Write procedures to:
13,800
8,700
10,300
15,000
6,200
5,100
6.25
6.00
625
700
6.00
5.75
input the data into arrays compute the actual pension fund contnbullons output the lists of names and computed contributions.
Link the procedures with a main program calling them in sequence.
Write a function select with two arguments range and miss.
The function should return a random whole number In the given range but it should not be the value of miss.
Use the function In a program which chooses a random PAPER colour and then draws random circles in random INK colours so that none is in the colour of PAPER.
Re-write the solution to exercise 1 so that a function pension takes salary and contribution rate as arguments and returns the computed pension contribution.
Use two procedures, one to input the data and one to output the required information using the function pension.
Wnte the following: a procedure which sets up a 'pack of cards: a procedure which shuffles the cards.
a function which takes a number as an argument and returns a string value describing the card.
a procedure which 'deals' and displays four poker hands of five cards each.
a main program which calls the above procedures.
(see chapter 16 for discussion of a similar problem)
PROBLEMS ON
CHAPTER 15
12/84 93
94
CHAPTER 16
SOME
TECHNIQUES
In this final chapter we present some applications of concepts and facilities already discussed and we show how some further ideas may be applied.
SIMULATION OF
CARD PLAYING
It is easy to store and manipulate "playing cards" by representing them with the numbers
1 to 52. This is how you might convert such a number to the equivalent card. Suppose, for example, that the number 29 appears. You may decide that: cards 1-13 are hearts cards 14-26 are clubs cards 27-39 are diamonds cards 40-52 are spades and you will know that 29 means that you have a 'diamond': You can program the QL to do this with:
LET suit = (card-1) DIV 13
This will produce a value in the range 0 to 3 which you can use to cause the appropriate suit to be printed. The value can be reduced to the range 1 to 13 by writing:
LET value
IF value
= card MOD 13
= 0 THEN LET vaLue = 13
Program
The numbers 1 to 13 can be made to print Ace, 2, 3... Jack, Queen, King,
Or
If you prefer it, such phrases as "two of hearts" can be printed. The following program will print the name of the card corresponding to your Input number.
Input and Output
100 REMark Cards
110 DIM suitname$(4,8),cardval$(13,5),
120 LET f$
=" of"
130 set up
140 REPeat cards
150 INPUT "Enter a card number 1-52:"
!
card
160
170
180
190
200
IF card <1 OR card> 52 THEN EXIT cards
LET suit
=
(card-1) DIV 13
LET vaLue
IF value
= card MOD 13
=
0 THEN LET value
=
13
PRINT cardval$(vaLue)
I f$
I suitname$(suit)
210 END REPeat cards
220 DEF i ne PROCedu re set up
230
240
FOR s
FOR v
= 1 TO 4 : READ suitname$(s)
=
1 TO 13 : READ cardvaL$(v)
250 END DEFine
260 DATA "hearts","cLubs","diamonds","spades"
270 DATA
II
Ace" , "lwol!
I
"Th ree"
, I I
Fou r" ," F; veil, "S i x"
I
"S even"
280 DATA "Eight","Nine","Ten","Jack","Queen","King"
13
King of hearts
49
Ten of spades
27
Ace of di amonds o
COMMENT
Notice the use of DATA statements to hold a permanent file of data which the program always uses. The other data which changes each time the program runs is entered through an INPUT statement If the Input data was known before running the program it would be equally correct to use another READ and more DATA statements This would give better control.
•
•
•
•
12/84
•
•
•
Some Techniques
SEQUENTIAL DATA
FILES
Numeric File
The following program will establish a file of one hundred numbers.
100 REMark Number Fi Le
110 OPEN NEW #6,mdv1 numbers
120 FOR cum = 1 TO 100
130 PRINT #6,num
140 END FOR num
150 CLOSE #6
After running the program check that the filename 'numbers' is in the directory by typing:
DI R mdv1 numbe rs
You can get a view of the file without any special formatting by copying from Microdrive to screen:
COPY mdv1 numbers to ser
You can also use fhe following program to read the file and display its records on the screen.
100 REMark Read File
110 OPEN IN #6,mdv1 numbers
120 FOR cum
=
1 TO 100
130 INPUT #6,item
140 PRINT
I item
I
150 END FOR num
160 CLOSE #6
If you wish you can alter the program to get the output in a different form.
In a similar fashion the following programs will set up a file of one hundred randomly selected letters and read them back.
100 REMark Letter Fi Le
110 OPEN NEW #6,mdv1 ehfi Le
120 FOR cum
=
1 TO 100
130 LET eh$ = CHR$(RND(65 TO 9OJ)
140 PRINT #6,eh$
150 END FOR num
160 CLOSE #6
Character File
FOR
SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844·351694
FAX: 01844 . 352554
100 REMark Get Letters
110 OPEN IN #6,mdv1 ehfi Le
120 FOR cum
=
1 TO 100
130 INPUT #6,item$
140 PRINT
I item$
I
150 END FOR num
160 CLOSE #6
SETIING UP A
DATA FILE
Suppose that you Wish to set up a simple file of names and telephone numbers.
RON
GEOFF
ZOE
BEN
MEG
CATH
WENDY
678462
896487
249386
584621
482349
438975
982387
The following program will do it.
100 REMark Phone numbers
110 OPEN NEW #6,mdv1 phone
120 FOR record
=
1 TO-7
130 INPUT name$,num$
140 PRINT #6;name$;num$
150 END FOR record
160 CLOSE #6
95
12/84
Some Techniques
96
Type RUN and enter a name followed by the ENTER key and a number followed by the ENTER key. Repeat this seven times.
Notice that the data is 'buffered: It IS stored internally until the system IS ready to transfer a batch to the Microdrive. The Microdrive is only accessed once, as you can tell from looking and listening.
COpy AFILE
Once a file is established, It should be copied immediately as a back-up. To do this type
COpy mdv1 phone TO mdv2_phone
READ AFILE
You need to be certain that the file eXists in a correct form so you should read it back from a Microdnve and display It on the screen. You can do this easily using:
COpy mdv2_phone TO sc r
The output to the screen will not provide spaces automatically between the name and the number but It will proVide a 'newline at the end of each record. The output will be:
RON678462
GEOFF896487
ZOE249386
BEN584621
MEG482349
CATH438975
WENDY982387
You can get a more controlled presentation of the data with the following program.
100 REMark Read Phone NUmbers
110 OPEN IN #5,mdv1 phone
120 FOR record
130
= 1 TO 7
INPUT #5, rec$
140 PRINT, rec$
150 END FOR record
160 CLOSE #5
The data is printed, as before, but this time each pair of fields is held In the vanable rec$ before being printed on the screen. You have the opportunity to manipulate it into any desired form.
Note that more than one string variable may be used at the file creation stage With INPUT and PRINT but the whole record so created may be retrieved from the Mlcrodnve file with a single stnng variable (rec$ in the above example).
AN INSERTION
SORT
The following colours are available In the low resolution screen mode (in code number order 0-7).
black blue red magenta green cyan yellow white
EXAMPLE
Method
Wnte a program to sort the colours into alphabetical order using an Insertion sort
We place the eight colours in an array, colour$, which we divide Into two parts:
I
LIID
UNSORTED PART
We take the leftmost item of the unsorted part and compare it with each item, from right to left, in the sorted part until we find its right place. As we compare we shuffle the sorted items to the right so that when without further shuffling.
we find the right place to insert we can do so immediately,
•
•
•
•
12/84
Some Techniques
•
•
Suppose we have reached the point where four items are sorted and we now focus on green, the leftmost item in the unsorted part.
2.
3.
black
2 3 sorted part
4 blue magenta red
I,,:"
6 7 8 cyan yellow white t unsorted part
1.
We place green In the variable, comp$, and set a vanable, p, to 5.
The variable,
p,
will eventually Indicate where we think green should go. When we know that green should move left, then we decrease the value of
p.
We compare green with red. If green IS greater than (nearer to we exit and green stays where It is.
Z) or equal to red
5 thus and decrease the value of p thus: Otherwise we copy red ,n to POSition
• black
2 3 blue magenta
4 red
I
I
5 red
6 cyan
7 yellow
8 white
4.
We now repeat the process but thiS time we are comparing green with magenta and we get:
I
6 cyan
7 yellow
8 white black
2 blue
3 4 magenta magenta
I
5 red
5 Finally we move left again comparing green with blue. This time there is no need to move or change anything. We eXit from the loop and place green in position
3.
We are then ready to focus on the sixth Item, cyan.
12/84 black
2 blue
3 4 green magenta
5 red
I
6 cyan
I
7 yellow
8 white
1.
We will first store the co/our$ In an array colour$(B) and use: comp$ the current colour being compared p to point at the position where we think the colour in comp$ might go.
2.
3.
4.
A FOR loop will focus attention on positions 2 to 8 In turn (a single item is already sorted).
A REPeal goes.
loop will allow comparisons until we find where the comp$ value actually
REPeal compare
IF comp$ need go no further left EXIT copy a colour Into the position on its right and decrease p
END REPeal compare
After the
EXIT from the REPeal loop the colour in comp$ is placed In position p and
FOR loop continues.
PROBLEM ANALYSIS
97
Some Techniques
98
Program Design
1
2
3
4
5
Declare array colour$
Read colours into the array
FOR item ~ 2mS
LET p = item
LET comp$ = colour$(p)
REPEAT compare
IF comp$
>
= cOlour$(p-1) : EXIT compare
LET colour$(p) = colour$(p-1)
LET p ~ p-1
END REPeat compare
LET colour$(p) ~ comp$
END FOR item
PRINT sorted array colour$
DATA
Further testing reveals a fault It anses very easily if we have data in which the first item
IS not in its correct position at the start. A simple change of initial data to: red black blue magenta green cyan yellow white reveals the problem. We compare black with red and decrease p to the value, 1.
We come round again and try to compare black with a vanable colour$(p-I) which is colour$(O) which does not exist
This is a well-known problem In computing and the solution is to "post a sentinel" on the end of the array. Just before entering the REPeat loop we need:
LET colour$(O) = comp$
Fortunately, SuperBASIC allows zero subscripts, otherwise the problem would have to be solved at the expense of readability.
MODIFIED
PROGRAM
100 REM Insertion Sort
110 DIM colour$(8,7l
120 FOR item = 1 TO 8: READ coLour$(item)
130 FOR item = 2 TO 8
140
150
LETp=item
LET comp$ = coLour$(p)
160 LET colour$(Q) = comp$
170
180
190
200
REPeat compare
IF comp$ >= coLour$(p-1) : EXIT compare
LET coLour$(p) = colour$(p-1)
LET p = p-1
210
220
END REPeat compare
LET colour$(p) = comp$
230 END FOR item
240 PRINT "Sorted . . . "
I colourS
250 DATA "black", "blue", lImagenta", "red"
260 DATA "green ll
,
"cyan", "ye llow", "wh; te"
COMMENT
1.
The program works well. It has been tested with awkward data:
AAAAAAA
BABABAB
ABABABA
BCDEFGH
GFEDCBA
2.
An insertion sort is not particularly fast, but it can be useful for adding a few items to an already sorted list It is sometimes convenient to allow modest amounts of time frequently to keep items in order rather than a substantial amount of time less frequently to do a complete re-sorting.
You now have enough background knowledge to follow a development of the handling of the file of seven names and telephone numbers.
•
•
•
•
12/84
Some Techniques
•
•
•
In order to sort the file 'phone' into alphabetical order of names we must read It Into an Internal array, sort it, and then create a new file which will be in alphabetical order of names.
It is never good practice to delete a file before its replacement is clearly established and proven correct You should therefore copy the file first, as security, uSing a different name.
The required processes are as follows:
1.
Copy the file 'phone' to 'phone_temp'
2.
Read the file 'phone' Into an array.
3.
Sort the array.
4.
Pause to check that everything IS in order.
5.
Delete file 'phone:
6.
Create new file 'phone:
This is all the program needs to do but the new file should be immediately checked using:
COPY mdv1 phone TO sc r
Any further necessary checks should be carried out then:
DELETE mdv2 phone
COPY mdv1 phone TO mdv2 phone
COPY mdv1 phone TO sc r -
DELETE mdv1_phone_temp
The above operations complete the process of substituting a sorted file for the original unsorted one in both master and back-up files.
SORTING
A
MICRODRIVE FILE
In the following program we Illustrate the passing of complete arrays between main program and procedure. The data passes in both directions.
In line 40 the array, row, holding the numbers 1,2,3 is passed to the procedure, addsix.
The parameter,
come,
receives the Incoming data and the procedure adds six to each element The array parameter, send, at this point holds the numbers 7,8,9.
These numbers are passed back to the main program to become the values of array, black.
The values are printed to prove that the data has moved as required.
MAIN
PROGRAM
[row~back_l_
Screen
Output
ARRAY
PARAMETERS
PROCEDURE addsix
L +6 - - - _ .
100 REMark Pass Arrays
110 DIM row(3) ,back(3)
120 FOR k = 1 TO 3 : LET row (k) = k
130 addsix row, back
140 FOR k = 1 TO 3 : PRINT
I back(k)
I
150 DEFine PROCedure addsix(come,send)
160 FOR k = 1 TO 3 : LET send(k)=come(k)+6
170 END DEFine
789
The following procedure receives an array containing data to be sorted. The zero element will contain the number of items. Note that it does not matter whether the array is numeric or string. The principle of coercion will change string to numeric data if necessary.
Program
Output
99
12/84
100
Some Techniques
A second pOint ot Interest is that the array element, come(O), IS used for two purposes:
It carnes the number of items to be sorted it is used to hold the Item currently being placed.
100 DEFine PROCedure sort(come,send)
110 LET num = come<O)
120
130
140
FOR item = 2 TO num
LET P = item
LET come (0) = come (p)
150
160
170
180
190
200
REPeat compare
IF come(O) >= come(p-1)
LET come(p) = come(p-1)
LET P = p-1
END REPeat compare
LET come (p) = come (0)
210
220
END FOR item
FOR k=1 TO 7 : send(k) = come(k)
230 END DEFine
EXIT compare
The follOWing additional lines will test the sort procedure. First type AUTO 10 to start the line numbers from 10 onwards.
10 REMark Test Sort
20 DIM row$(7,3),back$(7,3)
30 LET row$(O) = 7
40 FOR k = 1 TO 7 : READ row$(k)
50 sOrt row$,back$
60 PRINT
I back$
I
70 DATA "EEL II
,
"DOG", "ANT", "GNU", "CAT", IlBUG", "FOX"
ANT BUG CAT DOG EEL FOX GNU
Output
COMMENT
This program illustrates how easily you can handle arrays in SuperBASIC All you have to do is use the array names for passing them as parameters or for printing the whole array. Once the procedure IS saved you can use MERGE mdv1_sort to add It to a program in main memory
You now have enough understanding of techniques and syntax to handle a more complex screen layout Suppose you wish to represent the hands of four card players. A hand can be represented by something like:
H: A 37 Q
C.
5 9 J
D 610 K
S: 2 4 Q
To help the presentation the Hearts and Diamonds will be printed in red and the Clubs and Spades in black. A suitable STRIP colour might be white. The general background could be green and a table may be a colour obtained by mixing two colours.
METHOD
Since a substantial amount of character printing is involved it is best to start planning in terms of the pixel screen. You can see that you need to provide for twelve lines of characters with some space between lines and a total screen height of 256 pixels.
•
•
•
12/84
•
Some Techniques
•
It is useful to recall that the possible character heighfs are 10 pixels or 20 pixels. It is obvious that the 10 pixel height musf be used to allow space for a proper layout
The number of character pOSitions across the screen must be estimated. If we adopt the convention of 'T' for ten Instead of '10" all card values can be represented as a
Single character Suppose that we also allow a maximum of eight cards of the same
SUit as a first approach. We can reconsider the problem again if necessary. That would require a total of 10 characters for each hand. The across requirement is therefore: west hand + table width + east hand
Allowing a space between characters that would be:
20 + table width + 20
The decision now depends on which screen mode you choose. The 256 mode will cope with the problem, as you will see later but first we Will work in 512 pixel mode. The smallest character width IS six pixels which would give a total of 240 pixels + 'able width. The diagram will have some balance if we have a table width of about half of 240.
We should therefore experiment with a table width of about 120 pixels which may be adjusted. A little testing produced the layout shown.
•
H: 5 9 K
c:
A Q
0: A 4 6 J
S: A 2 3 T
H: A c:
7 J K
0: 5 8 9 K
S:457JK
H:2347J c:
3 9 T
0: 2 3
S: 89 Q •
WINDOW 440 x 220 at 35,15
Green with black border of 10 units
TABLE 100 x 60 at 150,60
Chequerboard stipple of red and green
HANDS Room for at least eight card symbols.
Initial cursor pOSitions are: north 150,10 east 260,60 south 150,130 west 30,60
CHARACTER SIZE
NUMBER OF PIXELS
CHARACTER COLOUR
CHARACTER STRIP
Standard for 512 mode between lines is 12
White
Red for Hearts and Diamonds
Black for Clubs and Spades.
H: 6 8 T Q
C:24568
0: 7 T
Q
s:
6
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www,maurltron,co,uk
TEL: 01844·351694
FAX: 01844·352554
101
--
Some Techniques
VARIABLES
PROCEDURES
card(52) sort(13) tok$(4,2) kmcmh ran temp item dart comp inc seat aC,dn; row
Iin$ max p n stores card numbers used to sort each hand stores tokens H:, C:, D:, S: working loop variables random position for card exchange used in card exchange card to be inserted in sort pointer to find position in sort hold card number in sort pixel increment in card rows current deal' position cursor position for characters current row for characters builds up row of characters highest card number pOints to card position current number of card shuffle split sortem layout printem gelline shuffles 52 cards splits cards into four hands and calls sortem to sort each hand sorts 13 cards in ascending order provides background colour, border and table prints each line of card symbols gets one row of cards and converts numbers into the symbols
A, 2,3,4,5,6,7.,8,9,T,J,Q, K
102
PROGRAM DESIGN
1.
OUTLINE
2.
3.
4.
5.
6.
7.
Declare arrays, pick up tokens' and place 52 numbers in array card.
Shuffle cards.
Split into 4 hands and sort each.
OPEN screen window
Fix the screen layout
Print the four hands.
CLOSE the screen window
100 DIM card(52) ,sart (13) ,tak$(4,2)
110 FOR k = 1 TO 4 : READ tak$(k)
120 FOR k
=
1 TO 52 : LET card(k)
= k
130 shuffLe
140 split
150 OPEN #6,scr 440x220a35x15
160 Layaut -
17.0 pri ntem
180 CLOSE #6
190 DEFine PROCedure shuffle
200 FOR c
=
52 TO 3 STEP -1
210
220
230
LET ran
LET temp
=
RND(1 TO c-1)
= card(c)
LET card(c)
= card(ran)
240 LET card(ran) = temp
250 END FOR c
260 END DEFine
27.0 DEFine PROCedure split
280
290
300
FOR h
=
FOR c
1 TO 4
=
1 TO 13
LET sart(c)
= card«h-1)*13+c)
310 END FOR c
320 sartem
330
340
350
FOR c = 1 TO 13
LET card«h-1)*13+c)
END FOR c
360 END FOR h
37.0 END DEFine sart(c)
380 DEFi ne PROCedure sartem
390 FOR item
=
2 TO 13
400 LET dart
=
item
12/84
•
•
•
•
Some Techniques
•
•
•
590
600
610
620
630
640
650
660
670
410
420
430
440
450
460
LET camp = sort<dartl
LET sort (0) = camp
REPeat campa re
IF camp >= sort<dart-1l : EXIT compare
LET sort(dart) = sort(dart-1)
LET dart = dart -1
470
480
END REPeat compare
LET sort(dart) = camp
490 END FOR; tem
500 END DEFine
510 DEFine PROCedure layout
520
530
540
PAPER #6,4 : CLS #6
BORDER #6,10,0
BLOCK #6,100,60,150,60,2,4
550 END DEFine
560 DEFine PROCedure printem
570 LET inc = 12 : INK #6,7
580 LET p = 0
FOR seat = 1 TO 4
READ ac, dn
FOR row = 1 TO 4 getLine
CURSOR #6,ac,dn
PRINT #6,lin$
LET dn = dn + inc
END FOR row
END FOR seat
680 END DEFine
690 DEFine PROCedure getLine
700 IF row MOD 2 = 0 THEN STRIP #6,0
710
720
730
740
750
760
770
IF row MOD 2 = 1 THEN STRIP #6,2
LET lin$ = tok$(row)
LET max = row*13
REPeat one suit
LET p = p
+ 1
LET n = card (p)
IF n >max THEN p = p-1 EXIT one suit
780
790
800
810
820
LET n = n MOD 13
IFn=OTHENn=13
IF n = 1 : LET ch$ = "A"
IF n >= 2 AND n <= 9 : LET ch$ = n
IF n = 10 LET ch$ = "T"
830
840
850
860
870
880
IF n = 11
IF n = 12 LET ch$ = "Q"
IF n = 13
LET ch$ = "J"
LET ch$ = "K"
LETLin$=Lin$&""&ch$
IF P = 52 : EXIT one=suit
IF card(p»card(p+ll EXIT one suit
890 END REPeat one sui t
900 END DEFine -
910 DATA "H: II ,"C:","D:","S:"
920 DATA 150,10,260,60,150,130,30,60
The program works in the 256 mode But the various lines of card symbols may overlap the ',able" or overflow at the edge of the window.
A simple change in procedure getline from:
860 LET lin$ = Lin$ & " " & ch$ to:
860 LET Lin$ = Lin$ & ch$ will correct this, The spaces between characters disappear but the larger sized characters enable the rO'NS to be easily readable. The program thus works well in either graphics mode.
COMMENT
104
Some Techniques
CONCLUSION
We have tried to show how you can use SuperBASIC to solve problems. We have shown how simple tasks can be performed in simple ways. When the task is inherently complex, like manipulating arrays or designing screen graphics, SuperBASIC enables it to be handled efficiently with maximum possible clarity.
If you were a beginner and you have worked through a fair proportion of this guide you will have started well on the road to good programming. If you were already experienced, we hope that you will appreciate and exploit the extra features offered by
SuperBASIC
So enormous is the range of tasks which can be done with SuperBASIC that we have only been able to touch a fraction of them in this guide. We cannot guess at which of the thousands of possibilities you will attempt, but we hope that you will find them fruitful, stimulating and fun.
•
•
12/84
•
•
e·
•
1.
2.
3
4.
Use the BREAK sequence to abandon a running program because: a) something is wrong and you do not understand it b) It IS longer of interest c) any other problem (three points)
The RESET button is On the right hand side of the computer
The effect of the RESET button is rather like switching the computer off and on again
The SHIFT key a) IS only effective while you hold it down whereas the CAPS LOCK key stays effective affer you have pressed It (one point)
•
6
7.
5.
8.
9.
10.
11.
12.
13.
b) The SHIFT key affects all the letter, digit and symbol keys, but the CAPS
LOCK key affects only letters.
(one point)
The CTRL ~ keys delete the previous character just leff of the cursor.
The ..'" (ENTER) key causes a message or. instruction to be entered for action by the computer
We use .." for the ENTER key.
CLS .." causes part of the screen to be cleared.
RUN .."
causes a stor.ed program to be executed.
LIST ..", causes a stor.ed program to be displayed on the screen.
NEW .." clears the main memor.y ready for a new program.
Keywords of SuperBASIC are recognised in upper or lower case.
The part of a keyword displayed in upper case is the allowed abbreviation.
ANSWERS TO
SELF TEST ON
CHAPTER 1
14 to 16 is very good. Carryon reading.
12 or 13 is good, but re-read some parts of chapter one.
10 or 11 is fair, but re-read some parts of chapter one and do the test again.
Under 10. You should work carefully through chapter one again and repeat the test
CHECK YOUR
SCORE
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL 01844 - 351694
FAX: 01844 - 352554
105
ANSWERS TO
SELF TEST ON
CHAPTER 2
8.
9.
1.
2.
READ count .."
3.
You can find the value of a pigeon hole with a PRINT statement
4.
5.
6.
(1 point)
The technical name for a pigeon hole is variable' because its values can vary as a program runs.
A variable gets its first value when it is first used in a LET statement, INPUT statement or READ statement.
A change in the value of a variable is usually caused by the execution of a LET statement.
7.
An internal number store is like a pigeon hole which you can name and put numbers Into.
A LET statement which uses a particular name for the first time will cause a pigeon hole to be created and named, for example
LET count = 1 .." (1 point)
A READ statement which uses a name for the first time will have the same effect, for example
The = sign In a LET statement represents an operation:
'Evaluate whatever is on the right hand side and place it in the pigeon hole named on the left hand side, that is 'Let the left hand side become equal to the right hand side:
An un-numbered statement is executed immediately.
A numbered statement is not executed immediately. It is stored.
10.
The quotes in a PRINT statement enclose text which is to be printed.
11.
When quotes are not used you are printing out the value of a variable.
12.
An INPUT statement makes the program pause so that you can type data at the keyboard.
13.
DATA statements are never executed.
14.
They are used to provide values for the variables in READ statements.
15.
The technical word for the name of a pigeon hole is 'identifier:
16.
Example answers: i.
ii day day_23 iii day_of_week (3 points)
17.
The space bar is especially important for putting spaces after or before keywords so that they cannot be taken as identifiers (names) chosen by the user
18.
Freely chosen identifiers are important because they help you to make programs easier to understand. Such programs are less prone to errors and more adaptable.
CHECK YOUR
SCORE
18 to 21 is very good. Carryon reading.
16 or 17. good but re-read some parts of chapter two.
14 or 15 fair, but re-read some parts of chapter two and do the test again.
Under 14 you should work carefuly through chapter two again and repeat the test.
'.
•
•
•
1?IR4
•
•
7.
8,
9,
3.
4.
.1.
2.
5.
6,
A pixel is the smallest area of light that can be displayed on the screen.
There are 256 pixel positions across the low resolution mode.
There are 256 pixel positions from top to bottom in the low resolution mode.
An address is determined by: the up value, 0 to 100 the across value, 0 to a number computed by the system
There are eight colours available in the low resolution mode including black and white.
i.
ii.
LINE draws a line, eg, LINE a,b
m
x,y
INK selects a colour for drawing, e,g, INK 5 iii, PAPER selects a background colour, e,g, PAPER 7 iv BORDER draws a border e,g. BORDER 1,5
REPeal name.... END REPeal name.
A REPeal loop ferminates when an 'EXIT name' statement is executed,
Loops in SuperBASIC have names so that it is possible to EXIT from them in a straighrtorward way. It is not necessary to work out line numbers in advance,
ANSWERS TO
SELF TEST ON
CHAPTER 3
11 to 13
IS very good. Carryon reading.
8 to 10 is good but re-read some parts of chapter three.
•
6 or 7
IS fair but re-read some parts of chapter three and do the test again.
Under 6, You should work carefully through chapter three again and repeat the test
CHECK YOUR
SCORE
•
•
1.
2
3.
A character string
IS a sequence of characters such as letters, digits or other symbols,
The term, character string: is often abbreviated to 'string:
A string variable name always ends with $,
4.
5
6,
7.
8.
Names such as wordS are sometimes pronounced 'worddollar:
The keyword LEN will find the length or number of characters in a string. For example, if the variable meatS has the value 'steak' then the statement:
PRINT LEN(meat$) will output 5.
The symbol for Joining two strings is &,
The limits of a string may be defined by quotes or apostrophes.
The quotes are not part of the actual string and are not stored.
9.
The function is CHR$. You must use it with brackets as in CHR$(66) or with brackets as in CHR$(RND(65 m
67)
10, You generate random letters with statements like: lettereode
=
RNO(65 TO 90)
PRINT CHR$(lettereode)
ANSWERS TO
SELF TEST ON
CHAPTER 4
9 or 10 is very good, Carryon reading,
7 or 8 is good but re-read some parts of chapter four,
5 or 6 is fair but re-read some parts of chapter four and do the test again.
Under 5 You shourd work carefully through chapter four again and repeat the test
CHECK YOUR
SCORE
12/84
107
108
ANSWERS TO
SELF TEST ON
CHAPTER 5
1.
Lower case letters for variable names or loop names contrast with the keywords which are at least partly displayed In upper case
5
6
2.
3.
4.
Indenting reveals clearly what is the extent and content ot loops (and other structures).
Identifiers (names) should normally be chosen so that they mean something, for example, count or word$ rather than C or W$.
You can edit a stored program by: replacing a line
Inserting a line deleting a line (three pOints)
The ENTER key must be used to enter a command or program line
The word NEW will wipe out the prevIous SuperBASIC program in the OL and will ensure that a new program which you enter will not be merged with an old one.
If you wish a line to be stored as part of a program then you must use a line number 7
8.
The word RUN followed by.'" will cause a program to execute.
9.
The word REMark enables you to put Into a program Information which is Ignored at execution time.
10.
The keywords SAVE and LOAD enable programs to be stored on and retrieved trom cartridges. (two points).
. j
CHECK YOUR
SCORE
12 to 14 is very good. Carryon reading.
10 or 11 IS good but re-read some parts ot chapter five.
8 or 9 IS fair but re-read some parts of chapter five and do the test again.
Under 8 You should re-read chapter five carefully and do the tesf again.
•
•
•
12/84
•
•
•
•
1.
2
7.
8.
9.
4.
5.
3
6.
10
It is not easy to think of many differenf variable names for sforing fhe data. If you can think of enough names, everyone has to be written in a LET statement or a READ statement if you do not use arrays.
A number, called the subscript, is part of an array variable name. All the variables in an array share one name but each has a different subscript
You must declare' an array giving its Size (dimension) in a DIM statement usually placed near the beginning of a program before the declared array is used.
The distinguishing number of an array variable is called the subscript
Houses in a street share the same street name but each has its own number
Beds in a hospital ward may share the name of the ward but each bed may be numbered
Cells in a prison block may have a common block name but a different number.
Holes on a golf course, e.g. the fifth hole at Royal Blrkdale.
A FOR loop terminates when the process corresponding to the last value of the loop variable has been completed.
A FOR loop's name is also the name of the variable which controls the loop.
The two phrases for thiS variable are loop variable' or control variable:
The values of a loop variable may be used as subscripts for array variable names.
Thus, as the loop proceeds, each array variable is 'visited' once.
Both FOR loops and REPeat loops: a.
have an opening keyword:
REPeal, FOR b.
have a closing statement
END REPeal
name,
END FOR
name
have a loop name.
c
Only the FOR loop has d.
a loop variable or control variable.
(four paints)
ANSWERS TO
SELF TEST ON
CHAPTER 6
This test is more searching than the previous ones.
15 or 16 is excellent Carryon reading .
13 or 14 is very good but think a bit more about some of the ideas. Look at programs to see how they work.
11 or 12 is good but re-read some parts of chapter SIX.
8.
to 10 is fair but re-read some parts of chapter six and do the test again.
Under 8.
You should re-read chapter six carefully and do the test again.
CHECK YOUR
SCORE
12184 109
110
ANSWERS TO
SELF TEST ON
CHAPTER 7
1.
2.
3.
4.
5
6.
7.
8.
We normally break down large or complex jobs into smaller tasks until they are small enough to be completed.
This principle can be applied In programming by breaking the total Job down and writing a procedure for each task.
FOR SERVICE MANUALS
A simple procedure IS:
CONTACT:
MAURITRON TECHNICAL SERVICES
a separate block of code properly named. (two points) www.mauntron.co.uk
TEL: 01844 - 351694
A procedure call ensures that:
FAX:
01844 - 352554 the procedure is activated control returns to Just aher the calling pOint (two pOints)
Procedure names can be used in a main program before the procedures have been written. ThiS enables you to think about the whole job and get an overview without worrying about the. detail.
It you write a procedure definition before uSing its name you can test it and then when It works properly forget the details. You need only remember its nar;e and roughly what It does.
A programmer who can write up to thirty line programs can break down a complex task into procedures in such a way that none IS more than thirty lines and most are much less. In thiS way he need only worry about one bit of the Job at a time.
The use of a procedure would save memory space if It is necessary to call it more than once from different parts of a program. The definition of a procedure only occurs once but It can be called as ohen as necessary
9 A main program can place Information ,n 'pigeon-holes' by means of LET or READ statements. These 'pigeon-holes' can be accessed by the procedure. Thus the procedure uses Information Originally set up by the main program.
A second method is to use parameters In the procedure call. These values are passed to variables in the procedure definition which then uses them as necessary.
10 An actual parameter is the actual value passed from a procedure call in a main program to a procedure.
11.
A formal parameter is a variable In a procedure definition which receives the value passed to the procedure by the main program.
•
•
CHECK YOUR
SCORE
This is a searching test. You may need more experience of uSing procedures before the ideas can be tully appreciated. But they are very powerful and, when understood, extremely helpful Ideas. They are worth whatever effort is necessary
12 to 14 excellent. Read on with confidence.
10 or 11 very good. Just check again on certain points.
8 or 9 good but re-read some parts of chapter seven.
6 or 7.
fair but re-read some parts of chapter seven. Work carefully through the programs writing down all changes In variable values. Then do the test again.
Under 6 read chapter seven again. Take It slowly working all the programs. These ideas may not be easy but they are worth the effort. When you are ready, take the test again.
•
•
12/84
•
Keywords
•
•
The Keyword Reference GUide lists all SuperBASIC keywords in alphabetical order. A brief explanation of the keywords function is given followed by loose definition of the syntax and examples of usage. An explanation of the syntax definition is given in the
Concept Reference Guide under the entry syntax.
Each keyword entry indicates to which, if any, group of operations it relates, I.e. DRAW is a graphics operation and further information can be obtained from the graphics section of the Concept Reference Guide.
Sometimes it is necessary to deal with more than one keyword at a time, i.e. IF, ELSE,
THEN, END, IF, these are all listed under IF.
An index is provided which attempts to cover all possible ways you might describe a
SuperBASIC keyword. For example the clear screen command, CLS, is also listed under
clear screen and screen clear.
©1984 SINCLAIR RESEARCH LIMITED by Stephen Berry (Sinclair Research Limited)
•
ASS returns the absolute value of the parametec It will return the value of the paramefer if the parameter IS positive and will return zero minus the value of the parameter if the parameter IS negative.
syntax: example:
ASS(numenc_expresslon) i.
PRINT ABS(Q.5) ii.
PRINT ABS(a-bJ
ASS
maths functions
•
•
ACOS and ASIN will compute the arc cosine and the arc Sine respectively. ACOT will calculate the arc cotangent and ATAN will calculate the arc tangent. There is no effective limit to the size of the parameter syntax: angle: = numeric~expresslon [in radians]
ACOS(angle) ASIN(angle)
ACOT (angle) ATAN (angle) example: i.
PRINT ATAN (ang LeJ ii.
PRINT ASIN (1) iii.
PRINT ACOT<3.6574J
~ PRINT ATAN(a-bJ
ACOS, ASIN
ACOT, ATAN
maths functions
12184
ADATE
clock
ADATE allows the clock to be adjusted.
syntax: seconds: ~ numeric_expression
ADATE seconds example: I il
ADATE 3600
ADATE -60
[will advance the clock 1
[will move the clock back hour]
1 minute]
•
2
ARC
ARC_R
graphics
ARC will craw an arc of a circle between two specified points in the window attached to the detault or specified channel. The end points of the arc are specified using the graphics co-ordinate system.
Multiple arcs can be drawn with a single ARC command.
The end points of the arc can be specified in absolute coordinates (relative to the graphics origin or in relative coordinates (relative to the graphics cursor).
If the first point is omitted then the arc is drawn from the graphics cursor to the specified point through the specified angle.
ARC Will always draw with absolute coordinates, while ARC_R Will always draw relative to the graphics cursOt syntax: x: =
y:
~ angle:~
numeric_expression
numeric_expression numeric_expression [in radians]
POint: x,y parameter _2:
=
I
TO POint, angle
I
,point m point, angle parameter_I::
I point TO pOlnt,angle
I m point,angle
ARC [channel,] parameter_I
ARC_R
*
[parameter_2]
*
[channel,] parameter_I * [parameter_2J * where 1 will draw from the specified point to the next specified point turning through the specified angle
2 Will draw from the the last point plotted to the specified point turning through the specified angle
1
2
1
2 example: I ARC 15,10 TO 40,40, PIIZ
[draw an arc from 15,10 to 40,40 turning through rc/2 radians] il.
ARC TO 50,50,PI/Z
[draw an arc from the last point plotted to rc /2 radians]
50,50 turning through iii.
ARC R 10,10 TO 55,45,0.5
[draw an arc. starting 10,10 from the last point plotted to 55,45 from the start of the arc, turning through 0.5
radians]
12/84
•
•
•
•
AT allows the print position to be modified on an imaginary rowlcolumn grid based on the current character size. AT uses a modified form of the pixel coordmate system where
(row 0, column 0)
IS in the top left hand corner of the window AT affects the print position in the window attached to the specified or default channel.
line: = numenc_expression
column:= numeric_expression
syntax:
AT [channel,
I
line , column example: AT 10,20: PRINT "This is at Line 10 coLumn 20"
AT
windows
•
•
AUlD allows line numbers to be generated automatically when entering programs directly into the computer. AUTO will generate the next number in sequence and will then enter the SuperBASIC line editor while the line is typed in. If the line already exists then a copy of the line IS presented along with the line number Pressing ENTER at any point in the line will check the syntax of the whole line and Will enter it into the program.
AUTO is terminated by pressing syntax: example:
I
CTRL
I I s--'-p_ac_e _ firsLline:~ gap: = line_number numenc_expression
AUlD [firsLline] [,gap] i.
AUTO ii.
AUTO 10.5
iii.
AUTO.
7
Istart at line 100 with intervals of 101
Istart at line 10 with intervals of 5]
[start at line 100 with intervals of 7)
AUTO
12/84
3
BAUD
communications BAUD
sets the baud rate for communication via both serial channels. The speed of the channels cannot be set independently.
syntax: rate: ~ numeric_expression
BAUD
rate
The value of the numeric expression must be one of the supported baud rates on the OL: example:
75
300
600
1200
2400
4800
9600
19200 (transmit only)
If the selected baud rate IS not supported, then an error will be generated.
I.
BAUD 9600
II.
BAUD pri nt speed •
BEEP
sound
BEEP activates the inbuilt sound functions on the OL. BEEP can accept a variable number of parameters to give various levels of control over the sound produced. The minimum specification requires only a duration and pitch to be specified. BEEP used with no parameters will kill any sound being generated.
syntax: duration: ~ numeric_expression [range -32768 .. 32767] pitch: ~ numeric_expression [range 0 .. 255] grad_x: ~ numeric_expression [range -32768 .. 32767) grad_y:~ numeric_expression [range -8 .. 71 wrap: = numeric_expression [range 0 ..
15] fuzzy:~ numeric_expression [range 0 .. 15] random:~ numeric_expression [range 0 .. 15]
BEEP [ duration, pitch
[, pitch_2 , grad_x, grad_y
[, wrap
[, fuzzy
[, random ] ] ] ] ] duration pitch wrap specifies the duration of the sound in units of microseconds.
A
72 duration of zero will run the sound until terminated by another BEEP command.
specifies the pitch of the sound.
255 is low
A pitch of 1 is high and specifies an second pitch level between which the sound will 'bounce defines the time Interval between pitch steps.
defines the size of each step.
grad_x and grad_y control the rate at which the pitch bounces between levels.
will force the sound to wrap around the specified number of times. If wrap is equal to 15 the sound will wrap around forever.
fuzzy random defines the amount of fUZZiness to be added to the sound.
defines the amount of randomness to be added to the sound.
12/84
•
•
•
•
BEEPING is a function which will return zero (false) if the OL IS currently not beeping and a value of one (true) If it is beeping.
syntax: example:
BEEPING
100 DEFine PROCedure be_quiet
110 BEEP
120 END DEFine
130 IF BEEPING THEN be_quiet
BEEPING
sound
•
•
BLOCK will fill a block of the specified size and shape, at the specified position relative to the origin of the window attached to the specified, or default channel.
BLOCK uses the pixel coordinate system.
syntax: width: = numeric_expression height: = numeric_expression x:
= y: =
numeric_expression
numeric_expression
BLOCK [channel,j width, height, x, y , colour example i. BLOCK 10, 10, 5, 5, 7 ii.
100 REMark "bar chart"
110 CSIZE 3,1
[a 10x10 pixel white block at 5,5]
120 PRINT "bar chart"
130 LET bottom
140 FOR bar
150
=
LET cotour
100 : size
=
1 to 10
=
20 : left
=
RND(O TO 255)
10
160 LET height = RND(2 TO 20>
170 BLOCK size, height, Left+bar*size,
180 bottom-height,O
BLOCK size-2, height-2, Left+bar*size+1, bottom-height+1,colour
190 END FOR bar
[use LET colour = RND(O TO 7) for televisionsj
BLOCK
windows
12/84 5
6
BORDER
windows
BORDER will add a border to the window attached to the specified channel, or default channel.
For all subsequent operations except BORDER the window size is reduced to allow space for the BORDER. If another BORDER command is used then the full size of the original window is restored prior to the border being added; thus multiple BORDER commands have the effect of changing the size and colour of a single border Multiple borders are not created unless speCIfic action is taken.
If BORDER IS used without specifying a colour then a transparent border of the specified width is created.
syntax: width:
= numeric_expression
BORDER [channel,] size [, cOlour] example: I.
BORDER 10,0,7 [black and white stipple border) ii.
100 REMark Lurid Borders
110 FOR thickness
=
50 to 2 STEP -2
120 BORDER thickness, RND(O TO 255)
130 END FOR thickness
140 BORDER 50
[use RND(O TO 7) for televisions)
•
•
CALL
ados
Machine code can be accessed directly from SuperBASIC by using the CALL command.
CALL can accept up to 13 long word parameters which will be placed into the 68008 data and address registers (D1 to D7, AO to />5) in sequence.
No data is returned from CALL syntax: address:
= numeric_expression data: = numeric_expression
CALL address,
*
(data]
*
[13 data parameters maximum] example: i.
CALL 262144,0,0,0 il.
CALL 262500,12,3,4,1212,6
warning
Address register A6 should not be used in routines called using this command. To return to SuperBASIC use the instructions:
MOVEQ #0,00
RTS
•
12/84
•
•
CHR$ is a function which will return the character whose value is specified as a parameter
CHR$ is the inverse of CODE.
syntax: CHR$ (numeric_expression) example: i.
ii.
PRINT CHR$(271 [print ASCII escape characterj
PRINT CHR$(6S) [print Al
CHR$
BASIC
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES wWW.mauritron.cO.uk
TEL: 01844 - 351694
FAX: 01844-352554
•
•
CIRCLE will draw a CIrcle (or an ellipse at a specified angle) on the screen at a specified position and size. The circle will be drawn In the Window attached to the specified or default channel.
CIRCLE uses the graphics coordinate system and can use absolute coordinates (i.e.
relative to the graphics origin). and relative coordinates (i.e. relative to the graphics cursor).
For relative coordinates use CIRCLE_R.
Multiple circles or ellipses can be plotted with a single call to CIRCLE.
parameters must be separated from each other with a semi colon (;)
Each set of
The word ELLIPSE can be substituted for CIRCLE If required.
syntax:
x:
= y: =
numeric_expression
numeric_expression radius: = eccentriclly: numeric_expression
= numeric_expression angle: = numeric_expression [range 0 .2
1t ] parameters: = I x.
y,
I
radius, eccentricity. angle
1
2
x
y where 1 Will draw a circle
2 will draw an ellipse of specified eccentricity and angle
CIRCLE [channel,J parameters
*[;
parameters] * horizontal offset from the graphics origin or graphics cursor verticat offset from the graphics origin or graphics cursor radius eccentricity angle radius of the circle the ratio between the major and minor axes of an ellipse.
the orientation of the major axis of the ellipse relative to the screen vertical. The angle must be specified in radians.
example: i.
CIRCLE SO,SO,20
ii.
CIRCLE 50,50,20,0.5,0
[a circle at 50,50 radius 201
[an ellipse at 50,50 major axis 20 eccentricity 0.5
and aligned with the verticaJ axisl
CIRCLE
CIRCLE_R
graphics
12/84 7
8
CLEAR
comment
CLEAR will clear out the SuperBASIC variable area for the current program and will release the space for Odos.
syntax: CLEAR example: CLEAR
CLEAR can be used to restore to a known state the SuperBASIC system. For example, if a program is broken into (or stops due to an error) while It is in a procedure then
SuperBASIC is still In the procedure even after the program has stopped. CLEAR will reset the SuperBASIC (See CONTINUE, RETRY.)
•
CLOSE
devices
CLOSE will close the specified channel.
Any window associated with the channel will be deactivated.
syntax: channel: ~ # numenc_expresslon
CLOSE channel example:
I.
CLOSE #4
Ii.
CLOSE #;nput_channeL
•
•
12/64
•
•
•
Will clear the window attached to the specified or default channel to current PAPER colour excluding the border If one has been specified.
CLS will accept an optional parameter which specifies if only a part of the window must be cleared.
syntax: part: = numenc_expression
CLS [channel,] [pari] where: pari = part a whole screen (default If no parameter)
1 - top excluding the cursor line part ~ 2 - bottom excluding the cursor line pari = 3 - whole of the cursor line pari 4 - right end of cursor line Including the cursor position example: i.
CLS ii.
CLS 3
[the whole window]
[clear the cursor line] iii.
CLS #2,2 Iclear the bottom of the window on channel 2]
CLS
windows
•
CODE is a function which returns the internal code used to represent the specified character If a string is specified then CODE Will return the internal representation of the first character of the string.
CODE is the inverse of CHR$. syntax: CODE (string_expression) example: i.
PRINT CODE("A") [prints 651 ii.
PRINT CODE("SuperBASIC") [prints 83]
CODE
12/84 9
10
CONTINUE
RETRY
error handling
CONTINUE allows a program which has been halted to be continued. RETRY allows a program statement which has reported an error to be re-executed.
syntax: CONTINUE
RETRY example: CONTINUE
RETRY
warning
A program can only continue if:
1.
No new lines have been added to the program
2. No new variables have been added to the program
3. No lines have been changed
The value of vallables may be set or changed.
•
•
COPY
COPY_N
devices
COpy will copy a file from an input device to an output device until an end of file marker is detected. COPY_N will not copy the header (if it exists) associated with a file and will allow Microdrive files to be correctly copied to another type of deVice.
Headers are associated with directory-type devices and should be removed uSing
COpy_N when copying to non-directory devices, e.g. mdv1 is a directory device; ser1 is a non-dlfectory device.
syntax: COpy device TO device
COPY_N deVice TO deVice
It must be possible to input from the source device and it must be possible to output to the destination device.
example: iii.
COpy mdv1 data fi le TO con
COpy neti-3 TOmdv1 data -
COpy N mdv1 test data TO ser1
[copy to default window]
[copy data from network station to mdv_data.]
[copy mdv1_tesLdata to serial port 1 removing header information]
•
12/84
•
•
COS syntax: will compute the COSine of the specified argument.
angle:~ numeric_expression example:
COS (angle) i.
PRINT COSltheta)
Irange -10000 .. 10000 in radians)
Ii PRINT COS 13 .141592654/2)
COS
maths functions
•
•
COT will compute the cotangent of the specified argument.
syntax: angle:= numenc_expresslon frange -30000.30000 In radiansj example:
COT (angle) i.
PRINT COT(3) ii.
PRINT COTl3.141592654/2)
COT
maths functions
12/84 11
CSIZE
windows
Sets a new character Sl2e for the window attached to the specified or default channel.
The standard size is 0,0 in 512 mode and 2,0 in 256 mode.
Width defines the horizontal size of the character space. Height defines the vertical size of the character space The character size IS adjusted to fill the space available.
•
12
Figure A Character Square width height size syntax: example:
3
2
1
°
6 pixels
8 pixels
12 pixels
16 pixels
Width: ~ numeric_expression height: ~ numenc_expression
CSIZE [channel,] Width, height
I.
CSIZE 3,0 ii.
CSIZE3,1
1
°
size
10 pixels
20 pixels
[range
[range
°
.31
.11
CURSOR
windows
CURSOR allows the screen cursor to be positioned anyWhere in the window attached to the specified or default channel.
CURSOR uses the pixel coordinate system relative to the window origin and defines the position for the top left hand corner of the cursm The size of the cursor is dependent on the character size In use.
If CURSOR is used with four parameters then the first pair is Interpreted as graphics coordinates (using the graphics coordinate system) and the second pair as the position at the cursor (in the pixel coordinate system) relative to the first point.
ThiS allows diagrams to be annotated relatively eaSily.
syntax: x: = numeric_expression
y:
=
numeric_expression
example:
CURSOR [channel,J x, y [,x, y] i.
CURSOR 0,0 ii.
CURSOR 20,30 iii.
CURSOR 50,50,10,10
•
•
12184
•
•
•
•
DATA
READ
RESTORE
BASIC
READ, DATA and RESTORE allow embedded data, contained in a SuperBASIC program, to be assigned to variables at run time.
DATA is used to mark and define the data, READ accesses the data and assigns it to variables and RES10RE allows specific data' to be selected.
DATA allows data to be defined within a program. The data can be read by a READ statement and the data assigned to variables. A DATA statement is Ignored by SuperBASIC when it IS encountered dUring normal processing.
syntax: DATA
*
[expression,]
*
READ reads data contained in DATA statements and assigns it to a list of variables.
Initially the data pointer is set to the first DATA statement in the program and is incremented aher each READ. Re-running the program will not reset the data pointer and so in general a program should contain an explicit RESIDRE
RESIDRE:
An error IS reported If a READ is attempted for which there is no DATA.
syntax: READ * [Identifier,]
* restores the data pointer, i.e. the position from which subsequent READs will read their data. If RES10RE is followed by a line number then the data pointer IS set to that line. If no parameter is specified then the data pointer is reset to the start of the program.
FOR SERVICE MANUALS syntax: RESIDRE [line_number]
CONTACT: example: 100 REMark Data statement exampLe
MAURITRON TECHNICAL SERVICES
110 DIM weekdays$(7,4)
120 RESTORE www.maurilron.co.uk
TEL: 01844 - 351694
130 FOR count= 1 TO 7 :
READ weekdays$(count)
140 PRINT weekday$
FAX: 01844 - 352554
150 DATA "MON'I,"TUE II ,"WED","THUR","FRI"
160 DATA IISAT" t
"SUN" ii.
100 DIM month$(12,9)
110 RESTORE
120 REMark Data statement exampLe
130 FOR count= 1 TO 12 :
READ month$(count)
140 PRINT month$
150 DATA "Januaryll,"February","March"
160 DATA "Apri l","MaY","June"
170 DATA "JuLy","August","S ep tember"
180 DATA "October", "November", "0ecemberll
An implicit RESTORE is not performed before running a program. This allows a single warning program to run with different sets of data. Either include a RESTORE in the program or perform an expliCit RES10RE or CLEAR before running the program
12/84 13
14
DATE$
DME
clock
DATE$ is a function which will return the date and time confained in the
OU;
clock.
The format of the string returned by DATE$ is:
"yyyy mmm dd hh:mm:ss" where yyyy is the year 1984, 1985, etc mmm is the month Jan, Feb etc d d h h mm
s s
is the day 01 to 28, 29, 30, 31 is the hour 00 to 23 are the minutes 00 to 59 are the seconds 00 to 59
DATE will return the date as a floating pOint number which can be used to store dates and limes in a compact form.
If DATE$ is used with a numeric parameter then the parameter will be interpreted as a date in floating point form and will be converted to a date string.
syntax: example:
DATE$ [get the time from the clock]
DATE$(numenc_expresslon) [get time from supplied parameter] i.
PRINT DATE$ [output the date and time] ii.
PRINT DATE$(234567) [convert 234567 to a date]
•
•
DAY$
clock
DAY$ is a function which will return the current day of the week. If a parameter is specified then DAY$ will interpret the parameter as a date and will return the corresponding day of the week.
syntax: DAY$
DAY$ (numenc_expression)
[get day from clock]
[get day from supplied parameterl example: i.
PRINT DAY$ ii.
PRINT DAY$ (234567)
[output the day]
[output the day represented by 234567
(seconds)]
•
12/84
•
•
•
•
DEFine
FuNction
END DEFine
functions and procedures
DEFine FuNction defines a SuperBASIC function. The sequence of statements between the DEFine function and the END DEFine constitute the function. The function definition may also include a list of formal parameters which will supply data for the function. Both the formal and actual parameters must be enclosed in brackets. If the function requires no parameters then there is no need to specify an empty set of brackets.
Formal parameters parameters.
take their type and characteristics from the corresponding actual
The type of data returned by the function is indicated by the type appended to the function identifier The type of the data returned in the RETURN statement must match.
An anS\\er is returned from a function by appending an expression to a RETurn statement
The type of the returned data is the same as type of this expression.
A function is activated by including its narne in a SuperBASIC expression.
Function calls in SuperBASIC can be recursive; that is, a function may call itself directly or indirectly via a sequence of other calls.
syntax: forma/_parameters:= (expression actua/_parameters:= (expression
*[, expression] *)
* [, expression] *) type: =
I
1$
1%
DEF FuNction identifier type [formal_parameters]
[LOCal identifier
* [,
Identifier]
*] statements
RETurn expression
END DEFine example:
RETurn can be at any position Within the procedure body. LOCal statements must preceed the first executable statement in the function.
10 DEFine FuNction mean(a, b, c)
20
30
40
LOCa L answer
LET answer =
RETurn answer
(a + b + c)/3
50 END DEFine
60 PRINT mean(1,2,3)
To improve legibility of programs the name of the function can be appended to the END
DEFine statement. However, the name will not be checked by SuperBASIC.
comment
12184
16
DEFine
PROCedure
END DEFine
functions and procedures
DEFine PROCedure defines a SuperBASIC procedure. The sequence of stafements between the DEFine PROCedure statement and the END DEFine statement constitutes the procedure. The procedure definition may also include a list of formal parameters which will supply data for the procedure. The formal parameters must be enclosed in brackets for the procedure definition, but the brackets are not necessary when the procedure IS called. If the procedure requires no parameters then there is no need to
Include an empty set of brackets In the procedure definition.
Formal parameters take their type and characteristics from the corresponding actual parameters.
Variables may be defined to be LOCal to a procedure. Local variables have no effect on similarly named variables outside the procedure. If required, local arrays should be dimensioned within the LOCal statement.
The procedure IS called by entering its name as the first Item In a SuperBASIC statement together with a list of actual parameters Procedure calls In SuperBASIC are recursive; that is, a procedure may call itself directly or Indirectly via a sequence of other calls.
It is possible to regard a procedure definition as a command definition ,n SuperBASIC; many of the system commands are themselves defined as procedures.
syntax: formal_parameters:
=
(expression * [, expression] *) actual_parameters:= expression
* [, expression]
*
DEFine PROCedure identifier [formal_parameters]
[LOCal identifier
*[, identifier]
*
J statements
[RETurn]
END DEFine example:
RETURN can appear at any position within the procedure body. If present the LOCal statement must be before the first executable statement in the procedure. The END DEFine statement Will act as an automatic return.
100 DEFine PROCedure start screen
110
120
130
140
WINDOW 100,100,10,10
PAPER 7 : INK 0 : CLS
BORDER 4,255
PRINT "Hello Everybody"
150 END DEFine
160 start screen ii.
100 DEFine PROCedure slow scroll(scroll limit)
110
120
130
LOCa l count
FOR count = 1 TO scroll limit
SCROLL 2
140 END FOR count
150 END DEFine
160 slow scroll 20
comment
To improve legibility of programs the name of the procedure can be appended to the
END DEFine statement. However, the name Will not be checked by SuperBASIC.
•
•
•
12184
•
DEG IS a function which will convert an angle expressed In radians to an angle expressed in degrees.
syntax: example:
DEG (numeric_expression)
PRINT DEG(PII2) [will print 90)
DEG
maths functions
•
•
DELETE will remove a file from the directory of the cartridge in the specified Mlcrodrive.
syntax: DELETE device example:
The device specification must be a Mlcrodrive device i.
ii.
DELETE
DELETE mdv1 old data mdv1-letter fi Le
DELETE
Microdrives
12/84 17
18
DIM
arrays
Defines an array to SuperBASIC.
String, integer and floating point arrays can be defined.
String arrays handle fixed length strings and the final index is taken to be the stnng length.
Array Indices run from 0 up to the maximum index specified in the DIM statement; thus
DIM will generate an array with one more element in each dimension than is actually specified.
When an array is specified it IS initialised to zero for a numeric array and zero length strings for a stnng array.
syntax: example: I.
ii.
index: ~ numenc_expresslon array: ~ indentifier(index * [, Indexl *)
DIM array *[.
array] *
DIM string array$(10,10,50)
DIM matrix(100,100)
•
•
DIMN
arrays
DIMN IS a function which will return the maximum size of a specified dimension of a specified array. If a dimension is not specified then the first dimension is assumed. If the speCified dimension does not exist or the identifier is not an array then zero is returned.
syntax: array:
= identifier index: ~ numeric_expression [1 for dimension 1, etc.]
DIMN(array [, dimension] ) example: i.
ii.
iii.
IV
v.
consider the array defined by: DIM a (2 ,3 ,4)
PRINT DIMN(A,1)
PRINT DIMN(A,2)
PRINT DIMN(A,3)
PRINTDIMN(A)
PRINT DIMN(A,4)
[will print 2]
[Will print 3]
[will print 4]
[will print 2]
[will print 0]
•
12184
•
•
•
DIR will obtain and display in the window attached to the specified or default channel the directory of the cartridge in the specified Microdrive.
syntax: DIR device
The device specification must be a valid Microdrive device
The directory format output by DIR is as follows: free_sectors: = available_sectors: = file_name: ~ the number of free sectors the maximum number of sectors on this cartridge a SuperBASIC file name screen format: Volume name
Iree_sectors I available_sectors sectors lile_name
DIR
Microdrives
example: i il.
iii.
DIR mdv1
OIR
II mdv2
/I
OIR " m dv"-& microdrive number$ &
II /I screen format: BAS I C
183 /221 sectors demo 1 demo-1 oLd demo-2-
DIV
operator
•
DIV is an operator which will perform an integer divide.
syntax: numenc_expression DIV numenc_expression example: i.
ii.
PR I NT 5 D I V 2
[will output 2]
-5 DIV 2 [will output -3]
12J84
19
DUNE
BASIC
DUNE will delete a single line or a range of lines from a SuperBASIC program.
syntax: range: = line_number TO line_number
line_number TO
TO line~number line_number
3
4
1
2
DUNE range
*
[,rangej
* where 1 will delete a range of lines
2 will delete from the specified line to the end
3 will delete from the start to the specified line
4 will delete the specified line example: ii.
DUNE 10 TO 70, 80, ZOO TO 400
[will delete lines 10 to 70 Inclusive, line 80 and lines 200 to 400 inclusive]
DUNE
[will delete nothing]
•
•
20
EDIT
The EDIT command enters the SuperBASIC line editor
The EDIT command is closely related to the AUTO command, the only difference being in their defaults. EDIT defaults to a line increment of zero and thus will edit a single line unless a second parameter is specified to define a line increment.
If the specified line already exists then the line is displayed and editing can be started.
If the line does not exist then the line number is displayed and the line can be entered.
The cursor can be manipulated within the edit line uSing the standard OL keystrokes.
EJ
B
ITJ cursor light cursor left cursor up
OJ cursor down
I
CTRL
I G
I
CTRL
I EJ same as ENTER but automatically gives previous existing line to edit next same as ENTER but automatically gives next eXisting line to edit next delete character right delete character left
When the line is correct pressing ENTER will enter the line Into the program.
If an increment was specified then the next line in the sequence will be edited otherwise edit will terminate.
syntax: increment: = numeric_expression
EDIT line_number [,increment] example: i ii.
EDIT
EDIT
10 [edit line 10 onlYI
20,10 [edit lines 20,30 etc.]
•
•
12/84
•
EOF is a function which will determine If an end of file condition has been reached on a specified channel. If EOF IS used without a channel specification then EOF will determine if the end of a program's embedded data statements has been reached.
syntax: example:
EOF [(channe01 i.
ii.
IF EOF (#6) THEN STOP
IF EOF THEN PRINT "Out of data"
EOF
devices
•
•
EXEC and EXEC_W will load a sequence of programs and execute them in parallel.
EXEC will return to the command processor aher all processes have started execution,
EXEC_W will walt until all the processes have terminated before returning.
syntax: program: ~device [used to specify a Mlcrodrive file containing the program)
EXEC program example: I.
ii.
EXEC mdv1 communcat; ens
EXEC_W mdv1 printer_process
EXEC
EXEC_W
ados
•
12/84
21
22
EXIT
repetition
EXIT will continue processing after the END ot the named FOR or REPeat structure.
syntax: example: il.
EXIT identifier
100 REM start looping
110 LET count
=
0
120 REPeat loop
130
140
LET count
= count + 1
PRINT count
150 IF count = 20 THEN EXIT loop
160 END REPeat loop
(the loop will be exited when count becomes equal to 201
100 FOR n = 1 TO 1000
110 REM program statements
120
130
REM program statements
IF RND >.5 THEN EXIT n
140 END FOR n
(the loop will be eXited when a random number greater than 0.5 is generated) •
•
EXP
maths functions
EXP will return the value of e raised to the power of the specified parameter.
syntax: example: i.
ii.
EXP (numeric_expression) (range -500 .5001
PRINT EXP (3)
PRINT EXP(3.141592654)
•
12/84
•
•
•
FILL will turn graphics fill on or off. FILL will fill any non-re-entrant shape drawn with
.the graphics or turtle graphics procedures as the shape
IS being drawn. Re-entrant shapes must be split into smaller non-re-entrant shapes.
When you have finished filling, FILL 0 should be called.
switch: ~ numenc_expression [range 0 .. 1] syntax:
FILL [channel,] switch example: FILL 1: LINE 10,10 TO 50,50 TO 30,90 TO 10,10: FILL 0
[will draw a filled triangle]
FILL 1 :CIRCLE 50,50,20:FILL 0
[will draw a lilled circle] ii.
FILL
graphics
•
FILL$ IS a function which will return a string of a specified length filled with a repetition of one or two characters.
syntax: FILL$ (string_expression,numeric_expression) example:
The string expression supplied to FILL$ must be either one or two characters long.
i.
ii.
iii.
PRINT F ILL$ ("a", 5)
PRINT FILL$(" o0", 7)
LET a$
= a$ & FILL$(" ", 10)
[will print aaaaa]
[will print 0000000)
FILL$
string arrays
•
12/84
23
FLASH
windows FlASH turns the flash state on and off. FLASH is only effective in low resolution mode.
FlASH will be effective In the window attached to the speCified or default channel. syntax: swilch:~ numeric_expression Irange 0 .1)
FlASH [channel,] swilch where: swilch ~ 0 will turn the flash off switch ~ 1 will turn the flash on example: 100 PRINT "A ";
110 FLASH 1
120 PRINT "flashing ";
130 FLASH 0
140 PRINT "word" warning Writing over part of a flashing character can produce SPUriOUS results and should be avoided.
FOR
END FOR
repetition short
The FOR statement allows a group of SuperBASIC statements to be repeated a controlled number of times. The FOR statement can be used In both a long and a short form.
NEXT and END FOR can be used together Within the same FOR loop to provide a
loop epilogue, ie. a group of SuperBASIC statements which will not be executed If a loop is exited via an EXIT statement but which will be executed if the FOR loop terminated normally.
define: for_ilem: = I numeric_expression
I numenc_exp
I numeric_exp
10
10 numeric_exp numeric_exp STEP numeric_exp for_list: = for_ilem
* [, for_item]
*
The FOR statement is followed on the same logical line by a sequence of SuperBASIC statements. The sequence of statements is then repeatedly executed under the control of the FOR statement. When the FOR statement is exhausted, processing continues on the next line. The FOR statement does not require its terminating NEXT or END
FOR. Single line FOR loops must not be nested.
syntax: FOR variable = for_list: statement *[: statement]
* example: i.
ii.
FOR i = 1, 2, 3, 4 TO 7 STEP 2 : PRINT i
FOR element
= fi rst TO last: LET buffer(elemenO
=
0 long The FOR statement is the last statement on the line. Subsequent lines contain a series of SuperBASIC statements terminated by an END FOR statement. The statements enclosec between the FOR statement and the END FOR are processed under the control of the FOR statement.
syntax: FOR variable statements
= for_list
END FOR variable example: 100 INPUT Ildata please" ~ x
110 LET factorial = 1
120 FOR value = x TO 1 STEP -1
130
140
LET factorial = factorial
PRINT x I I I I factor; a l
*
150
160
170
IF factorial>1E20 THEN
PRINT "Very large number"
EXIT value
180 END IF
190 END FOR va lue value warning A floating pOint variable must be used to control a FOR loop.
•
•
•
•
•
•
FORMAT will format and make ready for use the cartridge contained In the specified
Microdflve.
syntax: FORMAT [channel,] device
Device specifies the Microdflve fa be used for formatting and the identifier part of the specification is used as the medium or volume name for thaf cartridge. FORMAT will wrife the number of good sectors and the total number of sectors available on the cartridge on the default or on the specified channel.
It is helpful to format a new cartridge several times before use. This conditions the surface of the tape and gives greater capacity.
example: i.
ii.
FORMAT mdv1 data cartridge
FORMAT mdvZ=wp_Letters
FORMAT can be used to reinitialise a used cartridge.
However, all data contained on that cartridge will be lost.
FORMAT
Microdrives warning
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEl: 01844·351694
FAX: 01844·352554
•
For compatibility with other BASICs, SuperBASIC supports the GOSUB statement.
GOSUB transfers processing to the specified line number; a RETurn statement will transfer processing back to the statement tollowing GOSUB.
The line number specification can be an expression.
syntax: GOSUB line_number example I.
ii.
GOSUB 100
GOSUB 4*seLect variabLe
The control structures available in SuperBASIC make the GOSUB statement redundant.
GOSUB
comment
12/84 25
GOTO
For compatibility with other BASICs, SuperBASIC supports the
Gam statement.
Gam will unconditionally transfer processing to the statement number specified. The statement number specification can be an expression.
syntax:
Gam line~number example:
I.
ii.
GOTO program start
GOTO 9999 comment The control structures available In SuperBASIC make the GOTO statement redundant.
•
26
IF
THEN
ELSE
END IF
The IF statement allows conditions to be tested and the outcome of that test to control subsequent program flow.
The IF statement can be used in both a long and a short form: short The THEN keyword is followed on the same logical line by a sequence of SuperBASIC keyword. This sequence of SuperBASIC statements may contain an ELSE keyword. If the expression in the IF statement is true (evaluates to be non-zero), then the statements between the THEN and the ELSE keywords are processed.
If the condition is false
(evaluates to be zero) then the statements between the ELSE and the end of the line are processed.
If the sequence of SuperBASIC statements does not contain an ELSE keyword and if the expression in the IF statement is true, then the statements between the THEN keyword and the end of the line are processed. If the expression is false then processing continues at the next line.
syntax:
statements:
=
statement
* [:
statement]
*
IF
expression
THEN
statements
[:ELSE
statements]
example: i.
ii.
iii.
IF a:32 THEN PRINT "Lim;t" : ELSE PRINT "OK
IF test> maximum THEN LET maximum
IF "1"+1=2 THEN PRINT "coercion OK"
= test
II long 1 The THEN keyword is the last entry on the logical line. A sequence of SuperBASIC statements is written following the IF statements. The sequence is terminated by the END
IF statement. The sequence of SuperBASIC statements is executed if the expression contained in the IF statement evaluates to be non zero. The ELSE keyword and second sequence of SuperBASIC statements are optional.
long 2 The THEN keyword is the last entry on the logical line. A sequence of SuperBASIC statements follows
on
subsequent lines, terminated by the ELSE keyword. IF the expression contained in the IF statement evaluates to be non zero then this first sequence of SuperBASIC statements is processed. After the ELSE keyword a second sequence of SuperBASIC statements is entered, terminated
by
the END IF keyword, If the expression evaluated by the IF statement is zero then this second sequence of SuperBASIC statements is processed.
12/84
•
•
•
•
•
• syntax: example:
IF expression THEN statements
[ELSE statements]
END IF
100 LET limit; 10
110 INPUT "Type; n a number ll !
number
120 IF number> Limit THEN
130 PRINT "Range error"
140 ELSE
150 PRINT "Inside limit"
160 END IF
In all three forms of the IF statement the THEN is optional. In the short form it must be replaced by a colon to distinguish Ihe end of the IF and the start of the next statement.
In the long form it can be removed completely.
IF statements may be nested as deeply as the user requires (subject to available memory).
However, confUSion may arise as to which ELSE, END IF etc matches which IF
SuperBASIC will match nested ELSE statements etc to the closest IF statement, for example:
100IFa;bTHEN
110 IFc;dTHEN
120
130
PRINT "errorll
ELSE
"no error" 140
150
160 ELSE
END IF
170 PRINT
180 END IF
"not checked ll
The ELSE at line 130 is matched to the second IF. The ELSE at line 160 is matched with the first IF (at line 100).
comment nesting
This sets the current ink colour, i.e. the colour in which the output is written. INK will be effective for the window attached to the specified or default channel.
syntax: INK [channel,] colour example: i.
ii.
iii.
INK 5
INK6,2
INK #2,255
INK
windows
12/84
INKEY$
INKEY$ IS a function which returns a Single character Input from either the specified
Or default channel.
An
optional timeout can be specified which can walt for a specified lime before returning, can return Immediately or can walt for ever If no parameter IS specified then INKEY$ will return immediately.
syntax: example:
INKEY$ [[(channel)
I
(channel, time)
I
(time)] i.
il.
iiI.
IV.
v.
where: time time ~
1 .. 32767 [wait for specified number of frames] time ~ 0
-1 [wait foreverj
[return Immediately]
PRINT INKEY$
PRINT INKEY$(#4)
PRINT INKEY$(5OJ
PRINT INKEY$(Q)
[input from the default channel]
[input from channel 4j
Iwait for 50 frames then return anyway]
Ireturn immediatly (poll the keyboard)]
PR I NT IN KEY$ (#3,100) [walt for 100 frames for an input from channel 3 then return anyway]
•
•
28
INPUT
INPUT allows data to be entered Into a SuperBASIC program directly from the OL keyboard by the user. SuperBASIC halts the program until the specified amount of data has been input; the program will then continue. Each item of data must be terminated by the ENTER key.
INPUT will input data from either the specified or the default channel.
If input is required from a particular console channel the cursor for the window connected to that channel will appear and start to flash.
syntax: separator: ~ example: ii.
iii.
I TO prompt:= [channel,] expression separator
INPUT [prompt] [channel] variable
*
I ,variable]
*
INPUT ("Last guess guess
"& guess & "New guess?") !
INPUT "What ;s your guess?"; guess
100 INPUT "array size?" !
Limit
110 DIM array(limit-1)
120 FOR eLement = 0 to Limit-1
130 INPUT ("data for eLement" & element)
I array(eLement)
140 END FOR element
150 PRINT array
•
•
12/84
•
•
INSTR is an operator which will determine if a given substring is contained within a specified string. If the string is tound then the substring's position is returned. If the string is not found then INSTR returns zero.
Zero can be interpreted as false, i.e. the substring was not contained in the given string.
A non zero value, the substrings position, can be intepreted as true, i.e. the substring was contained in the specified string.
syntax: string_expression INSTR string expression example: I.
il.
iii.
PRINT lI a " INSTR "cat ll
PRINT "CAT" INSTR "concatenate"
PRINT "x" INSTR "eggs"
[will print
21
[will print 4)
[will print 0)
INSTR
operator
•
INT will return the Integer part of the specified floating point expression.
syntax: INT (numenc_expression) example: i.
ii.
PRINT INT(X)
PRINT INT(3.141592654/2)
INT
maths functions
12/84
29
30
KEYROW
KEYROW is a function which looks at the instantaneous state of a row of keys (the table below shows how the keys are mapped onto a matrix of 8 rows by 8 columns). KEYROW takes one parameter, which must be an Integer in the range a to 7: this number selects which row IS to be looked at. The value returned by KEYROW is an Integer between a and 255 which gives a binary representation indicating which keys have been depressed in the selected row
Since KEYROW is used as an alternative to the normal keyboard Input mechanism using
INKEY$ or INPUT, any character in the keyboard type-ahead buffer are cleared by
KEYROW: thus key depreSSions which have been made before a call to KEYROW will not be read by a subsequent INKEY$ or INPUT.
Note that multiple key depressions can cause surprising results. In particular, it three keys at the corner of a rectangle in the matrix are depressed simultaneously, it will appear as if the key at the tourth corner has also been depressed. The three special keys CTRL,
SHIFT and ALT are an exception to thiS rule, and do not interact with other keys in thiS way.
syntax: row: = numenc_expresslon
I range a .71
KEYROW (row) example: 100 REMark run this program and press a few keys
110 REPeat loop
120 CURSOR 0.0
130
140
FORrow=Oto7
PRINT row
I I I
KEY ROW (row)
150 END FOR row
160 END REPeat loop
KEYBOARD MATRIX
COLUMN
ROW 2 4 8 16 32 64 128
ALT X V I N 7 SHIFT CTRL
2 6 8 6 Q.
E 0 T y
U
5 9 W I TAB R
3
4
2 I
I
L 3
CAPS
LOCK z
H
K
ENTER
~
o
F4 F1
1
S
C
A
F
B up ESC
~
5 F2 F3
-
P 0 J
~
G
£ M
-
\
SPACE down
F5 4 7
•
•
•
•
12/84
•
LBYTES will load a data file into memory at the specified start address.
syntax: example: i.
slaLaddress: = numeric_expression
LBYTES device ,staLaddress
Ii.
LBYTES mdv1 screen, 131072
[load a screenlmage)
LBYTES mdv1 program, start address
!load a program at a specified address)
LBYTES
devices
Microdrives
•
•
LEN is a function which will return the length of the specified string expression.
syntax: LEN (string_expression) example: ii.
PRINT LEN( "LEN wi II find the length of this string")
PRINT LEN(output_stringS)
LEN
string arrays
12/84
31
LET
LET starts a SuperBASIC assignment statement The use of the LET keyword IS optional.
The assignment may be used for both string and numeric assignments. SuperBASIC will automatically convert unsuitable data types to a sUitable form wherever possible.
syntax:
I
LET] variable = expression example: i.
II.
iii.
iv.
LET a
LET a$
LET a$
= 1 + 2
= "12345"
= 6789 b$ = test data
•
32
LINE
L1NE_R
graphics
LINE allows a straight line to be drawn between two points In the window attached to the default or specified channel. The ends of the line are specified using the graphics coordinate system.
Multiple lines can be drawn with a single LINE command.
The normal speCiticatlon requires specifying the two end points for a line. These end points can be specified either in absolute coordinates (relative to the graphics ongin) or in relative coordinates (relative to the graphics cursor). If the first point is omitted then a line IS drawn from the graphics cursor to the speCified point If the second pOint IS omitted then the graphics cursor is moved but no line IS drawn.
LINE will always draw with absolute coordinates, i.e. relative to the graphics ongin, while
L1NE_R will always draw relative to the graphics cursor.
syntax:
x:
= numenc_expression l' = numeric_expression point= x, y parameter~2: = I TO point
I ,point TO point parameteU: ~ I TO point, angle
I TO point
I point
LINE [channel,] parametec..
J
* [, parameter:..2]
*
L1NE_R [channel,J parameter......1
*
[,parameter:..2J
*
1
2
3
1
2 where 1 will draw from the specified pOint to the next specified point
2 will draw from the the last pOint plotted to the specified point
3 will move to the specified point .. no line will be drawn example: i.
ii.
iii.
LINE 0,0 TO 0, 50 TO 50,0 TO 50,0 TO 0,0
LINE TO
LINE
0,75,0.5 [a line]
25,25 fmove the graphics cursor] la square)
12/84
•
•
•
•
•
LIST
allows a SuperBASIC line or group of lines to be listed on a specific or default channel.
LIST
is terminated by
I
CTRL
II space syntax: line: = line_number 10 line_number
line_number TO
TO line~number
Ime_number 4
5
1
2
3
LIST
[channel,] line
*
[,1me]
* where 1 will lisl from the specified line to the speCilied line
2 Will list from the specified line to the end
3 will list from the start to the specified line
4 will list the specified line
5 will list the whole program
LIST
example: i.
ii.
iii.
LIS T
LIST 10 to 300
LI ST 12.20.50
llist all lines]
[list lines 10 to 300)
[list lines 12,20 and 50 only]
If
LIST
output is directed to a hard copy.
channel opened as a printer channel then
LIST
Will provide
comment
•
LOAD will load a SuperBASIC program from any OL device. LOAD automatically performs a NEW before loading another program, and so any previously loaded program will be cleared by LOAD.
If a line input during a load has incorrect SuperBASIC syntax, the word MISTAKE IS inserted between the line number and the body of the line. Upon execution, a line of this sort will generate an error syntax: example:
LOAD device i.
LOAD "mdv1 test program" ii.
LOAD mdv1 gamesiii.
LOAD net ;-3 iv.
LOAD ser1-e
LOAD
devices
Microdrives
12/84
33
34
LN
LOG10
maths functions
LN will return the natural logarithm of the specified argument. LOG10 will return the common logarithm. There is no upper limit on the parameter other than the maximum number the computer can store.
syntax: LOG10 (numeric_expression) [range greater than zero]
LN (numeric_expression) [range greater than zero] example: i.
PRINT LOG10CZO) ii.
PRINT LNC3.141592654)
•
FOR SERVICE MANUALS
CONTACT:
MAUR1TRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
•
LOCal
functions and procedures comment
LOCal allows identifiers to be defined to be LOCal to a function or procedure. Local identifiers only exist within the function or procedure In which they are defined, or in procedures and functions called from the function or procedure in which they are defined.
They are lost when the function or procedure terminates.
l.Dca1 identifiers are independent of similarly named identifiers outside the defining function or procedure. Arrays can be defined to be local by dimensioning them within the LOCal statement.
The LOCal statement must precede the first executable statement in the function or procedure in which it is used.
syntax: example:
LOCal identifier * [.
identifier] * i.
LOC a La, b,
C
C10,1 Q)
Ii.
LOCaL temp_data
Defining variables to be LOCal allows variable names to be used within functions and procedures without corrupting meaningful variables of the same name outside the function or procedure.
•
1?/R4
•
LRUN will load and run a SuperBASIC program from a specified device.
LRUN will perform NEW before loading another program and so any previously stored SuperBASIC program will be cleared by LRUN.
If a line input dUring a loading has Incorrect SuperBASIC syntax, the word MISTAKE
IS inserted between the line number and the body of the line. Upon execution, a line of this sort will generafe an error.
syntax: example:
LRUN deVice
I.
LRUN mdv2 TEST ii.
LRUN mdv1 game
LRUN
devices
Microd rives
•
•
MERGE will load a file from the speCified device and Interpret it as a SuperBASIC program.
If the new file contains a line number which doesn't appear In the program already in the OL then the line will be added. If the new file contains a replacement line for one that already exists then the line will be replaced. All other old program lines are left undisturbed.
If a line input during a MERGE has incorrect SuperBASIC syntax, the word MISTAKE
IS inserted between the line number and the body of the line. Upon execution, a line of this sort will generate an error syntax: example:
MERGE device i.
MERGE mdv1 over lay program ii.
MERGE mdv1 new data
MERGE
devices
Microdrives
12/84
35
36
MOD
operators
MOD is an operator which gives the modulus, or remainder, when one Integer IS divided by another numeric~expression MOD numenc_expression syntax: example: I.
PRINT 5 MOD 2
II.
PR I NT 5 MOD 3
[will print 1]
[will print 2]
•
MODE
screen
MODE sets the resolution of the screen and the number of solid colours which It can display.
MODE will clear all windows currently on the screen, but will preserve their position and shape. Changing to low resolution mode (8 colour) Will set the minimum character size to 2,0.
MODE numeric_expression syntax: example: where: 8 or 256 will select low resolution mode
4 or 512 will select high resolution mode i.
MODE 256 ii.
MODE 4
•
•
12/84
•
•
MOVE will move the graphics turtle In the window attached to the default or specified channel a specified distance in the current direction. The direction can be specified using the TURN and TURNTO commands. The graphics scale factor is used In determining how far the turtle actually moves. Specifying a negative distance will move the turtle backwards.
The turtle IS moved in the wmdow attached to the specified or default channel.
syntax: distance: = numeric_expression example
MOVE [channel,] distance
MOVE #2,20
Ii.
MOVE -50
[move the turtle in channel 2 20 units forwards]
[move the turtle in the default channel 50 units backwards]
MOVE
turtle graphics
•
MRUN will interpret a file as a SuperBASIC program and merge it with the currently loaded program.
If used as direct command MRUN will run the new program from the start. If used as a program statement MRUN will continue processing on the line following MRUN.
If a line input during a merge has incorrect SuperBASIC syntax, the word MISTAKE is inserted between the line number and the body of the line. Upon execution, a line of thiS sort will generate an error.
syntax: example:
MRUN deVice i.
MRUN mdv1 chain program ii.
MRUN mdv1 new data
MRUN
devices
Microdrives
12184 37
J8
NET
network
NET allows the neI'MJrk station number to be set If a station number is not explicitly set then the QL assumes station number 1.
syntax: station:= numeric_expression [range 1 .. 127)
NET station example: i.
NET 63 ii.
NET 1 comment Confu~on may arise it more than one station on the neMork has the
same
station number.
•
NEW
NEW
will clear out the old program, variables and channels other than 0,1 and 2.
syntax: NEW
example: NEW
•
•
12184
•
•
NEXT is used to terminate, or create a loop epilogue in, REPeat and FOR loops.
syntax: NEXT identifier example:
The Identifier must match that of the loop which the NEXT is to control
10 REMark this loop must repeat forever
11 REPeat infinite loop
12 PRINT "stiLL looping"
13 NEXT infinite_loop ii.
10 REMark this loop wi lL repeat 20 times
11 LET Limit = 20
12 FOR index=1 TO limit
13 PRINT index
14 NEXT index lii.10REMarkthisLoopwilltetLyouwhena30isfound
11 REPeat loop
12
13
14
LET number = RND(1 TO 10m
IF number
<>
30 THEN NEXT Loop
PRINT number; "is 30"
15 EXIT LOOP
16 END REPeat Loop
If NEXT is used inside a REPeat· END REPeal construct it will force proceSSing to continue at the statement following the matching REPeat statement.
The NEXT statement can be used to repeat the FOR loop with the control variable set at its next value. If the FOR loop is exhausted then processing will continue at the statement following the NEXT; otherwise processing will continue at the statement after the FOR
NEXT
repetition in REPeat in FOR
•
ON GOTO
ON GOSUB
To provide compatibility with other BASICs, SuperBASIC supports the ON GOTO and
ON GOSUB statements. These statements allow a variable to select from a list of possible line numbers a line to process in a GOTO or GOSUB statement. If too few line numbers are specified in the list then an error is generated.
syntax: ON variable GOTO expression
ON variable GOSUB expression
* [, expression]
*
* [.
expression]
* example:
I.
ON x GOTO 10, 20, 30, 40 ii.
ON select_variable GOSUB 1000, 2000,3000,4000
SElect can be used to replace these two BASIC commands.
comment
39
12/84
OP:N
OPEN_IN
OPEN_NEW
C8'JJ~es
Mic=-Ives
01 'EN allows the user 10 link a logical channel to a physical QL device for I/O purposes.
lillie channel is to a Mlcrodrive then the Microdnve file can be an existing file or a new
III" In which case OPEN_IN will open an already existing Mlcrodnve tile for input and
01 'EN_NEW will create a new Microdnve tile for output.
"Vlllax: channel: ~
# numeric_expression
OPEN channel, device
"",mple: OPEN #5, f_name$ ii.
OPEN IN #9, "mdv1 fi Le name ll
[open-file mdv1_file_name] ill.
OPEN NEW #7, mdv1 data fi Le
[open-file mdv1_datLfile) -
IV.
OPEN #6, con 10x20a20x20 32
[Open channel
6 to the consoledevice creating a window size
10x20 pixels at position 20,20 with a 32 byte keyboard type ahead buffer.] v.
OPEN #8, mdv1 read_write_fi teo
•
•
OVER
wiroaws
OVER selects the type of over printing reqUired in the window attached to the specified or default channel. The selected type remains in effect until the next use of OVER.
SY"lax: eX"-~:T1ple: swltch:~ numeric_expression [range -1 .. 1)
OVER [channel,] switch where switch ~ 0 - print ink on strip switch ~ 1 - print in Ink on transparent strip switch ~ -1 - XORs the data on the screen
I.
OVER 1 [set 'bverprintlng"]
Ii.
10 REMark Shadow Writing
11 PAPER 7 : INK 0 : OVER 1 CLS
12CSIZE3,1
13 FOR i = 0 TO 10
14
15
CURSOR i, i
IF i=10 THEN INK 2
16 PRINT "Shadow"
17 END FOR i
•
12/84
•
•
PAN the entire current window the specified number of pixels to the leh or the right
PAPER is scrolled in to fill the clear area.
An optional second parameter can be specified which will allow only part of the screen to be panned.
syntax: distance: ~ numenc_expresslon part: = numenc~expression
PAN [channel,] distance [, partl where part 0 - whole screen (or no parameter) part 3 - whole of the cursor line part 4 right end of cursor line Including the cursor pOSition
If the expression evaluates to a positive value then the contents of the screen will be shihed to the right example: i.
PAN #2,50 Ipan leh 50 pixels] ii.
PAN -100 Ipan right 100 pixelsl iii.
PAN 50,3 [pan the whole of the current cursor line 50 pixels to the rlghtl
If stipples are being used or the screen is in low resolution mode then, to maintain the stipple pattern, the screen must be panned in multiples of two pixels.
PAN
windows warning
PAPER sets a new paper colour (Ie. the colour which will be used by CLS, PAN,
SCROLL, etc). The selected paper colour remains In effect until the next use of PAPER.
PAPER will also set the STRIP colour
PAPER will change the paper colour in the window attached to the specified or default channel • syntax: example:
PAPER [channel,] colour
PAPER #3,7
II.
PAPER 7,2 ill.
PAPER 255
[White paper on channel
[White and red stipple]
[Black and white stipple]
31
IV.
10 REMark Show colours and stippLes
11 FOR cotour = 0 TO 7
12 FOR contrast = 0 TO 7
13 FORstippLe=OT03
14
15
16
PAPER coLour, contrast, stippLe
SCROLL 6
END FOR stippLe
17 END FOR cant rast
18 END FOR co lour
[not suitable for televlsionsl
PAPER
windows
12/84
41
PAUSE
PAUSE will cause a program to wait a specified period of time. Delays are specified in units of 20ms in the UK only, otherwise 16.67ms. If no delay is specified then the program will pause Indefinitely. Keyboard input will terminate the PAUSE and restart program execution.
syntax: delay: ~ numeric_expression
PAUSE [delay] example: I.
PAUSE 50
Ii.
PAUSE 500
[wait 1 secondj
[wait 10 secondsj
•
42
PEEK
PEEILW
PEEILL
BASIC
PEEK is a function which returns the contents of the specified memory location.
PEEK has three forms which will access a byte (8 bits), a word (16 bitS), or a long word
(32 bits).
syntax: address: = numeric_expression
PEEK(address) [byte accessJ
PEEK.-W(address) [word access]
PEEK.-L(address) [long word accessJ example: I.
PRINT PEEK(12245) [byte contents of location 12245] ii.
PRINT PEEK W(12) [word contents of locations 12 and 13J iii.
PRINT PEEK-L(1000l [long word contents of location 1000J
warning
For word and long word access the specified address must be an even address.
•
12/84
•
•
•
•
Operates the 'pen' In turtle graphics. If the pen is up then nothing Will be drawn. If the pen is down then lines will be drawn as the turtle moves across the screen.
The line will be drawn in the window attached to the specified or default channel. The line will be drawn In the current ink colour for the channel to which the output is directed.
syntax: PENUP [channe~
PENDOWN [channe~ example: i.
PENUP ii.
PENDOWN #2
[will raise the pen in the default channel]
[will lower the pen in the window attached to channel 2)
PENUP
PENDOWN
turtle graphics
PI
maths functions
•
PI is a function which returns the value of 7t.
syntax: PI example:
PRINT PI
12/84 43
POINT
POINT_R
graphics
POINT plots a point at the speCified position In the window attached to the specified or default channel. The point IS plotted uSing the graphics coordinates system relative to the graphics ongm. If POINT_R is used then all points are specified relative to the graphics cursor and are plotted relative to each other
Multiple pOints can be plotted with a single call to POINT syntax: example: x:= numenc_Bxpression y: =
numenc_expression
parameters: = x , y
POINT [channel,] parameters
*
[,parameters]
*
I.
POINT 256,128 ii.
POINT X,
x*x
iii.
10 REPeat examp Ie
20 INK RND(255)
30 POINT RND(100) ,RND(100)
(plot a point at (256,128)]
(plot a point at (x,x
* x)]
40 END REPeat exampte •
•
44
POKE
POKE_W
POKE_L
BASIC
POKE allows a memory location to be changed. For word and long word accesses the specified address must be an even address.
POKE has three forms which will access a byte
(32 bits).
(8 bits), a word (16 bits), a long word syntax: address: data: ~
= numenc_expresslon numeric_expression
POKE address, data
PGKLW address, data
POKLL address, data
[byte access]
[word access]
[long word access] example: i.
ii.
POKE 12235,0
POKE_L 131072, 12345
(set byte at 12235 to 0]
(set long word at 131072 to
12345]
warning
Poking data into areas of memory used by Odos can cause the system to crash and data to be lost Poking into such areas' IS' not recommended.
•
•
12/84
•
•
Allows output to be sent to the specified or default channel. The normal use of PRINT is to send data to the OL screen. syntax: separator: ~ I !
I ,
I \
I ;
I TO numeric_expression item: ~ I expression
I channel
I separator
*
[item]
*
Multiple print separators are allowed. At least one separator must separate channel specifications and expressions. example: PRINT "HeLLo World"
[will output Hello World on the default output device (channel 1)] ii.
PRINT #5, lIdata", 1 ,2,3,4
[will output the supplied data to channelS (which must have been previously opened)] iii.
PRINT TO 20; "This is in coLumn 20"
Normal action is to insert a space between items output on the screen. If the item will not fit on the current line a line feed will be generated. If the current print position is at the start of a line then a space Will not be output.
!
affects the next item to be printed and therefore must be placed in front of the print i~m being printed.
Also a ; or a !
must be placed at the end of a print list if the spacing IS to be continued over a series of PRINT statements.
Normal separator, SuperBASIC will tabulate output every 8 columns.
Will force a new line.
Will leave the print position immediately after the last item to be printed. Output Will be printed in one continuous stream.
TO Will perform a tabbing operation.
10 followed by a numeric_expression Will advance the print position to the column specified by the numeric_expressIon. If the requested column is meaningless or the current print posilion is beyond the specified position then no action will be taken.
devices
Microdrives separators
RAD
maths functions
RAD is a function which Will convert an angle specifiec in degrees to an angle specified in radians.
syntax: example:
RAD (numeric_expression)
PRINT RAO(180) [will print 3.141593]
,
12/84
45
46
RANDOMISE
maths functions
RANDOMISE allows the random number generator to be reseeded. If a parameter
IS specified the parameter is taken to be the new seed. If no parameter is specified then the generator is reseeded from internal information.
syntax: example:
RANDOMISE [numeric_expressionl i.
RANDOMISE ii.
RANDOMISE 3.2235
[set seed to internal data)
[set seed to 3.2235]
•
RECOL
windows
RECOl will recolour individual pixels in the window attached to the specified or default
channel according to some preset pattern. Each parameter is assumed to specify, in order, the colour in which each pixel is recoloured, i.e. the first parameter specifies the colour with which to recolour all black pixels, the second parameter blue pixels, etc.
The colour specification must be a solid colour, i.e. it must be in the range 0 to 7 syntax: example: cO: ~ new colour for black
cl:= new colour for blue c2:~ c3: new colour for red
= new colour for magenta
c4:= new colour for green c5: = new colour for cyan c6: ~ new colour for yellow c7: = new colour for white
RECOl [channel ,I cO, cl,
c2,
c3, c4, c5, c6, c7
RECOl 2,3,4,5,6,7,1,0 !recolour blue to magenta, red to green, magenta to cyan etc.1
•
•
12/84
• REMark allows explanatory text to be inserted into a program. The remainder of the line is ignored by SuperBASIC.
syntax: REMark
text
example: REMark This is a comment in a program
REMark is used to add comments to a program to aid clarity.
REMark
comment
•
•
RENUM allows a group or a series of groups of SuperBASIC line numbers to be changed. If no parameters are specified then RENUM will renumber the entire program.
The new listing will begin at line 100 and proceed in steps of 10.
If a start line is specified then line numbers prior to the start line will be unchanged.
If an end line is specified then line numbers following the end line will be unchanged.
If a start number and stop are specified then the lines to be renumbered will be numbered from the start number and proceed in steps of the specified size.
If a GOlD or GOSUB statement contains an expression starting with a number then this number is treated as a line number and is renumbered.
syntax:
starl.-line:= end_line:
=
numeric_expression
[start renumber]
numeric_expression
[stop renumber)
starl.-number:= numeric_expression
[base line number)
step:
=
numeric_expression
[step)
RENUM
(starl.-line
[10
end_line];] [starl.-number] [,step]
example: i.
RE NUM [renumber whole program from 100 by 10) ii.
RENUM 100 TO 200 [renumber from 100 to 200 by 10)
No attempt must be made to use RENUM to renumber program lines out of sequence.
ie to move lines about the program.
RENUM should not be used in a program.
RENUM
warning
12/84
47
48
REPeat
END REPeat
repetition short long comment
REPeal allows general repeat loops to be constructed. REPeat should be used with
EXIT for maximum effect REPeal can be used In both long and short forms:
The REPEAT keyword and loop Identifer are followed on the same logical line by a colon and a sequence of SuperBASIC statements. EXIT will resume normal processing at the next logical line.
syntax: example:
REPeal idenlifier : statements
REPeat wait: IF INKEY$
<> ""
THEN EXIT wait
The REPEAT keyword and the loop identifier are the only statements on the logical line.
Subsequent lines contain a series of SuperBASIC statements terminated by an END
REPeal statement.
The statements between the REPeal and the END REPeat are repeatedly processed by SuperBASIC syntax: REPeal identifier statements
END REPeat identifier example: 10 LET number = RND(1 TO So)
11 REPeat guess
12
13
14
INPUT IlWhat is your guess?". guess
IF guess
= number THEN
PRINT "You have guessed correct Lyll
15
16
EXIT guess
E LS E
17 PRINT "You have guessed incorrectly"
18 END IF
19 END REPeat guess
Normally at least one statement In a REPeat loop will be an EXIT statement.
RESPR
Odos
RESPR is a function which will reserve some of the resident procedure space. (For example to expand the SuperBASIC procedure list.) syntax: space:
= numeric_expression
RESPR (space) example: PRINT RESPR(1024)
[will print the base address of a 1024 byte block)
•
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL 01844.351694
Ft0<: 01844 - 352554
12/84
•
•
•
•
RETurn is used to force a function or procedure to terminate and resume processing at the statement after the procedure or function call. When used within a function definition theRETurn statement is used to return the function's value.
RETurn
functions and procedures
syntax: example:
RETurn [expression]
100 PRINT ack (3,3)
110 DEFine FuNction ack(m,n)
120 IF m=O THEN RETurn n+1
130
140
IF n=O THEN RETurn ack (m-1,ll
RETurn ack(m-1,ack(m,n-1»
150 END DEFine ii.
10 LET warning flag = 1
11 LET error number = RND(O TO 10J
12 warning e-;ror number
13 DEFine PROCedure warning(n)
14 IF warning flag THEN
15
16
17
18
19
PRINT "WARNING:";
SELect ON n
ON n = 1
PRINT "Microdrive full"
ON n
=
2
PRINT "Data space full" 20
21
22
23
24
25
ON n = REMAINDER
PRINT "Program error ll
END SELect
ELSE
RETurn
26 END IF
27 END DEF i ne
It is not compulsory to have a RETurn in a procedure. If processing reaches the END
DEFine of a procedure then the procedure will return automatically.
RETurn by Itself is used to return from a GOSUB.
comment
RND
maths functions
RND generates a random number. Up to two parameters may be specified for RND.
If no parameters are specified then RND returns a pseudo random floating pomt number in the exclusive range 0 to 1. If a single parameter is specified then RND returns an integer in the Inclusive range 0 to the specified parameter If twc parameters are specified then RND returns an integer in the inclusive range specified by the two parameters.
syntax: example:
RND ( [numenc_expresslon]
[10
numenc_expressionj)
PRINT RND ii.
iii.
iv.
PRINT RND(10 TO 20)
PRINT RND(1 TO 6)
PRINT RND(10)
[ftoating pOint number between o and 11
[integer between 10 and 201
(integer between
[integer between
1 and 61
°
and 101
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 . 351694
FAX: 01844 352554
12/84
49
50
RUN
program RUN
allows a SuperBASIC program to be started. If a line number is specified in the
RUN
command then the program will be started at that pOint, otherwise the program will start at the lowest line number.
syntax:
RUN
[numeric_expression] example:
I.
RUN
Ii.
RUN 10
[run from startJ
I run from line 101 iii.
RUN 2*20 [run from line 40J
comment
Although
RUN
can be used within a program its normal use is to start program execution by typing It in as a direct command
•
SAVE
devices
Microdrives SAVE
will save a SuperBASIC program onto any QL device.
syntax: line: = numeric_expression 10 numeric_expression numeric_expression 10
10 numenc_expression numeric_expression
SAVE
device
*
[,line]
* where 1 will save from the specified line to the specified line
2 will save from the specified line to the end
3 will save from the start to the specified line
4 will save the specified line
5 will save the whole program
1
2
3
4
5 example: SAVE mdv1 program, 20 TO 70
[save lines 20 to 70 on mdv1_programJ
Ii.
SAVE mdv2 test program, 10,20,40
[save lines 10,20,40 on mdv1_tesLprogramJ iii.
SAVE net3
[save the entire program on the network]
IV.
SAVE ser1
[save the entire program on serial channel 1J
•
•
12/84
•
•
SBYTES syntax: allows areas of the OL memory to be saved on a slarLaddress: ~ numenc_expresslon
OL device.
length: ~
SBYTES numeric_expression device, slarLaddress, length example: SaYTES mdv1 screen data, 131072,32768
[save memory50000 length 10000 bytes on mdv1_tesLprogram] ii.
SaYTES mdv1 test program, 50000,10000
[save memory 50000 length 1000 bytes on mdv1_tesLprogramj iiI.
SaYTES neto 3,32768,32678
[save memory32768 length 32768 bytes on the network]
IV.
SaYTES ser1, 0,32768
[save memory 0 length 32768 bytes on senal channel 11
SBYlES
devices
Microdrives
•
SCALE allows the scale factor used by the graphics procedures to be altered.
A scale of 'x' implies that a vertical line of length 'x' will fill the vertical axis of the Window in which the figure is drawn.
A scale of 100 is the default SCALE also allows the origin of the coordinate system to be specified. This effectively allows the window being used for the graphics to be moved around a much larger graphics space.
syntax: x:
= y: ~ numeric_expression numeric_expression example: origln:~ scale: x,y
= numeric_expression
SCALE (channel,] scale, origin i.
SCALE 0.5,0.1,0.1
[set scale to 0.5 with the origin at 0.1,0.1] ii.
S CA LE 10,0,0 [set scale to 10 with the origin at 0,0)
Iii.
CA LE 100, 50, SO [set scale to 100 with the origin at 50,50)
SCALE
graphics
12/84
51
52
SCROLL
windows
SCROLL scrolls the window attached to the specified or default channel up or down by the given number of pixels. Paper IS scrolled in at the top or the bottom to fill the clear space.
An optional third parameter can be specified to obtain a part screen scroll.
syntax: pari: = numenc_expresslon distance: = numenc_expresslon example: where pari 0 - whole screen (default IS no parameter) pari = 1 - top excluding the cursor line pari ~ 2 - bottom excluding the cursor line
SCROLL [channel,] distance [, parll
If the distance is pOSitive then the contents of the screen will be shifted down.
i.
SCROLL 10 ii.
SCROLL -70 iii.
SCROLL -10,2
[scroll down 10 pixels]
[scroll up 70 pixels]
[scroll the lower part of the window up 10 pixels]
•
•
SDATE
clock
The SDATE command allows the OL:s clock to be reset.
syntax: year: ~ numeric_expression month: = numenc_expression day:
= numenc_expression hours: ~ numeric_expression minutes:
= numeric_expression seconds: = numeric_expression
SDATE year, month, day, hours, minutes, seconds example: i.
SDATE 1984,4,2,0,0,0 ii.
SDATE 1984,1,12,9,30,0 iii.
SDATE 1984,3,21,0,0,0
•
12/84
•
•
•
•
SElect allows vanous courses of action to be taken depending on the value of a vanable.
define:
selecL vanable:
~
numeric_ variable selecLitem:
~ I
expression
I
expression
TO
expression
selecL/lst:~
I
selecLitem
*[,
selecLitem]
*
Allows multiple actions to be selected depending on the value of a
selecL variabte.
long
The select variable is the last Item on the logical line. A senes of SuperBASIC
statements
follows, which IS terminated by the next ON statement or by the END SElect statement.
If the select Item is an expression then a check is made within approximately 1 part
In 10-', otherwise for expression TO expression the range is tested exactly and IS inclusive. The ON REMAINDER statement allows a, 'catch-all" which will respond if no other select conditions are satisfied.
SELect
END SELect
conditions
syntax: example:
SElect ON
*[[ON
[ON
selecL variable selecLvariable] selecLlist statements]
*
selecLvanable]
~ REMAINDER
statements
END SElect
100 LET error number
=
RND(1 TO 10)
110 SELect ON error number
120 ON error number
=
1
130 PRINTIiOivide by zero"
140
150
160
LET error number = 0
ON error number
=
2
PRINTI'iFi Le not found"
170
180
LET error number = 0
ON error number = 3 TO 5
190
200
210
220
PRINT"Microdrive fi le not found"
LET error number
ON error number
=
0
=
REMAINDER
PRINT"'"'i"iUnknown error"
230 END SELect
If the select variable is used In the body of the SElect statement then
It must match the select variable given in the select header
The short form of the SElect statement allows simple single line selections to be made.
A sequence of SuperBASIC statements follows on the same logical line as the SElect statement. If the condition defined in the select statement is satisfied then the sequence of SuperBASIC statements is processed.
syntax: example:
SElect ON
selecLvariable
~
selecLlist: statement
*[:
statement]
*
SELect ON test data
=
1 TO 10 :
PRINT "Answer within range" ii.
SELect ON answer
=
0.00001 TO 0.00005
PRINT "Accuracy OK" iii.
SELect ON a = 1 TO 10: PRINT a
I
"in range"
The short form of the SElect statement allows ranges to be tested more easily than with an IF statement. Compare example ii. above with the corresponding IF statement.
short comment
•
12/84
53
54
SEXEC
Odos
Will save an area of memory in a form which is suitable for loading and executing with the EXEC command.
The data saved should constitute a machine code program.
syntax: starLaddress:= numeric_expression [start of area] length: = data-space: numeric_expression [length of area]
= numeric_expression [length of data area which will be required by the program)
SEXEC deVice, starLaddress, length, data-space example: SEXEC mdv1 program, 262144,3000,500
comment
The Odos system documentation should be read before attempting to use this command.
•
•
SIN
maths functions
SIN will compute the sine of the specified parameter.
angle:= numeric_expression [range -10000 .. 10000 in radians) syntax: example:
SIN(angle) i.
PRINT SIN(3) ii.
PRINT SINI3.141592654/2)
•
12/84
•
• will compute the square root of the specified argument The argument must be greater than or equal to zero syntax: example:
SORT (numenc_expression) (range i.
PRINT SQRT(3) ii.
LET C
=
SQRT(a
A
2 + b
A
2)
>=
OJ
(print square root of 3)
[let c become equal to the square root of a" 2
+
b" 2)
SQRT
maths functions
•
•
STOP
BASIC
STOP will terminate execution of a program and will return SuperBASIC to the command interpreter.
syntax: STOP example: i.
STOP ii.
IF n
=
100 THEN STOP
You may CONTINUE after STOP.
The last executable line of a program will act as an automatic stop.
comment
•
12/84 55
STRIP
windows comment
STRIP will set the current strip colour in the window attached to the specitied or default channel.
The strip colour is the background colour which is used when OVER 1
IS selected. Setting PAPER will automatically set the strip colour to the new PAPER colour syntax: example:
STRIP [channel,] colour i.
STR I P 7 ii.
STRIP 0,4,2
[set a white stripj
[set a black and green stipple strip)
The effect of STRIP is rather like using a highlighting pen.
•
TAN
maths functions
TAN will compute the tangent of the specified argument. The argument must be in the range -30000 to 30000 and must be specified in radians.
syntax: example:
TAN (numeric_expression) i.
TAN (3)
[range -30000.30000)
[print tan 3J ii.
TAN(3.141592654/2) [print tan 7</2J
•
•
12/84
•
•
•
TURN allows the heading of the turtle' to be turned through a specified angle while
TURNlO allows the turtle to be turned to a specific heading.
The turtle is turned In the window attached to the specified or default channel.
The angle is specified in degrees. A positive number of degrees will turn the turtle anticlockwise and a negative number will turn it clockwise.
Initially the turtle is point at O~ that is to the right hand side of the window syntax: angle:~ numeric_expression [angle in degreesl
TURN [channel,] angle
TURNlO [channel,] angle example: I.
TURN 90 [turn through 90°1
Ii.
TURNTO 0 [turn to heading 0°1
TURN
TURNTO
turtle graphics
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
•
Turns underline either on or off for subsequent output lines. Underlining is in the current
INK colour in the window attached to the specified or default channel.
syntax: switch:= numeric_expression [range 0..11
example:
UNDER [channel,] switch i.
UNDER 1 [underlining on) ii.
UNDER 0 [underlining off]
UNDER
windows
12/84
57
58
WIDTH
devices
WIDTH allows the default width for non-console based devices to be specified, for example printers.
syntax: line_width:: numeric_expression
WIDTH [channel,] line_width example: i.
WIDTH 80 ii.
WIDTH #6, 72
[set the device width to 80)
[set the width of the device attached to channel 6 to 72J
•
WINDOW
windows
Allows the user to change the position and size of the window attached to the specified or default channel. Any borders are removed when the window is redefined.
Coordinates are specified using the pixel system relative to the screen origin.
syntax: width: ~ 'numeric_expression depth:: numeric_expression x:: numeric_expression y: ~ numeric_expression
WINDOW [channel,] width, depth, x, y example: WINDOW 3D, 40, 10, 10 [window 30x40 pixels at 10,10J
•
•
12/84
Keywords Index
•
•
•
A
ABS ..
Absolute values ...
ACOT
ADATE ..
ARC cotangent ..
tangent..
ARC_R ...
Arctangent ..
Arguments ..
Arrays
DIM.
DIMN ...
Assignment ....
AT
ATAN ...
AUTO
B
BAUD ..
Baudrates ....
BEEP ....
BEEPING ..
BLOCK .
BORDER .
c
CALL
Channel
CLOSE
Character
CODE ..
repetition.
size ..
CHR$
CIRCLE.
CIRCLE_R.
CLEAR.
BASIC screen ...
.
window ..
Clock
ADATE ...
DATE
DATE$ ..
DAY$.
SDATE .
CLOSE
Closing channels....
CLS ..
CODE ..
Colour
INK.
MODE . . . . .
PAPER..
RECOL recolour
Comments
Communications baud rates networks ..
.
.. H.
.
12/84
.
.
.
2
14
14
14
52
8
8
9
9
27
36
41
46
46
47
7
8
8
9
9
9
28
12
7
7
6
8
4
38
2
14, 15
2
2
2
17
17
32
3
1
3
1
2
1
1
4
5
5
6
4
4
Conditions
IF
SELect. .. H"H' H' H' H.... H. H"H HH" H"
CONTINUE.
COPY ...
COPY_N .
COS ...
cosineH
COT cotangent..
CSIZE.
CURSOR o
DATA ...
structures H'
DATE ..
DATE$ .
DEFine
DAY$ ..
DEFine
FuNction H
PROCedureH
DEG.
Degrees H .
H
Delay H
DELETE ...
files H .
lines H'
Devices
CLOSE.
directory H
LBYTES ....
LOAD ..
load and run H
LRUNH'
MERGE ...
merge and run H
MRUN ..
NETHH'" network stationH HHHHHHHH'
OPEN ..
OPEN_IN.
open for input.
OPEN_NEW ..
open newH
RUN ..
SAVE ..
SBYTES HH.HH
DIM .
Dimension arrays H
DIMN
DIR ..
Directory
Display directory H'
DIV
DliNE 'HH
Documentation
DotsH HHHHHH.
13
18
14
14
15, 16
14
8
19
31
38
38
40
40
40
40
40
50
33
35
35
35
37
37
. 'HH.
.
50
51
18
'HH'HH 18
18
HHH .. HHH 20
19
19
19
20
'HHH 47
HHH 44
15
16
17
17
42
17
17
20
26
53
10
11
11
12
12
10
10
11
11
E
EDIT
ELLIPSE ....
ELlIPSE_R.
'HHH
20
7
'H HHHH 7
Keywords Index
END
DEFINE .....
FOR ...
IF.
REPeaL
SELect..
EOF ..
Equals.
Errors
CONTINUE ..
RETRY ..
EXEC
EXEC_W ..
EXIT ..
with FOR ...
with REPeat..
EXP ..
Exponentiation.
F
Files
COPY .
COPY_N ...
DELETE ..
DIR ..
directory ...
LBYTES ..
LOAD ..
load and run ..
LRUN ..
MERGE ..
merge and run ..
MRUN ..
.
. .....................................
OPEN ..
Open tor input ..
OPEN_IN.
open new ..
OPEN_NEW ..
PRINT ...
RUN ..
SAVE ...
FILL.
FILL$ ..
..............
.............
FLASH ...
FN ...
FOR.
with EXIT.
with NEXT
FuNction ..
DEFine.
RETurn ..
.....................
24
24
15
15
49
45
50
50
23
23
24
15
24
33
33
35
35
37
37
40
40
40
40
40
10
10
17
19
19
31
15, 16
24
26
48
53
21
32
22
24
48
22
22
10
10
21
21
G
GOSUB.
GOTO .
Graphics
ARC
ARC_R ...
CIRCLE
CIRCLE_R
.................
25
26
ELLIPSE ................................. ................
,
...
ELLlPSE_R .
FILL ..
......................
7
7
23
2
2
7
7 till shape.
LINE ..
L1NE_R
POINT
POINT_R ..
SCALE
Turtle
FILL
MOVE ...
TURN.
TURNTO.
SCALE.
PENDOWN.
PENUP ...
H
Highlighting ....
23
32
32
44
44
51
23
37
57
57
51
43
43
56
I/O
INKEY$ ..
keyboard input ..
KEYROW
IF.
printing ...
nesting.
INK ...
INKEY$ ....
INPUT.
INSTR ...
INT ...
Integer divide.
J
Jump ....
K
Keyboard input ....
KEYROW ....
L
LBYTES
LEN.
Length ot strings ..
LET.......
LINE ...
delete ...
DLiNE editor ...
numbering ...
renumbering ..
RENUM .
L1NE_R ...
LIST
LN ..
LOAD ..
load and run.
LRUN.
Local variables ..
in functions ..
in procedures.
................
........
"
.....
............ ,.",."
..
" ,
...
.
................
.............
26
28,30
30
26
27
27
28
28
29
29
18
28
30
30
45
47
47
32
33
34
33
35
35
34
15
16
32
20
20
20
3
31
31
31
32
12/84
•
•
•
•
•
•
•
Logarithm ..
LOG10.
Loop epilogue ..
Loop repetition
EXIT
FOR.
NEXT .
REPeat .
M
Machine code.
CALL
SEXEC.
saving.
EXEC ..
EXEC_W loading.
respr ..
Maths functions
ABS ..
absolute value.
ACOT .
arc cotangent .
ATAN.
arc tangent.. ..
common logarithm.
COS cosine ..
COT
EXP ..
exponentiation
.
INT integer part ..
LOG.
LN ..
natural logarithm
RAD radians conversion ..
SIN ..
sine ....
SQR square root
TAN .
tangent...
.
Merge and run.
Microdrives
COpy .
.
.
copying ..
DELETE ..
deleting files ...
FORMAL ..
formatting cartridges .
LOAD......
.
loading SuperBASIC programs
SAVE saving SuperBASIC programs.. .
.
MOD..
MODE modulus .
MOVE ..
MRUN.
Multitasking
PAUSE
SEXEC .
.
1
34
22
22
................. 29
29
34
34
34
45
45
54
54
11
11
11
55
55
56
56
37
1
1
1
1
1
.
.
.
54
54
21
21
21
48
6
6
10
10
17
17
25
25
33
33
50
50
36
36
36
37
37
42
54
12184
34
34
24
22
24
39
48
PAN ...
PAPER ..
Parameters ....
PAUSE
PEEK ..
PEELL ..
PEELW ..
PENDOWN ...
PENUP ..
PI..
Plotting pOints ..
POINT.
POINT_R
POKE.
POKE_L
POKE_W.
PRINT ..
OVER .
UNDER .
Printout ..
Procedures
DEFine
LOCal ..
RETurn .
Programs
CONTINUE.
RETRY ...
RUN ..
SAVE ..
p
N
NET
Networks ..
NEW ...
NEXT ..
with FOR ..
with REPeaL
Restarting SuperBASIC .
o
ON GOSUB
ON GOTO
OPEN ..
channel ...
serial port ..
window ..
OPEN_IN ..
open existing file ..
OPEN_NEW open new file.
Operators
INSTR ..
MOD ....
OVER overprinting ..
R
RAD.
Random numbers
RANDOMISE ..
READ ..
RECOL ...
Keywords Index
40
40
40
40
40
40
39
39
40
40
29
36
40
40
38
38
38
39
24
48
38
40
40
15, 16
42
42
42
42
43
43
43
44
44
44
44
44
44
45
40
57
45
15, 16
34
49
10
10
50
50
45
49
46
13
47
Keywords Index
REM ..
REMark ..
RENUM
Renumber lines
REPeaL.
EXIT..
.
NEXT......
Repetition
FOR.
NEXT
Reset clock
Resolution
RESPR ..
RESTORE
RETRY.
RETurn with FuNction ..
with PROCedures.
RND.
Routines .
RS-232-C .
RUN
LRUN load and run ..
.
.
s
SAVE ..
machine code programs.
SBYTES..
SCALE.....
. . . .
Screen
BLOCK........
BORDER...............
character size.. ..
clear .
FLASH
INK....
........
MODE...................
output
OVER..
overprinting....
~N..
~~R.
RECOL recolouring .
OCR~L
STRIP..
UNDER.............
underlining.
WINDOW.
SCROLL.
SDATE
SELect......
Setting clock
Setting station number
Shapes
ARC .....
CIRCLE ...
ELLIPSE
FILL.
LINE ...
SIN sine ..
.
.
47
47
.
.
47
47
.............. ..... 48
22
39
.
.
.
.
..
24
.. ......... 27
36
45
........
40
40
~
~
45
46
46
~
56
57
5
6
12
9
57
58
52
52
53
52
38
50
51
50
51
51
7
23
34
54
54
2
7
24
39
2,52
36
48
4
50
35
35
13
10
49
15
16
49
16
Size of characters ..
Sound
BEEP ..
BEEPING .
SORT
Square rooL
.
Starting programs.
Station number.
STOP.
Strings
CHR$ ...
FILL$ ..
INSTR..
LEN ..
length ...
STRIP.
subroutines.
T
TAN.
Tangent..
THEN ..
Time clock adJUSt..
clock reset..
date ....
PAUSE.
TURN ..
TURNTO ..
T,urtle graphics
FILL
MOVE ..
PENUP.
PENDOWN
TURN ....
TURNTO ...
..
u
Unconditional jump
UNDER ....
Underlining.
v
Value absolutes w
Windows
AT
BLOCK ..
BORDER
CSIZE ........
Character size ..
clear ..
cursor control ......
FILL ..
FLASH ..
INK .
MODE ..
OVER ..
overprinting ...
PAN
PAPER
..
..........
56
56
26
2
52
14
42
57
57
23
37
43
43
57
57
26
57
57
12
55
55
4
5
35,50
38
55
7
23
29
31
31
56
15, 16
•
•
•
12
................ 12
3
5
6
.... 9
3, 12
40
............. 40
........ 41
... 41
23
24
27
36
12/84
•
•
• print position ..
SCROLL
STRIP ..
UNDER ..
underlining.
WINDOW.
3
52
56
57
57
58
12/84
Keywords Index
•
Concepts
•
•
The Concept Reference Guide describes concepts relating to SuperBASIC and the OL hardware. It is best to think of the Concept Guide as a source of Information. If there are any questions about SuperBASIC or the OL Itself which arise out of uSing the computer or other sections of the manual then the Concept Guide may have the answer
Concepts are listed In alphabetical order using the most likely term for that concept
If the sublect cannot be found then consult the index which should be able to tell you which page to turn to.
Where an example is listed with line numbers, then it is a complete program and can be entered and run. Examples listed without numbers are usually simple commands and it may not always be sensible to enter them Into the computer in Isolation. Examples which demonstrate stipples will not work properly on a television set.
©1984 SINCLAIR RESEARCH LIMITED by Stephen Berry (Sinclair Research Limited)
•
•
•
arrays
Arrays must be DIMensioned before they are used. When an array is dimensioned the value of each of its elements is set to zero or a zero length string if it is a string array.
An array dimension runs from zero up to the specified value. There is no limit on the number of dimensions which can be defined other than the total memory capacity of the computer. An array of data is stored such that the last index defined cycles round most rapidly: the array defined by
DIM array(2,4) will be stored as
0,0
0,1
0,2
0,3
0,4
1,0
1,1
1,2
1,3
1,4
2,0
2,1
2,2
2,3
2,4 low address high address
example
The element referred to by array(a,b,c) is equivalent to the element referred to by array(a)(b)(c).
Command
DIM
DIMN
Function dimension an array find out about the dimensions of an array
12/84
2
BASIC
SuperBASIC Includes most of the functions, procedures and constructs found in other dialects of BASIC. Many of these funelions are superfluous In SuperBASIC but are
Included for compatibility reasons:
GOTO
GOSUB
ON GOTO
ON GOSUB use IF, REPeat, etc use DEFine PROCedure use SELect use SELect
Some commands appear not to be present. They can always be obtained by using a more general function. For example, there are no LPRINT or LLiST statements In
SuperBASIC but output can be directed to a pnnter by opening the relevant channel and uSing PRINT or LIST.
LPRINT
LLiST
VAL
STR$
IN
OUT use PRINT# use LIST# not required In SuperBASIC not required In SuperBASIC not applicable to 68008 not applicable to 68008
comment
Almost all forms of BASIC require the VAL(x$) and STR$(x) functions In order to be able to convert the Internal codified form of the' value of a stnng expression to or from the internal codified form of the value of a numeric expression.
These functions are redundant in SuperBASIC because of the provision of a unique facility referred to as 'coercion': The VAL and STR$ functions are therefore not provided.
•
•
•
12/64
•
•
•
• If at any time the computer fails fo respond or you wish to stop a SuperBASIC program or command then hold down
break
and then press
SPACE
A program broken into In this way can be restarted by using the CONTINUE command.
12/84 3
4
channels
A channel is a means by which data can be output to or Input from a QL device.
Before a channel can be used it must first be activated (or opened) with the OPEN command .
Certain channels should always be kept open: these are the default channels and allow simple communication with the QL via the keyboard and screen. When a channel is no longer In use it can be deactivated (closed) with the CLOSE command.
A channel is identified by a channel number. A channel number IS a numeric expression preceded by a #.
When the channel is opened a device is linked to a channel number and the channel is initialised. Thereafter the channel is identified only by its channel number For example:
OPEN #5,SER1
Will link serial port 1 to the channel number 5. When a channel is closed only the channel number need be specified. For example:
CLOSE #5
Opening a channel requires that the device driver for that channel be activated. Usually there is more than one way in which the device driver can be activacted, for example the network requires a station number.
This extra information IS appended to the device name and passed to the OPEN command as a parameter see concept device and peripheral expansion.
Data can be output to a channel by PRINTing to that channel; this is the same mechanism by which output appears on the QL screen. PRINT without a parameter outputs to the default channel # 1. For example
10 OPEN #5, mdv1 test file
20 PRINT #5, "this text is in fi Le test fi le"
30 CLOSE #5 will output the text 1his text is In file test_file' to lhe file tesLfile. It IS important to close the file after all the accesses have been completed to ensure that all the data is written.
Data can be input from a file In an analogous way uSing INPUT. Data can be input from a channel a character at a time uSing INKEY$.
A channel can be opened as a console channel; output is directed to a specified window on the OL screen and input is taken from the QL keyboard. When a console channel is opened the size and shape of the initial window is specified. If more than one console channel is active then it is possible for more than one channel to be requesting input at the same time. In this case, the reqUired channel can be selected by pressing CTRL
C to cycle round the waiting channels. The cursor in the window of the selected channel will flash.
The OL has three default channels which are opened automatically. Each of these channels is linked to a window on the QL screen: channel 0 - command and error channel channel 1 - output and graphics channel channel 2 program listing channel
•
•
•
Monitor
Command
OPEN
CLOSE
INPUT
INKEY$
Television
Function open a channel for I/O close a previously opened channel output to a channel input from a channel
Input a character from a channel
12/84
are to be provided by applications software, they should use the keys specified; also
character set
•
The cursor controls are not built in to the operating system: however, if these functions
and keys
the specified keys should not normally be used for any other purpose.
Decimal Keying Hex Display I Function
NULL 00
01
02 2
3
4
5
6
7
8
0
1
03
04
05
06
07
08
CfRL £
CTRL A
CTRL B
CfRL C
CfRL D
CTRL E
CTRL F
CTRL G
CTRL H
9 TAB (CTRL I)
10
09
OA
11 OB
• 12
13
14
15
OC aD
OE
OF
CTRL L
CfRL M
CTRL N
16
17
18
10
11
12
CfRL 0
CfRL P
CTRL Q
CfRL R
19 13
ENTER ICTRL J)
CTRL K
CTRL S
20
21
22
23
24
25
26
27
28
29
30
31
18
19
1A
18
1C
10
1E
1F
14
15
16
17
CfRL T
CTRL U
CfRL V
CTRL w
CTRL X
CTRL Y
CfRL Z
ESC ICTRL SHIFT
CTRL SHIFT \
CTRL SHIFT
I
CfRL SHIFT £
CTRL SHIFT ESC
I) change input channel (see note)
Next field
New line/Command entry
Enter
Abort current level of command
32 20
41
Space
• 33
34
35
36
37
21
22
23
24
25
SHIFT 1
SHIFT'
SHIFT 3
SHIFT 4
SHIFT 5
I
$
#
38
39
40
26
27
28
SHIFT 7
SHIFT 9 (
%
&
Space
29 SHIFT a )
+
* 42
43
2A
2B
SHIFT 8
SHIFT =
44 2C
45 2D
46 2E
2F 47
5
12/84
Decimal
72
73
74
75
76
77
68
69
70
71
78
79
64
65
66
67
56
57
58
59
52
53
54
55
60
61
62
63
48
49
50
51
104
105
106
107
108
109
96
97
98
99
100
101
102
103
110
111
84
85
86
87
80
81
82
83
88
89
90
91
92
93
94
95
Hex
5B
5C
50
5E
5F
55
56
57
58
59
5A
50
51
52
53
54
4C
40
4E
4F
48
49
4A
4B
44
45
46
47
40
41
42
43
69
6A
6B
6C
60
65
66
67
68
60
61
62
63
64
6E
6F
35
36
37
38
39
3A
3B
3C
3D
3E
3F
30
31
32
33
34
Keying a
1
2
3
4
5
6
7
8
9
SHIFT,
SHIFT,
SHIFT .
SHIFT I
SHIFT 2
SHIFT A
SHIFT B
SHIFT C
SHIFT 0
SHIFT E
SHIFT F
SHIFT G
SHIFT H
SHIFT I
SHIFT J
SHIFT K
SHIFT L
SHIFT M
SHIFT N
SHIFT 0
G
H
I
J
K
L
M
N
0
£
A
B
C
0
E
F
SHIFT P
SHIFT 0
SHIFT R
SHIFT S
SHIFT T
SHIFT U
SHIFT V
SHIFT W
SHIFT X
SHIFT Y
SHIFT Z
[
\
I
SHIFT 6
SHIFT .
J k
I m n
0 d
I e
£ a b c
9 h
W x
Y
Z
\
I
I
A
S
T
U
V
P
0
R
@
A
B
J
K
L
M
N
0
G
H
I
C
0
E
F
<
?
>
Display I Function a
3
4
1
2
5
8
9
6
7
•
•
•
•
Decimal Hex Keying Display I Function
112
113
70
71
P
0
P q
72 R 114 s 115 73 S
74 116 T
U
V t u 117
118
75
76 v w x
119
120
121
122
123
124
125
126
127
77
78
79
7A
7B
7C
7F
W
X
Y
Z
SHIFT
I
SHIFT \
SHIFT
I
SHIFT £
SHIFT ESC z
Y
©
7D
7E
• 128
129
130
131
132
80
81
82
83
133
134
135
84
85
86
87
136 88
89 137
SA
8B
138
139
8C 140
141 8D
BE 142
8F 143
CTRL ESC
CTRL SHIFT 1
CTRL SHIFT .
CTRL SHIFT 3
CTRL SHIFT 4
CTRL SHIFT 5
CTRL SHIFT 7
CTRL·
CTRL SHIFT 9
CTRL SHIFT 0
CTRL SHIFT B
CTRL SHIFT ~
CTRL.
CTRL·
CTRL
CTRL /
144
145
90
91
CTRL 0
CTRL 1
146 92
93
CTRL 2
CTRL 3 147
94 CTRL 4 148
149 95 CTRL 5
• 150
151
152
153
154
96
97
98
99
9A
CTRL 6
CTRL 7
CTRL B
CTRL 9
CTRL SHIFT ;
0
6
6
U
155
156
157
9B
9C
9D
CTRL.
CTRL SHIFT .
CTRL ~
U
U
B
¢
~
158 9E CTRL SHIFT .
159 9F CTRL SHIFT / e e
6 c;
Ii u
a
oe
0 a a
a
e
G a a a e
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
AO
A1
A2
A3
A4
AS
A6
A7
AS
AS
AA
AB
AC
AD
CTRL SHIFT 2
CTRL SHIFT A
CTRL SHIFT B
CTRL SHIFT C
CTRL SHIFT D
CTRL SHIFT E
CTRL SHIFT F
CTRL SHIFT G
CTRL SHIFT H
CTRL SHIFT I
CTRL SHIFT J
CTRL SHIFT K
CTRL SHIFT L
CTRL SHIFT M
AE CTRL SHIFT N
AF CTRL SHIFT a
E
6 c:
0
U
A
N
CE
A
A
A
I alpha delta theta lambda
12/84
7
8
Decimal
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
181
182
183
184
185
186
187
188
176
177
178
179
180
189
190
191
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
219
220
221
222
223
208
209
210
211
212
213
214
215
216
217
218
CO
C1
C2
C3
C4
C5
C6
C7
C8
C9
CA
C8
CC
CO
CE
CF
DO
01
02
03
04
09
OA
08
DC
05
06
07
08
DO
DE
OF
EC
ED
EE
EF
E4
E5
E6
E7
EO
E1
E2
E3
E8
E9
EA
E8
Hex
85
86
87
88
89
SA
88
8C
80
8E
8F
80
81
82
83
84
Keying
CTRL SHIFT P
CTRL SHIFT 0
CTRL SHIFT R
CTRL SHIFT S
CTRL SHIFT T
CTRL SHIFT U
CTRL SHIFT V
CTRL SHIFT W
CTRL SHIFT X
CTRL SHIFT Y
CTRL SHIFT Z
CTRL
I
CTRL \
CTRL
I
CTRL SHIFT 6
CTRL SHIFT ~
<
§ c
«
»
Display I Function mu p' ph,
Lett
ALT Lett
CTRL Lett
CTRL ALT Lett
SHIFT Lett
SHIFT ALT Lett
SHIFT CTRL Lett
SHIFT CTRL ALT Lett
RighI
ALT Right
CTRL Right
CTRL ALT R,ght
SHIFT R,ght
SHIFT ALT Right
SHIFT CTRL R,ght
SHIFT CTRL ALT Right
Up
ALT Up
CTRL Up
ALT CTRL UP
SHIFT Up
SHIFT ALT Up
SHIFT CTRL Up
SHIFT CTRL ALT Up
Down
ALT Down
CTRL Down
ALT CTRL Down
SHIFT Down
SHIFT ALT Down
SHIFT CTRL Down
SHIFT CTRL ALT Down
Cursor left one character
Cursor to start of line
Delete left one character
Delete line
Cursor left one word
Pan left
Delete left one word
Cursor right one character
Cursor to end of line
Delete character under cursor
Delete to end of line
Cursor right one word
Pan right
Delete word under & right of cursor
Cursor up
Scroll up
Search backwards
Top of screen
Cursor down
Scroll down
Search forwards
Bottom of screen
CAPSLOCK
ALT CAPS LOCK
CTRL CAPS LOCK
ALT CTRL CAPSLOCK
SHIFT CAPSLOCK
SHIFT ALT CAPSLOCK
Toggle CAPS LOCK function
SHIFT CTRL CAPSLOCK
SHIFT CTRL ALT CAPSLOCK
Fl
CTRL F1
SHIFT F1
CTRL SHIFT Fl
F2
CTRL F2
SHIFT F2
CTRL SHIFT F2
12/84
•
•
•
•
•
•
•
Decimal Hex Keying
240
241
FO
F1
F3
CTRL F3
SHIFT F3 242
243
244
F2
F3
F4
245
246
247
248
249
250
251
252
253
254
255
F9
FA
FB
FC
F5
F6
F7
F8
FD
FE
FF
CTRL SHIFT F3
F4
CTRL F4
SHIFT F4
CTAL SHIFT F4
F5
CTRL F5
SHIFT F5
CTAL SHIFT F5
SHIFT space
SHIFT TAB
SHIFT ENTER
See below
Display' Function
"Special" space
Back tab (CTRL ignored)
"Special" newline (CTRL ignored)
Codes up to 20 hex are either control characters or non-printing characters. Alternative keyings are shown in brackets after the main keying.
Note that CTRlC is trapped by Odos and cannot be detected without changes to the system variables.
Note that codes CO-OF are cursor control commands.
The ALT key depressed with any key combination other than cursor keys or CAPSLOCK generates the code FF, followed by a byte indicating what the keycode would have been if ALT had not been depressed.
Note that CAPSLOCK and CTRlF5 are trapped by Odos and cannot be detected without special software.
12/84 9
10
clock
The OL contains a real time clock which runs when the computer IS sWitched on .
The format used for the date and time is standard ISO format
1983 JAN 01 12:09:10
Individual year month, day, and time can all be obtained by assigning the string returned by DATE to a string variable and slicmg It.
The clock Will run frorn 1961 JAN 01 00:00:00.
comment
For a description of the format see 6S5249: PART 1: 1976 and as modified in Appendix
D2.1 Table 5 Sellal 5 and Appendix E.2 Table 6 Serrals 1 and 2.
Command
SDATE
ADATE
DATE
DATE$
DAY$
Function set the clock adjust the clock return the date as a number return the date as a string return day of the week
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www,mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
•
12/84
•
If necessary SuperBASIC will convert the type of unSUItable data to a type which will allow the specified operation to proceed.
The operators used determine the conversion required. For example, If an operation requires a stnng parameter and a numeric parameter is supplied then SuperBASIC will first convert the parameter to type string. It is not always possible to convert data to the required form and if the data cannot be converted an error is reported.
The type of a function or procedure parameter can also be converted to the correct type. For 9xample, the SuperBASIC LOAD command requires a parameter of type name but can accept a parameter of type string and which will be converted to the correct type by the procedure Itself Coercion of this form IS always dependent on the way the function or procedure was implemented.
There is a a natural ordering of data types on the OL, see figure.
String is the most general type since It can represent names, floating pOint and mteger numbers. Floating point is not as general as string but It is more general than integer since floating pOint data can represent Integer data (almost exactly). The figure below shows the ordering diagramatlcally. Data can always be converted moving up the diagram but It is not always possible moving down.
.
coercion
• not always possible string floating point
/'always possible integer
• a ::: b + c a% = b + c a$
= b$ + c$
LOAD "mdv1 dat a"
(no conversion is necessary before performing the addition. Conversion is not necessary before assigning the result to a.)
(no conversion is necessary before performing the addition but the result is converted to integer before assigning)
(b$ and c$ are converted to floating point, if possible, before being added together. The result is converted to string before assigning.)
(the string "mdv1_data" is converted to type name by the load procedure before it IS used.)
example
Statements can be written in SuperBASIC which would generate errors in most other computer languages. In general it is possible to mix data types In a very flexible manner: i.
ii.
PRINT "1 11 + 2 + "3"
LET
a$ :::
1 + 2 +
a
$ + "4"
comment
12/84 11
12
colour
single
Colours on the OL can be either a solid colour or a stipple - a mixture of two colours to some predefined pattern'. Colour specification on the OL can be up to three items; a colour, a contrast colour and a stipple pattern.
colour: = composite_colour
The single argument specifies the three parts of the colour specification. The main colour is contained in the bottom three bits of the colour byte. The next three bits contain the exclusive or (XOR) of the main colour and the contrast colour. The top two bits indicate the stipple pattern.
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ stipple
- - - - - - - - - c o n t r a s t XOR main (mix) iCOlour
• bit 7 6 5 4 3 2 o
By specifying only the bottom three bits (i.e. the required colour) no stipple will be requested and a single solid colour will be used for display.
double
colour:= background, contrast
The colour is a stipple of the two specified colours. The default checkerboard stipple is assumed (stipple 3).
triple
colour: = background, contrast, stipple
Background and contrast colours and stipple are each defined separately.
colours
The codes for colour selection depend on the screen mode in use: code bit pattern composition a
1
2
3
4
5
6
7
000 a a
1 a
1 a
011 red blue red
+
blue
1
100 green a
1 green
+
blue
1 1 a green
+
red
1 1 1 green
+
red
+
blue
Colour Composition and Codes colour
8 colour 4 colour black blue red magenta green cyan yellow white black black red red green green white white
stipples
Stipples mix a backgound and a contrast colour In a fine stpple pattern. Stipples can be used on the OL In the same manner as ordinary solid colours although stipples may not be reproduced correctly on an ordinary domestic television. There are four stipple patterns:
•
•
Stipple a
Stipple 1 Stipple 2 Stipple 3
Stipple 3 is the default.
example i.
PAPER 255 : ct.s
ii.
PAPER 2,4: CLS iii.
PAPER 0,2,0 : CLS
warning
Stipples may not reproduce correctly on a domestic television set which
IS fed via the
UHF socket.
12/84
•
•
The OL has two serial ports (called SER1 and SER2) for connecting it to equipment
communications
• • which uses serial communications obeying EIA standard RS-232-C or a compatible standard.
The RS-232-C 'standard' was originally designed to enable computers to send and receive data via telephone lines using a modem. However, it is now frequently used to connect computers directly with each other and to various items of peripheral equipment, e.g.
printers, plotters, etc.
As the RS-232-C 'standard' manifests Itself in many different forms on different pieces of equipment, It can be an extremely difficult Job, even for an expert, to connect together for the first time two pieces of supposedly standard RS-232-C equipment. ThiS section
Will attempt to cover most of the basic problems that you may encounter
The RS-232-C 'standard' refers to two types of equipment.
1 Data Terminal Equipment (DTE)
2 Data Communication EqUipment (DCE)
The standard envisaged that the terminal (usually the DTE) and the modem (usually the DCE) would both have the same type of connector.
•
2 _ TxD (output)
_ _ _
~
2
3 3 . . . RxD (input) • • • • • • •
DTE
7 . . . GND (ground)
._-_.~
7
DCE
•
The diagram above illustrates how the DTE transmits data on pin 2 whilst the DCE must receive data on its pin 2 (which is still called transmit datal). Likewise, the DTE receives data on pin 3 whilst the DCE must transmit data on its pin 3 (which is still called receive datal). Although this is confusing in itself, it can lead to far greater problems when there is disagreement as to whether a certain device should be configured as DCE or DTE.
Unfortunately, some people decide that their computers should be configured as DCE devices whilst others configure equivalent computers as DTE devices. This obviously leads to difficulties in the configuration of the serial ports on each piece of equipment.
SER1 on the OL is configured as DCE, while SER2 is configured as DTE. Therefore it should be possible to connect at least one of the serial ports to a given deVice simply by using whichever port is wired the correct' way. The pin-out for the serial ports is given below. A cable for connecting the OL to a standard 25-way '0' type connector is available from Sinclair Research Limited.
SER1 pin name function
3
4
5
6
1
2
GND
TxD
RxD
DTR
CTS
TxD Transmit Data
RxD Receive Data signal ground input output ready input ready output
+12V
SER2 pin name function
1
2
3
4
5
6
GND
TxD
RxD
DTR
CTS signal ground output input ready output ready input
+12V
DTR Data Terminal Ready
CTS Clear To Send t2/84 t3
14
Once the equipment has been connected to the torrect' port. the baud rate, (the speed of transmission of data) must be set so that the baud rates tor both the OL and the connected equipment are the same. The OL can be set to operate at:
75
300
600
1200
2400
4800
9600
19200 (transmit only) baud.
The OL baud rate is set by the BAUD command and IS set tor both channels. The baud rates cannot be set Independently.
The parity to be used by the OL must also be set to match that expected by the peripheral equipment Parity is usually used to detect Simple transmission errors and may be set to be even. odd. mark. space or no panty. I.e. all 8 bits at the byte are used tor data.
Stop bits mark the end of transmiSSion of a byte or character The OL will receive data with one. one and a half. or two stop bits, and will always transmit data with at least two stop bits. Note that If the OL IS set up to 9600 baud It will not receive data with only one stop bit at least 1
'
/2 stop bits are required.
It may be necessary to connect the handshake lines between the OL and a piece of equipment connected to it ThiS allows the OL and its peripheral to monitor and control their rate of communication. They may need to do this if one of them cannot cope with the speed at which data is being transmitted. The OL uses two handshaking lines:
CTS Clear to Send
DTR Data Terminal Ready.
If the DTE cannot cope With the rate of transmission of data then it can negate the DTR line which tells the DCE to stop sending data. ObViously when the DTE has caught up it tells the DCE, via the DTR line. to start transmitting again. In the same way. the DCE can stop the DTE sending data by negating the CTS line. If additional control Signals are required they can be Wired up using the 12V supply available on both serial ports.
Although transmission from the QL is often possible without any handshaking at all, the QL will not receive correctly under any circumstances without the use of CTS on SERl and DTR on SER2.
Communications on the OL are lull duplex: that is both receive and transmit can operate concurrently.
The parity and handshaking are selected when the senal channel is opened.
command function
BAUD
OPEN
CLOSE set transmission speed open senal channels • close serial channels see concept deVice tor a full specification
•
•
•
12/84
•
•
•
•
data types v~riables
integer Integers are wrole numbers In the range -32768 to +32767.
Variables are assumed to be Integer If the variable identifier IS suffixed with a percent %.
There are no integer constants in SuperBASIC, so all constants are stored as floating point numbers.
syntax: Identifier'l/o example: I.
il.
ill.
counter% size limitY.
this_is_an_integer_variabLe%
Floating pOint numbers are in the range ±(lOS" to 10·6"), with 8 significant digits.
Floating point is the default data type in SuperBASIC All constants are held in floating point form and can be entered using exponent notation syntax: example:
Identifier I constant i.
Ii.
IIi.
current
76.2356accumulation
354E25 floating point
A string IS a sequence of characters up to 32766 characters long.
Variables are assumed string to be type string if the variable name is suffixed by a $.
String data IS represented by enclosing the required characters In either single or double quotation marks.
syntax: identifier$ I "text" example: i.
ii.
string
"this variables$
is
string data" iii.
"this;s another string ll
Type name has the same form as a standard SuperBASIC identifier and is used by the system to name Mlcrodrive flies etc.
syntax: example: identifier i.
ii.
mdv1 ser1e data fi Le name
12/84
15
16
devices
A device IS a piece of equipment on the OL to which data can be sent (input) and from which data can be output
Since the system makes no assumptions about the ultimate 1/0 (input/output) device which will be used, the 1/0 device can be easily changed and the data diverted between devices. For example, a program may have to output to a printer at some point during
ItS run. If the printer is not available then the output can be diverted to a Microdrive
!lie and stored. The file can then be printed at a later date.
1/0 on the OL can be thought of as being written to and read tram a logical file which is in a standard deviceindependent form.
All device speCitic operations are performed by IndiVidual device drivers specially written for each device on the OL. The system can automatically tind and include drivers for peripheral devices which are fitted. These should be written in the standard OL device driver format; see the concept peripheral expansion
When a device is activated a channel is opened and linked to the device. To correctly open a channel device basic information must sometimes be supplied. This extra information is appended to the device name.
The file name should conform to the rules for a SuperBASIC type name though it IS also possible to build up the file name (device name) as a SuperBASIC stong expression.
tn summary the general form of a file name IS: identifier [information] where the complete file name (inclUding the extra information) conforms to the rules for a SuperBASIC Identifier.
Each logical device on the system requires ItS own particular extra information' although default parameters will be assumed in each case where possible: define device: = name where the form of the device name is outlined below.
example for console device
Select Console Device
Underscore
Window Width
Separator
Height
Separator - read as AT
r----
Window X coordinate
/ r - - - - - - - Separator
Window Y
Separator coordinate length of keyboard type ahead buffer
•
•
•
Console 1/0
I wXh]
[AxXy]
[k] default: example:
- window Width, height
- window X,Y coordinate of upper left-hand corner
- keyboard type ahead buffer length (bytes) con_448x180a32x16_128
OPEN #4, can 20x5000xO 32
OPEN #8, can-20x50 -
OPEN #7,con=20x50010x10
12/84
•
•
Screen Output •
[wXhJ
[AxXy] default: example:
- window width, height
- window X,Y coordinate scr__448x180a32x16
OPEN #4, ser 10x10a20x50
OPEN #5, ser-10x10
Serial (RS-232-C) n port number (1 or 2)
[PI
parity e even o - odd m - mark s - space
[hi handshaking
I ignore h - handshake
[z] protocol r raw data no EOF z control Z
IS
EOF c - as z but converts
ASCII 10 (Odos newline character) to ASCII 13
<CR» default: ser1rh (8 bit no parity with handshake) sere example: •
Serial Network I/O
[d] Indicates direction
I - Input
OPEN #3, ser1e
OPEN #4,
COPY mdv1 test fiLe TO ser1e s station number o for broadcast o - output own station - for general listen
(Input only) default: no default example: OPEN #7, net i 32
OPEN #4, neto-O
COPY ser1 TO neto_21
MIcrodrive File Access
n
Mlcrodrlve number
name
MIcrodrlve file name default: no default example: OPEN #9, mdv1 data fi Le
OPEN #9, mdv1 test program
COpy mdv1 test fi te
TO ser
Keyword
OPEN
CLOSE
COPY
COPY_N
Function
Initialise a device and activate It for use deactivate a device copy data between devices copy data between devices, but do not copy a file's header Information test for end of file set width
EOF
WIDTH
SERnphz
12/84
17
direct command
SuperBt\SIC makes a distinction between a statement typed in preceded by a line number and a statement typed in without a line number Without a line number the statement is a direct command and is processed immediately by the SuperBASIC command interpreter.
For example, RUN is typed In on the command line and is processed, the effect being that the program starts to run. It a statement is typed in with a line number then the syntax of the line IS checked and any detectable syntax errors reported A correct line is entered into the SuperBASIC program and stored. These statements constitute a SuperBASIC program and will only be executed when the program is started With the RUN or GOTO command.
Not all SuperBASIC statements make sense when entered as a direct command, for example, END FOR, END DEFine, etc.
•
•
•
•
•
•
Errors are reported by SuperBASIC in a standard form:
At line Ime_number error_text
Where the line number is the number of the line where the error was detected and the error text IS listed below.
(1) Not complete
An uperatlon has been prematurely terminated (or break has been pressed).
(2) Invalid job
An error return from Odos relating to system calls controlling multitasking or I/O
(3) Out of memory
Odos and/or SuperBASIC has Insufficient free memory.
(4) Out of range
Usually results from attempts to write outside a window or an incorrect array index.
(5) Buffer full
An I/O operation to fetch a buffer full of characters filled the buffer before a record terminator was found.
(6) Channel not open
Attempt to read, write or close a channel which has not been opened.
Can also occur If an attempt to open a channel fails.
(7) Not found
File system, device, medium or file cannot be found.
SuperBASIC cannot find an Identifier This can result from Incorrectly nested structures.
(8) Already exists
The file system has found an already existing file with the same name as a new file to be opened for writing.
(9) In use
The file system has found that a file or device IS already exclusively used.
(10) End of file
End of file detecfed during input.
(11) Drive full
A device has been filled (usually Microdrive).
(12) Bad name
The file system has recognised the name but there is a syntax or parameter value error
In SuperBASIC it means a name has been used out of context. For example, a variable has been used as a procedure.
(13)
(14)
Xmit error
RS-232-C parity error
Format failed
Attempted format operation has failed, the medium is possibly faulty (usually a
Microdrive cartridge).
(15)
(16)
(17)
(18)
(19)
Bad parameter
There is an error in the parameter list of a system or SuperBASIC procedure or function call.
An attempt was made to read data from a write only deVice.
Bad or changed medium
The medium (usually a Microdrive cartridge) is possibly faulty.
Error in expression
An error was detected while evaluating an expression.
Overflow
Arithmetic overflow, division by zero, square root of a negative number etc,
Not Implemented
error handling
12184
19
20
(20) Read only
There has been an attempt to wnte data to a shared file.
(21) Bad line
A SuperBASIC syntax error has occurred.
(22) PROC/FN cleared
This is a message which is for information only and is not reporting an errOr It is reporting that the program has been stopped and subsequently changed forcing
SuperBASIC to reset Its internal state to the outer program level and so losing any procedure environment which may have been in effect.
error recovery
After an error has occurred the program can be restarted at the next statement by typing
CONTI NUE
If the error condition can be corrected, without changing the program, the program can be restarted at the statement which triggered the error Type
RETRY
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICE~ www.mauritron.co.uk
TEL: 01844 . 351694
FAX: 01844 - 352554
•
12/84
•
•
•
•
expressions
SuperBASIC expressions can be string, numeric, logical or a mixture; unsuitable data types are automatically converted to a sUitable form by the system wherever this is possible.
monop:=
1+
1-
INOT expression;=
1
[monop] expression operator expression
I (expression)
I atom atom: = variable constant
function [ (expression array_element
* [ , expression] *)
I variable: =
I
I
1 identifier identifier identifier
%
$
function: = constant =
1
1
I identifier identifier identifier
%
$
1
1
1 digit
*
[digit]
*
* [digit] *. * [digit]
*
* [digiti * [.] * [digit] * E * [digit]
*
The final value returned by the evaluation of the expression can be integer giving an integer_expression, string giving a string_expression or floating pOint giving a f1oatin9-expression. Often floating point and integer expressions are equivalent and the term numeric_expression is then used.
Logical operators can be included in an expression. If the specified operation is true then a one is returned as the value of the operation. If the operation is false then a zero is returned. Though logical operators can be used in any expression they are usually used in the expression part of an IF statement.
example; i.
test data + 23.3
+ 5 ii.
"abcdefghi jklmnopqrstuvwxyz"(2 TO 4) iii.
32.1
*
(colour=1)
IV.
count
=
-Limit
define
12184
21
22
file types files
All 1/0 on the OL is to or from a logical file. Various file types exist:
data
SuperBASIC programs, text flies. Created using PRINT, SAVE, accessed uSing INPUT,
INKEY$, LOAD etc.
exec
An executable transient program. Saved uSing SEXEC, loaded using EXEC, EXEC_W etc.
code
Raw memory data, screen Images, etc. Saved using SBYTES, loaded using LBYTES.
•
•
•
12/84
•
•
•
SuperBASIC
DE~ine functions and procedures are defined with the DEFine FuNction and
PROCedure statements. A function IS activated (or called) by typing its name at the appropriate point In a SuperBASIC expression. The function must be included
,n an expression because it is returning a value and the value must be used. A procedure is activated (or called) by typing its name as the tirst Item in a SuperBASIC statement.
Data can be passed Into a funellon or procedure by appending a list ot aelual parameters after the function or procedure name. ThiS list is compared to a similar list appended after the name of the function or procedure when it was defined. ThiS second list is called the formal parameters of the function or procedure. The formal parameters must be SuperBASIC variables The actual parameters must be an array, an array slice or a SuperBASIC expression of which a Single variable or constant is the simplest form.
Since the actual parameters are actual expressions, they must have an actual type associated with them. The formal parameters are merely used to indicate how the actual parameters must be processed and so have no type associated with them. The items in each list of parameters are paired off In order when the function or procedure IS called and the formal parameters become equivalent to the actual parameters. There are three distinct ways of uSing parameters.
If the actual parameter is a single vanabie and If data IS assigned to the formal parameter
In the function or procedure then the data is also assigned to the corresponding actual parameter
If the actual parameter is an expression then assigning data to the corresponding formal parameter will have no effect outside the procedure. Note that a variable can be turned into an expression by enclosing it within brackets.
If the actual parameter is a variable but has not previously been set then assigning data to the corresponding formal parameter will set the variable speCified as the actual parameter.
Variables can be defined to be local to a function or procedure with the LOCal statement
Local variables have no effect on similarly named variables outside the function or procedure in which they are defined and so allow greater freedom in choosing sensible variable names without the risk of corrupting external variables. A local variable IS available to any inside function or procedure called from the procedure function in which It is declared to be local unless the function or procedure called contains a further local declaration of the same vanable name.
Functions and procedures in SuperBASIC can be used recursively. That is a function or procedure can call itself either directly or indirectly.
functions and procedures
Command
DEFine FuNelion
DEFine PROCedure
RETurn
LOCal
Function define a function define a procedure leave a function or procedure
(return data from a function) define local data In a function or procedure
23 12/84
24
graphics
It is important to realise that the OL screen has non square pixels and that changing mode will change the shape of the pixels. Thus if the graphics procedures were simply pixel based they would draw different shapes in the two modes. For example, in one mode we would have a circle while the same figure in the other mode would be an ellipse.
The graphics procedures ensure that whatever screen mode is in use, consistent figures are produced. It is not possible to use a simple pixel count to indicate sizes of figures, so instead the graphics procedures use an arbitrary scale and coordinate system to specify sizes and positions of figures.
The graphics procedures use the graphics co-ordinate system, i.e. draw relative to the graphics origin WhiCh is in the bottom left hand corner of the specified or default window
Note that this is not the same as the pixel origin used to define the position of Windows and blocks, etc. The graphics origin allows a standard Cartesian coordinate system to be used. A graphiCS cursor is updated after each graphics operation; subsequent operations can either be relative to this cursor or can be absolute, i.e. relative to the graphics origin.
100
Y • x
(0.0)
The Graphics Coordinate System
The scaling factor is such that the full distance in the vertical direction in the specified or default window has length 100 by default and can be changed with the SCALE command. The scale in the x direction is equal to the scale in the y direction.
However, the length of line which can be drawn in the x direction is dependent on the shape of the window. Increasing the scale factor increases the maximum size of the figure which can be drawn before the window size is exceeded. If the graphics output is switched to a different size of window then the subsequent size of the output is adjusted to fit the new window. If a figure exceeds its output window then the figure is clipped.
It is useful to consider the window to be a window onto a larger graphics space in which the figures are drawn. The SCALE command allows the graphics origin to be set so allOWing the window to be moved around the graphics space.
The graphics procedures are output to the window attached to the specified or default
channel and the output is drawn in the INK colour for that channel.
Command
CIRCLE
LINE
ARC
POINT
CIRCLE_R lINE_R
ARC_R
POINT_R
SCALE
FILL
CURSOR
Function draw an ellipse or a circle draw a line draw an arc of a circle plot a point draw an ellipse or a circle draw a line draw an arc of a circle plot a point set scale and move origin fill in a shape position text
~
~ absolute relative
graphics fill
Figures drawn with the graphics and turtle graphics procedures can be optionally 1illed'
With a specified stipple or colour, If
FILL
is selected then the figure is filled as it is drawn.
The FILL algorithm stores a list of points to plot rather than actually plotting them. When the figure closes there are two points on the same hOrizontal line. These two points are
12/84
•
•
•
•
• connected by a line in the current ink colour and the process repeats. Fill must always be reselected before drawing a new figure to ensure that the buffer used to store the list of points is reset.
The following diagram illustrates FILL:
•
(75.50)
//'
(10,20)
,
,
,
,
,
,
/&,
/ (50,80)
FlLL1:LINE 10,20 TO 75,50 TO 50,80
There is an implementation restriction on FILL: FILL must not be used for re-entrant shapes (i,e. a shape which is concave), Re-entrant shapes must be split into smaller shapes which are not re-entrant and each sub-shape filled independently,
warning
•
12/84 25
26
identifer
A SuperBASIC identifier is a sequence of letters, numbers and underscores.
define: example:
I
II.
iii.
IV.
letter: =
1 a..Z
I A.Z
n=b~=
111213141516171819101
IdentJIJer ~ letter
* II letter
I number
1_ 1I * a
Lim it 1 current guess counter
An identifier must begin with a letter followed by a sequence of letters, numbers and underscores and can be up to 255 characters long. Upper and lower case characters are equivalent.
Identifiers are used In the SuperBASIC system to Identify vaoables, procedures, functions,
repetition loops, etc
warning
NO meaning can be attflbuted to an Identifier other than Its ability to 'Identify' constructs to SuperBASIC SuperBASIC cannot Infer the intended use of an Identifier from the identifier's name l '
•
•
12/84
•
•
•
•
•
The Joystick ports, marked CfL1 and CfL2, allow two Joysticks to be attached to the OL.
The joysticks are arranged to generate specific key depressions when moved in a specific way and any program which uses a Joystick must be able to adapt to these keys. The
OL keyboard can be read directly uSing the KEYROW function.
joystick
mode up down left right fire
CfL1 key cursor up cursor down cursor left cursor right space
CfL2 key
F4
F2
F1
F3
F5
The joystick ports can be used tor adding other more general purpose control devices to the OL
Joysticks for other computers uSing a 9-way '0' connector require an adaptor to be used with the OL. Such an adaptor is available from Sinclair Research .
comment
12/84
27
28
keyword
SuperBASIC keywords are identifiers which are defined In the SuperBASIC Keyword
Reference GUide.
Keywords have the same form as a SuperBASIC standard identifier.
The case of the keyword is not significant. Keywords are echoed as a mixture of upper and lower case letters and are always reproduced in full. The upper case portion indicates the minimum required to be typed in for SuperBASIC to recognise the keyword.
The set of SuperBASIC keywords may be extended by adding procedures to the OL.
It is a good idea to define these with their names in upper case, procedure names defined th is way will always be reproduced by SuperBASIC in upper case, and thiS will Indicate their special function in the SuperBASIC system. Conversely, ordinary procedures should be defined with their names in lower case.
warning
Existing keywords cannot be used as ordinary identifiers within a SuperBASIC program.
SuperBASIC keywords are:
List of Keywords
ABS
ACOS, ASIN
ACar, ATAN
ADATE
ARC, ARC_R
AT
AUTO
BAUD
BEEP
BEEPING
BLOCK
BORDER
CALL
CHR$
CIRCLE
CIRCLE_R
CLEAR
CLOSE
CLS
CODE
CONTINUE
RETRY
COPY, COPY_N
COS
COT
CSIZE
CURSOR
DATA, READ,
RESTORE
DATE$, DATE
DAY$
DEFine FuNction,
END DEFine
DEFine PROCedure
END DEFine
DEG
DELETE
DIM
DIMN
DIR
DIV
DLiNE
EDIT
ELLIPSE,
ELLlPSE_R
EOF
EXEC, EXEC_W
EXIT
EXP
FILL
FILL$
FLASH
FOR
END FOR
FORMAT
GO SUB
GO TO
IF, THEN, ELSE
END IF
INK
INKEY$
INPUT
INSTR
INT
KEYROW
LBYTES
LEN
LET
LIST
LOAD
LOCal
LN, LOG10
LRUN
MERGE
MOD
MODE
MOVE
MRUN
NET
NEW
NEXT
ON GO TO
ON GO SUB
OPEN, OPEN_IN
OPEN_NEW
OVER
PAN
PAPER
PAUSE
PEEK, PEEK-W
PEEK-L
PENUP
PENDOWN
PI
POINT, POINT_R
POKE, POKE_W
POKE_L
RAD
RANDOMISE
RND
RECOL,
REMark
RENUM
REPeat,
END REPeat
RESPR
RETurn
RETRY
RUN
SAVE
SIN
SCALE
SCROLL
SDATE
SELect
END SELect
SEXEC
SORT
STOP
STRIP
TAN
TO
TURN
TURN TO
UNDER
VER$
WIDTH
WINDOW
•
•
•
12/84
•
•
•
• SuperBl\SIC has the standard trigonometrical and mathematical functions
Function
COS
SIN
TAN
ATAN
ACOT
ACOS
ASIN
COT
EXP
LN
LOG10
INT
ASS
RAD
DEG
PI
RND
RANDOMISE
Name cosine sin tangent arctangent arcotangent arcosine arcsine cotangent exponential natural logarithm common logarithm integer absolute value convert to radians convert to degrees return the value of 7t generate a random number reseed the random number. generator
maths functions
12184
29
30
memory map
The OL contains a Motorola 68008 microprocessor, which can address 1 Megabyte ot memory, Ie. from 00000 to FFFFF Hex. The use ot addresses Within this range are defined by Sinclair Research to be as tollows'
FFFFF coooo
RESERVED expansion 1/0
RESERVED addon RAM
40000
28000
RAM
96 Kbytes
RAM
32 Kbyles main RAM screen RAM
20000
18000 ocooo
I/O OLI/O
ROM
16 Kbyles
ROM
48 Kbytes system ROM
00000
PhYSical Memory Map
The screen RAM is organised as a senes of sixteen bit words starting at address Hex
20000 and progressing In the order of the raster scan, I.e. from leK to nght with each display line and then from the top to the bottom of the picture. The bits Within each word are organised so that a pixel to the leK IS always more significant than a pixel to the right (i,e, the pixel pattern on the screen looks the same as the binary pattern). However the organisation of the colour informaflon ,n the two screen modes IS different: high byte
AO~O low byte
AO~1 mode
GGGGGGGG RRRRRRRR 512 mode (high res)
GFGFGFGF RBRBRBRB 256 mode (low res)
G-green B-blue R-red F-flash
Setting the Flash bit toggles the flash state and freezes the backgound colour for fhe flash to the value given by R, G, and B for that pixel. Flashing is always reset at the beginning of each display line.
In high resolution mode, red and green specified together is interpreted by the hardware as white,
warning
Use of reserved areas in the memory map may cause incompatibility With tuture Sinclair products. Spurious output to addresses defined to be peripheral I/O addresses can cause unpredictable behaviour. It is recommended that these areas are NOT wntten to and not used for any other purpose. Poking areas in use as Microdnve buffers can corrupt
Microdrive data and can result in a loss of Information. Poking areas in use such as system tables can cause the system to crash and can result in the loss of data and programs,
All I/O should be performed using either the relevant SuperBASIC commands or the
Odos operating system traps,
•
•
•
•
12/84
•
•
•
Microdrives
Microdrives provide the main permanent storage on the QL. Each M,crodflve cartridge has a capacity of at least 100 Kbytes. Available free memory space IS allocated by Qdos as Microdrive buffers when necessary to Improve performance.
Each blank cartridge must be formatted before use and can hold up to 255 sectors of 512 bytes per sector. Qdos keeps a directory of files stored on the cartridge. Each
Microdrive file is identified using a standard SuperBASIC Me or device name
A cartridge can be write-protected by removing the small lug on the fight hand side.
On receiving new blank QL Microdrive cartridges, format them a few times to condition the tape.
Physically each Microdrive cartridge contains a 200 Inch loop of high quality Video tape which is moved at 28 inches per second. The tape completes one circuit every lV, seconds.
NEVER touch the tape with your fingers or Insert anything into the cartridge
NEVER turn the computer on or off with cartridges In place.
ALWAYS store cartridges in their sleeves when not in use.
ALWAYS insert or remove cartridges from the Mlcrodrive slowly and carefully.
ALWAYS ensure the cartridge is firmly installed before starting the Microdrive.
NEVER move the QL with cartridges Installed - even if not in operation.
NEVER touch the cartridge while the Microdrive is in operation
DO Nor repeatedly insert and remove the cartfldge Without running the Microdflve.
If a tape loop appears at either of the two places shown In figure 1 then gently ease it back into the cartridge. Use a non-fibrous instrument for this, e.g. the side of a pen or pencil. NEVER touch the tape with your fingers for this or any other reason .
general care tape loops
.----------tape loop label ----------'
-------II-label a Microdrive cartridge
CONTINUED
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
WWW-mauntron.co,uk
TEL: 01844 - 351694
FAX: 01844 - 352554
12/84
31
32
Command Function
FORMAT
DELETE
DIR
SAVE
SBYTES
SEXEC
LOAD
LBYTES
EXEC
MERGE prepare a new cartndge for use delete a file from a cartndge lists the files on a cartridge saves data from a cartndge loads data from a cartndge
OPEN IN
OPEN NEW opens and closes files
OPEN
CLOSE
INPIdT
INKEY$
SuperBASIC file I/O
warning
if you attempt to wnte to a cartndge which is wnte protected then the OL will repeatedly attempt to write the data but will eventually give up and give a "bad medium" error.
•
•
•
12/84
•
•
•
A monitor may be connected to the OL via the RGB socket on the back of the computer.
Connection IS via an 8way DIN plug plus cable for colour monitors, or a 3-way DIN plug plus cable for monochrome. The RGB socket connections are as in the following table, and the column Indicating wire colour refers to the colour coding used on the
8-way cable and connector available from Sinclair Research limited. Pin deSignation
IS as shown In the diagram below.
monitor
pin
5
6
3
4
7
1
2
8 function
PAL
GND
VIDEO
CSYNC
VSYNC
GREEN
RED
BLUE signal composite PAL ground
(4) composite monocrhome video (3) composite sync (2) vertical sync green red blue
(1)
(1)
(1 )
(1) sleeve colour on QL RGB colour lead orange green brown yellow blue red white purple
A monochrome monitor can be connected using a screened lead with a 3-way or as
8-way DIN plug at the OL end. Only pins 2 (ground) and 3 (compOSIte video) need to be connected via the cable to the monitor. The connection at the monitor end will vary according to the monitor but IS usually a phono plug. The monitor must have a
75 ohm 1V pk·pk composite video non-inverting Input (which IS the Industry standard)
Both 3-way DIN plugs and phono plugs are commonly available from audio shops.
•
Diagram of Monitor Connector as Viewed from rear of OL Showing pin numbers and functions
An RGB (colour) monitor can be connected uSing a lead with an 8·way DIN Plug at the QL end. The connection at the monitor end will vary according to the monitor (there is no Industry standard) and will often be supplied with It. A suitable cable with an 8-way
DIN plug at one end and bare wires at the other end is available from Sinclair Research limited.
A composite PAL monitor, or the composite video Input on some VCR's, may work with the OL. Only pins 2 (ground) and 1 (composite PAL) need to be connected via a cable, to the monitor or VCR.
12"84
33
34
network
The OL can be connected with up to 63 other OLs. It there are more than two computers on the network then each computer (or station) must be assigned a unique station number.
On the OL this can be done uSing the NET command.
Information is transmitted over the network in blocks. For normal communication between two stations the receiving station must acknowledge correct reception of the block. If a block is corrupted then the receiving station will request retransmission.
Using a network station number of zero has a speCial meaning. Sending to nelo_O is called broadcasting: any message sent in this way can be read by any station which is listening to neli_O. Note that the normal veriticatlon that a message has been received is disabled for broadcasts, so that broadcasting messages of length more than one block
(255 bytes) is unreliable.
A network station which listens to ItS own station number (e.g. NET3:LOAD neti_3) can receive data from any station sending to it.
Command
NET
OPEN
CLOSE
INPUT
INKEY$
LOAD
SAVE
LBYTES
SBYTES
EXEC
SEXEC
LRUN
MRUN
MERGE
Function assign a network station number open a network channel close a network channel network I/O load and save via network
comment
If you are planning to connect several OLs on the network, or use a long piece of cable, then you should wire it up with low-capacitance twin core cable, such as 3 amp light-flex or bell wire. Take care to connect the centres of each Jack to each other, and the outsides to each other. You will find that although the software can handle 63 stations, the hardware will not drive more than about 100m of cable, depending on what type it is.
If you are only connecting a few machines with the leads supplied, you need not worry.
•
•
•
12/84
•
•
•
•
Operator Type
Iloating string numeric string
+
OR
AND
XOR
NOT
MOD
DIV
INSTR
"
*
<
>
<=
>=
<>
&
&&
II
/\/\
+
logical logical logical
Integer integer string floating
Iloating floating numeric numeric numeriC numenc numeric string numeric string numeric string numeric string numeric string string bitwise bitwise bitwise bitwise logical
operators
Function logical type 2 comparison almost equal" (type addition
3 comparison) subtraction division multiplication less than (type 2 comparison) greater than (type 2 comparison) less than or equal to (type 2 comparison) greater than or equal (type 2 comparison) not equal to (type concatenation
3 comparison)
AND
OR
XOR
FOR SERVICE MANUALS
NOT
OR
AND
XOR
NOT modulus divide type 1 string comparison raise to the power unary minus unary plus
CONTACT:
MAURITRON TECHNICAL SERVICES www.maurilron.co.uk
TEL: 01844·351694
FAX: 01844·352554
"almost equal equal to 1 part in 10'
If the specified logical operation IS true then a value not equal to zero will be returned.
If the operation IS false then a value 01 zero will be returned.
The precedence of SuperBASIC operators is defined in the table above. If the order of evaluation in an expression cannot be deduced from this table then the relevanf operations are performed from leh to right The Inbuilt precedence of SuperBASIC operators can be overriden by enclosing the relevant sections of the expression in parentheses.
highest unary plus and minus string concatenation
INSTR exponentiation multiply, divide, modulus and Integer divide add and subtract logical comparison
NOT (bitwise or logical) lowest
AND (bitwise or logical)
OR and XOR (bitwise or logical)
precedence
35
36
peripheral expansion
The expansion connector allows extra peripherals to be plugged into the QL. The connections available at the connector are:
GNO
03
04
05
06
07
A19
A18
A17
A16
CLKCPU
REO
A14
A13
A12
A11
A10
A9
AS
A7
AS
AS
M
A3
OBGL
SP2
OSMCL
SP1
SPO
VP12
VM12
VIN a 1 ba 2 b a 3 b a 4 b a 5 b a 6 b a 7 b a 8 b a 9 b a 10 b a 11 b a 12 b a 13 b a 14 b a 15 b a 16 b a 17 b a 18 b a 19 b a 20 b a 21 b a 22 b a 23 b a 24 b a 25 b a 26 b a 27 b a 28 b a 29 b a 30 b a 31 b a 32 b.
GNO
02
01
00
ASL
OSL
ROWL
DTACKL
BGL
BRL
A15
RESETCPUL
CSYNCL
E
VSYNCH
VPAL
GREEN
BLUE
FC2
FC1
FCO
AO
ROMOEH
Al
A2
SP3
IPLOL
BERRL
IPL1L
EXTINTL
VIN
VIN
The connector on the QL is a 54-way (male) DIN-41612 indirect edge connector
An 'L: appdended to a signal name indicates that the signal is active low.
•
•
•
Signal Function
AO..A19
RDWL
ASL
DSL
BGL
DSMCL
CLKCPU
E
RED
BLUE
GREEN
CSYNCL
VSYNCH
ROMOEH
FCO
FC1
FC2
RESE1CPUL
68008 address lines
Read / Write
Address Strobe
Data Strobe
Bus Grant
Data Strobe - Master Chip
CPU Clock
6800 peripherals clock
Red
Blue
Green
Composite Sync
Vertical Sync
ROM Output Enable
Processor Status
Processor Status
Processor Status
Reset CPU
QL Peripheral Output Signals
•
12/84
•
•
•
Signal
DTACKL
BRL
VPAL
IPLOL
IPL1L
BERRL
EXTINTL
DBGL
Function
Data acknowledge
Bus request
Valid Peripheral Address
Interrupt Priority Level 5
Interrupt Priority Level 2
Bus Error
External Interrupt
Data bus grab
OL Peripheral Input Signals
Signal Function
0007 Data lines
OL Peripheral Bi-directional Signals
Signal
SPQSP3
VIN
VM12
VP12
GND
Miscellaneous
Function
Select peripheral
°
to 3
9V DC (nominal) - 500mA maximum
-12V
+12V ground
It IS not intended that the following description of the OL peripheral expansion mechanism be sufficient to Implement an actual expansion device, but rather be read to gain a basic understanding of the expansion mechanism.
Single or multiple peripherals may be added to the OL up to a maximum of 16 devices.
A single peripheral can be plugged drrectly into the OL Expansion Slot while multiple peripherals must be plugged into the OL Expansion Module, which in turn is plugged into the OL Expansion Slot via a buffer card.
In this context the term device also inctudes expansion memory. Although the areas of the OL memory map allocated to expansion memory are different from those allocated to expansion devices, the basic mechanism is the same. Only one expansion memory peripheral can be plugged into the OL at anyone time. The address space allocated for peripheral expansion In the OL Physical memory map allows 16 Kbytes per peripheral.
This area must contain the memory mapped 1/0 requrred lor the driver and the code for the driver Itself
Odos includes facilities for queue management and Simple serial use when Writing device drivers.
1/0 which may be of
The position ot each peripheral device In the overall memory map of the OL is determined by the select peripheral lines: SPO, SP1, SP2 and SP3. These select lines generate a signal corresponding to the slot position in the OL expansion module, thus for a device to be selected the address input from address lines: A14, A15, A16 and A17 must be the same as the signals from SPO, SP1, SP2 and SP3 respectively.
12/84
37
38
pixel coordinate system
The pixel coordinate system is used to define the positions and sizes of wmdowo, blocks and cursor positions on the OL screen. The coordinate system has Its origin In the top left hand corner of the default window (or screen) and always assumes that pOSitions are speCified as though the screen were in 512 mode (high resolution mode). The system
Will use the nearest pixel available for the particular mode set making the coordinate system independent of the screen mode ,n use.
Some commands are always relative to the default window Origin, e.g WINDOW, while some are always relative to the current window origin, e.g. BLOCK.
(0.0) x
(0.512)
•
•
(256,0)
The Pixel Coordinate System
•
12/84
•
•
•
•
A SuperBASIC program ConSiStS of a sequence of SuperBASIC statements, where each statement IS preceded by a line number. line numbers are in the range of 1 to 32767
Command Function
RUN start a loaded program
LRUN load a program from a device and start It
I
GfRL
II
SPACE
I force a program to stop syntax: example:
Ilne_number=
*
[dlgitj
*
(range L32767:
* Illne_number statement * I
:statementj * I *
100 PRINT IIThis is a vaLid line number"
RUN
II.
100 REM a small program
110 FOR foreground = 0 TO 7
120
130
FOR cant rast = 0 TO 7
FORstipple=OT03
140
150
160
170
180
190
200
PAPER foreground, contrast, stipple
CURSOR 0,70
FORn=OT02
SCROLL 2,1
SCROLL -2, 2
END FOR n
END FOR stipple
210 END FOR cant rast
220 END FOR foreground
RUN
program
39
40
Qdos
Odos is the OL Operating System and supervises:
Task Scheduling and resource allocation
Screen 1/0 (including windowing)
Microdrive 1/0
Network and serial channel communication
Keyboard input
Memory management
memory map
A full description of Odos IS beyond the scope ot this gUide but a brief description IS included.
The system RAM has an organisation imposed by the Odos operating system and is detined as tollows:
SV_RAMT-1
Resident procedures
Transient programs
SuperBasic command
Interpreter and data
SuperBaslc programs
Filing subsystem slave block
SV_FREE f - - - - - - - - - - - - j
Channels and other heap items
1
SV_HEAP f - - - - - - - - - - - - i fills
System tables and
System Variables f - - - - - - - - - - 4 28000 Hex
Display Memory
•
•
•
ODOS Memory Map
The terms SV_RAM1 SV_RESPR, SV_TRNSR SV_BASIC, SV_FREE, SV_HEAP are used to represent addresses inside the OL. These terms are not recognised by
SuperBASIC or the Odos operating system. Furthermore the addresses represented are liable to change as the system is running.
sv_ramt
SV
_respr
RAM Top
This will vary according to the memory expansion boards attached to the system.
Resident Procedures
Resident procedures are loaded Into the top of RAM. Space can be allocated in the resident procedure area using the RESPR function, but this space cannot be released except by resetting the OL. Resident procedures written in machine code can be added to the SuperBASIC name list and so become extensions to the SuperBASIC system.
12/84
•
•
•
•
Transient Programs
Transient programs are loaded immediately below the resident procedures. Each program must be self contained, Ie. It must contain space for its own data and ItS own stack. It must be position
Independent or must be ioaded by a specially written linking loader.
A transient program is executed from BASIC by using the EXEC command or from Odos by activating It as a Job.
The transient program area may be used for storing data only but this data will still be treated by Odos as a lob and therefore must not be activated.
SuperBASIC Area
This area contains all loaded SuperBASIC programs and related data.
ThiS area expands and contracts using up the free space as required.
Free Space
Free space is used by the Odos file subsystem to create M,crodrlve
Slave Blocks, i.e. copies of Microdrlve blocks which can be held ,n RAM.
System Heap
This is used by the system to store data channel definitions etc. and also provides working storage for the 1/0 subsystem. Transient programs may allocate working space for themselves on the heap via Odos system calls.
System Tables I System Variables
This area is directly above the screen memory. The System Tables and supervisor stack are resident above the system variables.
System calls are processed by Odos in supervisor mode. When in supervisor mode
Odos will not allow any other job to take over the processm System calls processed in thiS way are said to be atomic, i.e. the system call will process to completion before relinquishing the processor. Some system calls are only partially atomic, i.e. once they have completed their primary function they will relinqUish the processor if necessary.
Unless specifically requested all the I/O system calls are partially atomic.
The standard mechanism for making a system call IS by making a trap to one of the
Odos system vectors With appropriate parameters in the processor registers. The action taken by Odos following a system call is dependent on the particular call and the overall state of the system at the time the call was made.
system calls input/output
Odos supports a multitasking environment and therefore a file can be accessed by more than one process at 2.
time. The Odos filing sub-system can handle files which have been opened as exclusive files or as shared files. A shared file can not be written to.
OL devices are processed by the serial 110 sub-system. The filing sub-system and the serial I/O sub-system together make up the redirectable 110 system.
As its name suggests any data output via thiS system can be redirected to any other device also supported by the redirectable 1/0 system.
The device names required by Odos are the same as ttie device names required by
SuperBASIC and are discussed In the concept section devices. The collection of standard devices supplied with the OL can be expanded.
devices
The standard devices included in the system are discussed in this guide in the section devices. Further devices may be added to the system, given a name (e.g. SER1, NET) and then accessed In the same way as any other OL device.
multitasking
Jobs will be allowed a share of the CPU In hne with their priority and competition with other jobs in the system. Jobs running under the control of Odos can be In one of three states: active: suspended:
Capable of running and sharing system resources. A job In thiS state may not be running continuously but will obtain a share of the CPU in line with its priority.
The job IS capable of running but is waiting for another job or 1/0 A job may be suspended indefinitely or for a specific period of time.
Inactive: The job is incapable of running, its priority is 0 and so it can never obtain a share of the CPU.
41
42
Odos will reschedule the system automatically at a rate related to the 50 Hz frame rate.
The system will also be rescheduled after certain system calls.
example: This program generates an on-screen readout of the real-time clock, running as an Independent Job.
First RUN this program with a formatted cartndge in mlcrodnve 2, This generates a machine code title called 'Clock': Walt for the Mlcrodnve to stop, Next, set the clock using the SDATE command.
Then type
EXEC mdv2 cLock and a continuous time display will appear at the top nght of the command window.
100 c=RESPR(100)
110 FOR ;=0 TO 68 STEP 2
120 READ x:POKE_W ;+c,x
130 END FOR i
140 SEXEC mdv2 clock,c,100,256
1000 DATA 29439~29697,28683,20033,17402
1010 DATA 48,13944,200,20115,12040
1020 DATA 28691,20033,17402,74,-27698
1030 DATA 13944,236,20115,8279,-11314
1040 DATA 13944,208,20115,16961,16962
1050 DATA 30463,28688,20035,24794
1060 DATA 0,7,240,10,272,200
N.B. line 1060 governs the position and colour of the clock window - the data Items are, in order: border colour/width, paper/ink colour, window width, height, x-ongln, y-origin
These are pairs of bytes, entered by POKE_Was words.
The x-ongin and the y-origin (the last data item) should be 272 and 202 In monitor mode, or 240 and 216 in TV mode.
Generate the paper and 'nk word, for example, as 256 red Ink is 256
*
7 + 2 = 1794.
* paper + Ink, Thus white paper,
•
•
•
12/84
•
•
•
•
Repetition In SuperBASIC IS controlled by two basic program constructs. Each construct must be identified to SuperBASIC:
REPEAT Identifier statements
END REPEAT identifier
FOR identifier = range statements
END FOR identifier
These two constructs are used In conjunction with two other SuperBASIC statements:
NEXT Identifier EXIT identifier
Processing a NEXT statement will either pass control to the statement following the appropnate FOR or REPeat statement, or If a FOR range has been exhausted, to the statement following the NEXT.
Processing an EXIT will pass control to the statement after the END FOR or END REPeat selected by the EXIT statement, EXIT can be used to eXit through many levels of nested repeat structures. EXIT should always be used In REPeat loops to terminate the loop on some condition.
A combination of NEXT, EXIT and END statements allows FOR and REPeal loops to have a loop epilogue added. A loop epilogue is a series at SuperBASIC statements which are executed on some special condition arising within the loop:
FOR identifier ~ for ~/ist statements..
: J e x l t
NEXT Ident.ifier_ _ next epilogue
END FOR Identifier
The loop epilogue is only processed if the FOR loop terminates normally. If the loop terminates via an EXIT statement then processing will continue at the END FOR and the epilogue will not be processed.
It is possible to have a similar construction In a REPeat loop:
REPeat identifier statements
..
IF condition THEN NEXT identifier epilogue
END REPeat identifier
]
This time entry into the loop epilogue is controlled by the IF statement. The epilogue will or will not be processed depending on the condition in the IF statement. A SElect statement can also be used to control entry Into the epilogue.
repetition
12/84
43
ROM cartridge slot
Allows software to be used in the OL system from a Sinclair OL ROM cartridge. The
ROM cartridge can contain software to directly change the behaviour of the SuperBASIC system. The cartridge can contain: .
i. Software to be used instead of or with the SuperBASIC system. For example: assemblers compilers debuggers application software etc
Ii. Software to expand the SuperBASIC system. For example: special procedures etc.
It is not possible to use ZX ROM cartridges on the OL.
pin out
A12
A7
A6
M
SLOT
M f>3
A2
A1
MJ
DO
01
02
GNO a 1 b a a a a a a a a
2
3
4
5
7 b b b b
6 b b
8 b
9 b a 10 b a 11 b a 12 b a 13 b a 14 b a 15 b
VOO
A14
A15
07
06
05
04
03
A13
A6
A9
SLOT
A11
ROMOEH
A10
Side b is the upper side of the connector; side a is the lower
warning
Signal
AO .. A15
00 .. 08
ROMOEH
VOO
GNO
Function
Address lines
'Oata lines
ROM Output Enable
5V
Ground
Never plug or unplug a ROM cartridge while the OL power is on.
•
•
•
•
•
•
screen
512 mode
The screen is 512 pixels across and 256 pixels deep. Only the solid colours: black red green white can be displayed in this mode.
Low resolution mode also has a hardware flash.
The screen is 256 pixels across and 256 pixels deep. The full set of solid colours is available in this mode: blue red magenta green cyan yellow white
A domestic television is not capable of displaying the complete OL screen. Portions of the screen at the top and the sides will not be reproduced. The default Initial window will take account of this and will reduce the effeclive picture size. The full size can be restored with the WINDOW command.
256 mode warning
Command
MODE
Function set screen mode
12/84
45
46
slicing
Under certain Circumstances It IS possible to refer to more than one element in an array i.e slice the array. The array slice can be thought of as defining a subarray or a series of subarrays to SuperBASIC Each slice can define a continuous sequence of elements belonging to a particular dimension of the ollginal array The term array In thiS context can include a numellc array, a stllng array or a simple stllng.
It is not necessary to specify an index for the full number of dimensions of an array.
If a dimension IS omitted then slices are added which will select the full range of elements for that particular dimension, i,e, the slice (0 TO ). SuperBASIC can only add slices to the end of a liSt of array indices.
syntax: index: = numeric_exp numerlc_exp TO numerlc_exp numerlc_exp TO
TO numeric_express/on array_reference: =
(single elementj
I range of elements)
(range to end]
[range from beglnnlngl
I variable
I varlabfe ( [mdex
*
[,mdexj
*
i )
An array slice can be used to specify a source or a destination subarray for an assignment statement example: I
II,
III.
PRINT data array
PRINT letters$(1 TO 15)
PRINT two_d_array (3) (2 TO 4)
Stllng slicing IS performed in the same way as sliCing numeric or stllng arrays.
Thus a$(n) a$(n TO m) a$(n TO) a$(1 TO m) a$ will select the nth character.
Will select all characters from the nth to the mth, inclUSively.
will select from a character n to the end, inclUSively will select from the beginning to the nth character, inclusively, will select the entire contents 01 a a$
Some forms of BASIC have functions called LEFT$, MID$, RIGHT$, These are not necessary in SuperBASIC Their eqUivalents are specified below:
SuperBASIC a$(n) a$(n TO m) a$(1 TO n) a$(n TO)
Other BASIC
MID$ (a$,n,1)
MID$ (a$,n,m+1-n)
LEFT$ (a$,n)
RIGHT$ (a$,LEN(a$)+1-n)
warning
Assigning data to a sliced stllng array or string vallable may not have the deslled effect
Assignments made in this way will not update the length of the stllng. The length of a string array or stllng variable is only updated when an assignment is made to the whole string.
•
•
•
12'S4
•
•
Immediately after sWitch on (or resel) the OL will perform a RAM test which will give a spurious pattern on the display. If the RAM test is passed then the screen will be cleared and the copyright screen displayed.
start up
•
•
After start-up, the OL displays the copyright message and asks whether It IS being used on a television or a mOnitor. The OL will set different Initial screen modes and Window sizes depending on the answer
Press F1 if you are using a monitor and F2 if you are using a televIsion set.
The OL has the ability to 'boot' Itself up from programs contained In either the ROM cartridge slot or in Microdrive 2. If the ROM cartridge slot contains a self starting program then start up will continue under the control of the program in the ROM cartridge. If nothing suitable is found then the OL will check Microdnve 1 for a cartridge. If a cartridge is found and If it contains a file called BOOT It IS loaded and run.
The OL has three default channels which are linked 10 three default Windows.
defau It screen
Monitor TelevIsion
Channel 0 IS used for listing commands and error messages, channel 1 for program and graphics output and channel 2 for program listings. The default channel can be modified using the optional channel speCifier in the relevant command.
It is important NOT to switch on the OL with a Mlcrodnve cartndge In position. If booting from a Microdrive cartridge is required then the cartridge must be inserted between switching on and pressing either F1 or F2.
warning
12(S4
47
48
sound
Sound on the by specifying:
OL IS generated by the Ot..:s second processor (an 8049) and IS controlled up to two pitches the rate at which the sound must move between the pitches, the ramp how the sound is to behave after it has reached one of the specified pitches, the wrap
If any randomness should be built Into the sound, Ie. deviations from the ramp
If any fuzziness should be built into the sound. ie. deviations on every cycle of the sound
Fuzziness tends to result in buzzy sounds while randomness, depending on the other parameters, will result in 'melodic' sounds or nOise.
The complexity of the sound can be built up stage by stage gradually bUilding more complex sounds. This is, In fact the best way to master sound on the OL.
Specify a duration and a single pitch. The specified pitch will be beeped for the speCified time.
LEVEL 1
pitch
This is the simplest sound command, other than the command to stop the sound, on the OL
LEVEL
2 A second pitch and a gradient can be added to the command. The sound will then
'bounce' between the two pitches at the rate specified by the gradient
The sounds produced at this level can vary between: semi musical beeps, growls, zaps and moans. It is best to experiment
-fl-L~-----Pltch2 pitch
--~V~-----Pitch
1 time
LEVEL
3
A parameter can be added which controls how the sound behaves when it becomes equal to one of the specified pitches. The sound can be made to 'bounce' or Wrap:
The number of wraps can be specified, including wrap forever. It is even more important to experiment.
•
•
• pitch
- - pitch 1 pitch
_777' - - - - - - - - pltch2 pitch 1
12/84
•
•
•
• pitch
Randomness can be added to the sound. This is a deviation from fhe specified step or gradient.
Depending on the amount of randomness added In relation to the pitches and the gradient, it will generate a very wide and unexpected range of sounds.
,JI--_~-
p,tch2
~ pitch 1 time
LEVEL 4
More variation can be added by speCifying iuzziness: Fuzziness adds a random factor to the pitch continuously. FUZZiness tends to make the sound buzz.
Combining all of the above effects can make a very wide range of sounds, many of them unexpected. OL sound is best explored through experiment By speCifying a time interval of zero the sound can be made to repeat forever and so a sequence of BEEP commands can be used until the sound generated IS the sound which is required. A word of warning: slight changes in the value of a single parameter can have alarming results on the sound generated.
LEVEL 5
12/84
49
50
statement
A SuperBASIC statement IS an Instruclion to the OL to perform a specific operation, tor example:
LET a
=
2 will assign the value 2 to the variable identified by a.
More than one statement can be written on a single line by separating the Individual statements trom each other by a colon ( : ), for example:
LET a = a + 2 : PR I NT a will add 2 to the value Identified by the variable a and will store the result back In a.
The answer will then be printed out
If a line IS not preceded by a line number then the line IS a direct command and
SuperBASIC processes the statement immediately. If the statement is preceded by a line number then the statement becomes part of a SuperBASIC program and is added into the SuperBASIC program area for later execution
Certain SuperBASIC statements can have an effect on the other statements over the rest of the logical line in which they appear ie.
IF, FOR, REPeat, REM, etc. It is meaningless to use certain SuperBASIC statements as direct commands.
' •
•
12/84
•
•
•
•
•
String arrays and numeric arrays are essentially the same, however there are slight differences in treatment by SuperBASIC The last dimension at a string array defines the maXimum length of the strings within the array. String variables can be any length up to 32766 Both string arrays and string variables can be sliced.
String lengths on either side of a string assignment need not be equal. If the sizes are not the same then either the right hand string IS truncated to fit or the length of the left hand string IS reduced to match. If an assignment IS made to a sliced string then if necessary the 'hole' defined by the slice will be padded with spaces.
It IS not necessary to specify the final dimension of a strrng array. Not specifying the dimension selects the whole strrng while specifying a single element will pick out a single character and specifying a slice will define a sub strrng.
Unlike many BASICs SuperBASIC does not treat strrng arrays as fixed length strings.
If the data stored in a strrng array is less than the maximum size of the strrng array then the length of the strrng IS reduced.
ASSigning data to a sliced string array or sfrrng varrable may not have the desired effect.
ASSignments made In this way will not update the length of the string and so It is possible that the system will not recognise the assignment. The length at a string array or a string varrable IS only updated when an assignment IS made to the whole string.
Command
FILL$
LEN$
Function generate a string find the length of a string
string arrays string
variable~ comment warning
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844.351694
FAX: 01844.352554
12/24 51
S2
string comparison
order
. (decimal poinVfull stop) digits or numbers in numerical order
AaBbCcOdEeFfGgHhliJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz space
I "
# $ X & ' ( )
*
+ • • I : ;
<
=
>
?
@ [
I
1
A
I [
I J-© other non printing characters
The relationship of one string to another may be: equal: lesser:
All characters or numbers are the same or equivalent
The first part of the string, which is different from the corresponding character in the second string, is before it in the defined order greater: The first part of the first string which is different from the corresponding character in the second string, is after it in the defined order
Note that a ' .' may be treated as a decimal point in the case of string comparison which sorts numbers (such as SuperBASIC comparisons). Note also that comparison of strings containing non-printable characters may give unexpected results.
types of comparison
type 0 case dependent - character by character comparison type 1 case independent· character by character type 2 case dependent - numbers are sorted in numerical order type 3 case independent - numbers are sorted in numerical order type 0 not normally used by the SuperBASIC system.
usage
type 1 File and variable comparison type 2 SuperBASIC
< ,< =,=,> =,>
INSTR and
< >
type 3 SuperBASIC == (equivalence)
•
•
•
12/24
•
•
•
•
SuperBASIC syntax IS defined uSing a non·rigorous 'meta language' type notation. Four types of construction are used:
I I Select one of
[ ] Enclosed item(s) are optional
**
Enclosed items are repeated
..
Range
II
Comment eg IAIBI
[ A ]
*
A
*
A..Z
AorB
A is optional
A is repeated
A, B, C, etc
[this IS a comment]
Consider a SuperBASIC identifier:
A sequence of numbers, digitS, underscores, starting with a letter and finishing with an optional % or $
Jetter.= I A.Z
laz
[a letter is one of: ABCDEFGHIJKLMNOPQRSTUVWXYZ] or abcdefghijklmnopqrstuvwxyz
digit= I 0
I
1
I
2 I 3
I
4 I 5
I
6 I 7
I
8 I 9 I
[a digit is 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9] underscore: = _
[an underscore is _]
syntax definitions
identifier must
= letter ~ [Jetter
start~
with a letter
I digit
I underscore
J,*
I
%
I
$
I
] a sequence of letters digits and underscores i.e. repeat something which is optional
12/84 53
54
windows
Windows are areas of the screen which behave, in most respects, as though each individual window was a screen In its own right, I.e. the window will scroll when It has become filled by text, It can be cleared with the ClS command, etc
Windows can be specified and linked to a channel when the channel is opened.
The current window shape can be changed with the WINDOW command and a border added to a window with the BORDER command. Output can be directed to a window by printing to the relevant channel. Input can be directed to have come from a particular window by inputting from the relevant channel.
If more than one channel is ready tor input then Input can be switched between the ready channels by pressing
ICTRllc
The cursor will flash in the selected window.
Windows can be used for graphics and non-graphic output at the same time The non graphic output is relative to the current cursor position which can be positioned anywhere within the specified window with the CURSOR command and at any line-column boundary with the AT command. The graphics output IS relative to a graphics cursor which can be positioned and manipulated with the graphics procedures.
parts
Certain commands (ClS, PAN etc.) will accept an optional parameter to define part of the current window for their operation. ThiS parameter IS as defined below:
2
3
4 part o
1 description whole screen above and excluding cursor line bottom of screen excluding cursor line whole of cursor line line right of and including cursor
Command
WINDOW
BORDER
PAPER
INK
STRIP
PAN
SCROll
AT
CLS
CSIZE
FLASH
RECOl
Function re-define a window take a border from a window define the paper colour for a window define the ink colour for a window define a strip colour for a window pan a window's contents scroll a window's contents position the print position clear a window set character size character flash recolour a window
•
•
•
12/84
•
~erBASIC has a set of turtle graphics commands
Jnmand
.:,,,uP
. ':NDOWN
')VE
;ClN
;ClNlD
Function stop drawing start drawing move the turtle turn the turtle turn to a speCific heading c set of commands is the minimum and normally would be used within another
:edure to expand on the commands. For example
100 DEFine PROCedure forward(distance)
110 MOVE distance
120 END DEFine
130 DEFine PROCedure backwards(distance)
140 MOVE-distance
150 END DEFine
160 DEFine PROCedure LefttangLe)
170 TURN ang Le
180 END DEFine
190 DEFine PROCedure right(angLe)
200 TURN -ang Le
210 END DEFine
"'5e will define some of the more famous turtle graphic commands.
ally the turtle's pen is up and the turtle IS pointing at 00, which is to the rlght·hand
• '0 of the window
~ FILL command will also work with figures drawn with turtle graphics. Also ordinary c.;JhICS and turtle graphics can be mixed, although the direction of the turtle is not
'::llf,ed by the ordinary graphics commands.
turtle graphics
55
Concepts Index
A
Arrays.
slicing ..
stCings storage
B
BASIC.
Baud rates
BEEP.
Monochrome monitor ..
Booting
Break.
C
Cartridges
ROM.
M,crodrlve
Channels.
Character set ...
Circles.
Clock ..
CoerCion ..
Close channels.
Commands keywords.
direct.
turtle graphics.
windows screen.
Codes characters ..
colour.
Communications ..
channels devices ..
networking .
Comparisons.
Console device ..
Control characters.
Conversion ..
Coordinates graphics.
pixel.
CTS
Cursor ..
D
Data structures ..
types.
Data storage
Mlcrodrives.
arrays date ...
DCE.
DEFine FuNction ..
Defaults
DEFine PROCedure.
DeVices console (con) .
2
13
48
33
50
3
1
15
31
1
10
13
23
23
16
1
46
52
1
34
53
16
11
5
5
12
13
4
16
28
18
55
56
45
24
36
13
24
44
31
4
5
24
10
11
4
Identifiers.
Initialisation.
Input channels ....
devices.
windows ..
Integers ..
I/O devices.
monitor ..
peripherals.
Odos windows ...
J
Joystick.
K
Keyboard conventions. .
Keywords.
I/O
Mlcrodrives (mdv) network (net) ..
peripherals ...
screen (scr).
serial (ser) .
channels ..
file types ..
Dimension.
Direct command ..
DTE
E
Elements.
Error handling.
EXIT
Expansion
ROM cartridge.
peripherals.
Expressions.
F
Files
Filename ..
Filling shapes ...
Floating point.
FOR
Functions ...
G
GraphiCS ...
turtle.
H
Handshaking.
Hex codes ......... : .....
High resolution monitor ..
16,31
16,34
36
16
13,16
4
22
1
18
13
1
19
43
44
36
21
13
5
33
26
50
4
16
56
15
16
33
36
40
56
27
22
16,26
24
15
43
23
24
55
5
28
12/84
•
•
•
•
•
L
Lines,.
Line numbering.
direct commands ..
Local variables ..
Loops.
•
M
Maths funclions ..
Memory map.
expansion ..
Microdrlves ....
Modes
Monitor .
Multitasking.
•
N
Name.
NET ..
Network.
NEXT
0
OPEN.
Operators ..
Operating system.
Output monitor ..
channels ..
Ordering coercion.
precedence.
P
Parameters.
Peripheral expansion ..
Pictures ...
Pixel coordinates ..
POints ....
Power up.
Precedence ....
Procedure ..
Programs ...
Q
Odos.
R
RAM.
Repetition ..
RGB
ROM.
RS-232-C.
RTS ..
RXD
12.'84
30
43
33
30
13
13
13
23
36
24
38
24
50
35
23
39
29
30
36
31
45
33
41
4
35
40
33
4
11
35
24
39.51
18
23
43
26
34
34
43
S
Scaling ..
Scheduler ..
Screen.
con.
scr windows .
colours modes ..
Serial communications ..
Signals.
Slicing ...
Sound ..
Start up .
Statements .
Stipples.
Strings variables ..
slicing ..
arrays .
comparisons, . .
Switching on ..
Syntax definitions ..
T
Time.
Trig functions.
Turtle graphics.
TXD ..
Type conversion ...
V
Variables.
local string ..
W
Windows ..
40
Concepts Index
45
13
13
46
48
50
51
12
24
39
45
16
16
56
12
52
46
52
53
50
54
10
29
55
13
11
15
23
15
56
•
•
•
QL Quill
by
©1984 PSION LIMITED
Dick de Grandis-Hamson (Psion Limited)
:0: sated v,ordprocessOl It has been designed to give you the maximum
:: "ty, yet IS still easy to learn and to use. As you will see later, you will
::rmed as to what you can do next and how to do it.
_'::processor in any circumstance where you would otherwise use a
: machines are very similar in function, although the word processor
,,~as that are not matched by a conventional typewriter Perhaps the
=,ance is the ease with which mistakes can be corrected. Since the
,mediately as you type It in, you can make as many corrections as cC only print the text when you are sure that it is exactly what you want
Ja assured of perfect results every time.
,',mklng through this manual, there are a number of other advantages.
: - uSing a typewriter, it is necessary to press the carnage return key
~s
:ne. In Quill, this function IS performed automatically. Whenever the the end of a line, a new line is starfed; you press ENTER when
: "\aw paragraph. Whenever a new line IS started you will notice that c
:axt in the last line will be adjusted so that the left and right margins
_ ~~out the text. This process, which IS known as justifJcation, gives a
~.
appearance to the final result, without any effort on your part. Like
,as of QUill, the form of Justification that you use can be modified,
_ c' requirements.
_ are not sure what to do, remember that you can ask for Help by
"member that you can cancel any partially completed operation (e.g.
:: oy pressing ESC.
CHAPTER 1
ABOUT
QL QUILL
CHAPTER 2
GETTING
STARTED
LOADING QL QUILL
Load QL Quill as desCrIbed in the QL Program Introduction. When loaded the following message will be displayed:
LOADING QL QUILL version x.xx
Copyright © 1984 PSION SYSTEMS wordprocessor where x.xx is the verSion number, e.g.
2.00.
QUill will only need to access the cartlidge in M,crodllve 1 whenever you print a document or ask for Help.
When a document is being entered QUill will only require a cartlidge In Mlc;rodlive
2 when the text IS longer than about three pages. QUill will ask for a cartridge when necessary Once the cartridge is inserted it should not be removed until the document is saved or abandoned.
HElP press F1
PROMPTS press F2
CURSOR move w;thTI keys -
TEXT Insert
New para
Delete
Change mode
Type at
0
TYPEfACE COMMANDS
Press ENTER press f3
CTRL&~I.~ Press F4 ESCAPE
SHIfT & f4 press ESC
•••• :., •• 1 •••• :, ••. 2•••• :,., .3 •• ,,: ••• ,4, ••• :,., .5 •• ,.: •••. 6., •• :." .7 •.•• : ••••
•
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICEf
www,mauritron.co.uk
TEL: 01844 . 351694
FAX: 01844 . 352554
2
MODE: INSERT
TYPEfACE: NORMAL
WORDS: 0
Figure 2.1 The main display with a monitor (80 characters)
LINE: 1 PAGE: 1
OOCUMENT: no name
GENERAL
APPEARANCE
Initially the Quill display should look like that shown in Figure 21 or Figure 2.2. This is known as the mam display
Quill can show 80, 64 or 40 characters per line of the screen. If you are uSing a domestic television the display may not be clear enough for you to see 80 characters per line.
If this is the case you will need to use is very similar to that for
64 or 40 characters. The 64 character screen
80 characters. The 40 character screen IS arranged differently and the main display will look like Figure 2.2.
•
12/84
•
•
CURSOR move with;" keys --
TEXT Insert
New para
Delete
Change mode
Type at
D
Press ENTER
CTRL &
-n--
SHifT & f4
TYPEfACE
Press f4
I HELP f1 II PROMPT f2 II COMMANDS f3 II ESCAPE ESC
:
D
1 : 2 : 3 :
I
Gelling Started
•
•
I MODE: INSERT
TYPE:
WORDS: 0
Figure 2.2 The main display with 40 characters
L: 1 no name
P: 11
Quill initially selects either an 80 or a 64 character display depending on whether you pressed F1 or F2 when you switched on the computer You can change from one form of display to another at any time with the Design command which is described later.
Apart from the difference in appearance, QUill works in exactly the same way with all three forms of display. Most of the diagrams in this manual are shown for the 80 character display.
The screen is divided into three main sections: the display area, the status area and the control area.
Figure 2.3 The display area Figure 2.4 The ruler
The largest area, in the centre of the screen, is reserved for the text of your document.
Almost everything that you type at the keyboard will appear in thiS area.
Across the top of the display area is the ruler. This is a row of dots, marking each character space across the screen. Every fifth space on it is marked with a colon (:) and every tenth space is numbered.
The Display Area
Getting Started
The'Status Area
The status area, which uses the bottom three lines of the screen, shows informatIOn about your current document For example, it normally shows Its name. Initially you will not have given a name to a document and QUill shows "no name': Quill will show this for any text that you type, until you give the document a name.
The status area also shows that QUill IS currently In Insert mode, which means that anything you type into your document will be inserted (as opposed to writing over any following text). It also shows that there IS no special typeface, i.e. that you are uSing a normal typeface. Bold (emphasised), underlined, subscript and superscript typefaces are also available and we shall see how to use them later on.
In addition, the status area shows the number of words ,n the current document, and the line and page number of the position of the cursor It initially shows that you are at line 1 of page 1 of a document which contains no words.
The status area is also used for showing any speCial text that IS typed in during the use of commands (the set of instructions available when you press F3). For example, the section of text being searched for when you use the Search command (see Chapter
5) will appear in the status area.
BDDDB
•.•• 1•••. 2.... 3 .... 4.... 5•... 6.... 7....
..•• 1••.. 2•... 3 .... 4..•. 5••.. 6..•. 7.... 8
•
•
4
Figure 2.5 The status area Figure 2.6 The control area
The Control Area
The control area occupies the top few lines of the screen. It shows the normal options to obtain Help (F1). to turn the prompts on and off (F2), to select a command (F3) and to cancel any incomplete operation (ESC). In addition there are three options that are specific to Quill. These are displayed in the three central boxes of the oontrol area and are:
Cursor - move the cursor
Text - add or remove text
Typeface change the typeface
THE
CURSOR
On the top line of the central display area you will see a small rectangle. This IS known as a cursor and marks the position where the text you type will be placed.
The control area shows that you can move the cursor around the text area by use of the four cursor keys on the keyboard. When you have some text in your document, each time that you press one of these keys, the cursor Will move by one space in the direction indicated by the arrow The cursor will not pass the end of the text If there is no text in your document you will not be able to move the cursor from ItS original position.
You can also move the cursor around the text in larger steps. If you hold down SHIFT and. press the left or right cursor keys the cursor will move left or right by units of one word. When you press SHIFT together with the up or down cursor keys the cursor will move backwards or forwards by one paragraph.
TEXT
The option shown at the centre of the control area indicates the various ways in which you can change the text of the document Simply typing at the keyboard will insert the text at the cursor position.
•
•
12/84
•
BDDDB
...• 1 ••.. 2..•. 3 •..• 4.... 5.... 6.... 7.•.. 8
BDDDB
.... 1.... 2.••• 3 .... 4.•.. 5.... 6.... 7•.•. 8
Getting Started
•
•
Figure 2.7 Moving the cursor Figure 2.8 The text options
The second line of the Text option shows that pressing ENTER is used to mark the start of a new paragraph. You do not need to press ENTER when you reach the end of a line at text. If you continue typing in words until you reach the end of the first line, the new words will automatically appear on the second line and the spacing of the words on the first line will be adjusted. This is justification, which controls the way the text is aligned with respect to the left and nght margins.
Try pressing ENTER and then typing in some text to see the effect of starting a new paragraph. Do not worry If the Indentation of the new paragraph IS not as you wish
- you will find how to change It in Chapter 4.
You can include characters In your document which are not shown on the keyboard.
They are selected by pressing CTRL or CTRL and SHIFT and another key. The Concepf reference gUide contains a full list of the usable characters together with the relevant keying.
You can delete text. one character at a time, to the left or right of the cursor position.
Hold down CTRL and press either the left or the right cursor keys.
While you were typing in text you may have noticed some changes taking place in the status area at the bottom of the screen. The word and line counts will always agree with the contents of the document. The remainder of the status area Will not have changed.
In particular the document Will stili be unnamed. You give a name to a document when you save it on a Microdrive cartndge, (as described in Chapter 7).
Now that you have some text in your document, you can try moving the cursor around the text area by use of all four cursor keys. When you have finished, move the cursor to the end of the text.
A further option in the control area is headed typeface and is used to modify the appearance of the text in your document.
Press F4 and you are given five choices: to use bold (or heavy) type to display high script (superscript) to display low script (SUbscript) to produce underlined text to 'paint' existing text.
Anyone of these is brought Into effect by pressing F4 and then a single key from the list shown in the control area. As an example let us use thiS option to produce underlined text. Press F4, then the U key.
The display returns to normal and nothing seems to have changed, except that the typeface is marked as 'UNDERLINE' In the status area. If you now type in some more text you will see that it is underlined as it is displayed.
In Quill you see exactly what will appear In the final printed version. The only things that are not always shown on the screen are the upper and lower page margins, and the spacing between lines (when you select double or triple spacing). Quill does not show these since they would reduce the amount of text visible on the screen at any one time.
TYPEFACE
12/84 5
Getting Started
To turn off underlining, press F4 and then the U key again. If you now type in a few more words you Will see that they are not underlined - the underlining option works like a simple on-off sWitch, or toggle.
You will find a fuller description of underlining, and the other three typeface options,
In Chapter 4.
BODOB
•... 1 .... 2..•• 3 .•.. 4•.•. 5..•• 6•... 7.... 8
BODO
..•. 1 .... 2...• 3 .•.. 4.... 5.••. 6.•.. 7...• 8
•
Figure 2,9 Typeface Figure 2.10 The commands
COMMANDS
You select a command by pressing F3. The list of commands in the control area is known as the command menu.
You can select any of the commands shown in the menu (list) at the centre of the control area by pressing the key corresponding to ItS first letter
Quill has more commands than can be displayed in the command menu. You are therefore given two alternative lists and can switch between them with the Other command.
Since some commands start with the same letter it is important to check that the command you want is displayed in the control area before you select it.
HElP press F1
PROMPTS press F2
COMMANDS Erase
Copy Footer
Design
Other
Goto
Header
Justify load
Marg i ns
Pri nt
Quit
Press fi rst
Save
Tabs
Letter
COMMANDS press F3
ESCAPE press ESC
.... : .... 1.... : .... 2.... : ....
In the beg i nni ng
3.... : .... 4.... : .... 5.... : .... 6.... : .... 7.... : .... 8
D
•
•
6 command>
MODE: INSERT
TYPEFACE:
Figure 2.11 the first command menu
WORDS: 3 LINE: 1 PAGE: 1
DOCUMENT: no name
12/84
•
•
•
The descriptions of the vanous commands will take up much at the rest of this manual.
For the moment we will describe the use of just two commands QUit and Zap.
Quit IS used when you have finished with Quill. Press F3 and then the Q key to use quit and return to SuperBASIC Quit will ask whether you want to save your current document on a Mlcrodrive cartndge before qUitting. Press ENTER to save It or press
A to abandon It
You can press ESC to cancel the command and return to your document
The Zap command is in the commands II menu and so you will have to use the Other command before selecting Zap You must press F3, 0 and then Z. Zap clears from memory the text of the current document, but does not return to SuperBASIC
HELP press F1
PROMPTS press f2
COMMANDS
F i l es
Hyphenate
Other
Merge
Page
RepLace
Search
Zap
Press fi rst letter
COMMANDS press F3
ESCAPE press ESC
.... : .... 1.... : .... 2.... : .... 3.... : .... 4.... : .... 5.... : .... 6.... : .... 7.... : .... 8
In the beginning 0
Getting Started
•
.
command>
MODE: INSERT
TYPEfACE:
Figure 2,12 The second command menu
WORDS: 3 LINE: 1 PAGE: 1
DOCUMENT: no name
If you clear the text before you have saved it on a Microdrive cartndge you will not be able to recover It without typing it in again. Quill will therefore ask you to conf"m your chOice by pressing ENTER. You have the alternative choice of pressing ESC to cancel the command and return to your document
12/84
7
8
CHAPTER
CURSOR
EDITING
3
In this chapter you will learn how to use Quill's simple editing facilities. The changes to the text will always occur at the position ot the cursor You must therefore use the cursor keys to move the cursor to the place you want to alter before making any changes.
This form of editing is known, for fairly obvious reasons, as cursor editIng.
YoU may practise using these technrques on a piece of text that you type In yourself, or you may use the text provided with QUill. If you type In your own text, do not worry about any mistakes you make. In fact it may be a good idea to add deliberate mistakes - each mistake will give you extra practice in using the editing facilities.
INSERTING TEXT
Quill is initially in Insert mode, so that any text you type IS automatically inserted at the cursor position. To insert letters or words Into the middle of the text, do the following:
Move the cursor, by uSing the four cursor keys, to the point where you want to make the insertion.
Type the letters or words that you want to Insert. The characters are Inserted immediately under the cursor position, and any eXisting text moves to the right to make room for them.
The text is reJustlfied automatically as you make the insertion.
tI you wished to insert severat words, it would be annoying to have to wait until the text was adjusted each time you pressed a key. Quill detects this situation and reacts by splitting the line at the point where you are inserting text, This is known as an automatic text split.
You can then type in as much text as you like.
Quill will restore the text when you finish inserting text at that point (i.e. when you press a cursor key, a function key or ESC).
DELETING TEXT
The deletion of text at the cursor position is also very simple You use the CTRL key together with the cursor keys.
To see the action of the left cursor key, position the cursor immediately after the character or characters that you want to delete. Now hold down CTRL and press the left cursor key bllefly. The letter immediatety to the left of the cursor position will be deleted and the cursor will move one space to the left Each time you press the left cursor key, with the CTRL key held down, one more letter will be deleted. If you Wish to delete'several letters you can hold both the CTRL and the left cursor key down, using the auto-repeat facility. Always press the CTRL key before the cursor key.
tf you use CTRL together with the right cursor key, text will be deleted, character by characte~ fill the gap.
from beneath the cursor position, and the text to the light will close up to
You can delete whole words at a time, to the left or to the light of the cursor, by using
SHIFT and CTRL together and pressing either the left or the right cursor key.
You can delete the whole line to the left or right of the cursor. Hold down the CTRL key and press the up cursor key. The line to the left of the cursor will disappear. Similarly, pressing the down cursor key will delete the whole of the line to the right of the cursor.
In all cases the text will be rejustified automatically.
OVERWRITING
In overwrite mode you can wllte over existing text and replace it with the new text.
You can change to overwllte mode by holding down SHIFT and pressing F4. The mode
Indicator at the left hand side of the status area will change from 'INSERT' to OVERWRITE' indicating that text typed at the keyboard will replace eXisting text. Pressing SHIFT and
F4 again will change back to insert mode.
With Quill set to overwrite mode, position the cursor at the start of the text to be replaced and type in the replacement. When you have finished making replacements, return to insert mode by pressing SHIFT and F4 again, otherwise you will write over text that you want to keep.
•
•
•
•
12/84
•
HelP press f1
PROMPTS press F2
CURSOR move .withll keys -
TEXT Insert
New para
Delete
Change mode
Type at
I]"] TYPEFACE
Press ENTER
CTRL&~I1~ Press f4
SHIfT & f4
COMMANDS press f3
ESCAPE press ESC
•••• : •••• 1 .... : •••• 2.... : .... 3 .... : .... 4.... : .... 5.... : •••• 6.... : .... 7. _•• : ....
this
IS a sentliJlece to be ammended
Cursor Editing
•
•
MODE: INSERT
TYPEfACE:
Figure 3.1 Overwriting
WORDS: 7 LINE: 1 PAGE: 1
DOCUMENT: no name
Figure 3.1 shows a typical situation where you would want to use the overwrite mode.
With the display as shown, with the cursor on the 'n' of 'sentnece: you can overwrite with eo and 'n' to correct the word. (You can also practice deleting a character by removing one of the 'm's from 'ammended')
12184
9
CHAPTER 4
TEXT
/I~MATTING
TYPEFACE
This chapter is concerned with the format of the text; that is, the layout and appearance, as opposed to the actual content You will find out how to use the different typefaces,
Bold, Underline, High and Low script You will also learn how to move the pOSition of the left, right and indent margins, and how to change the Justification which affects the way the text IS aligned with respect to the margins.
The underlining facility has already been used as an example at the use of the typeface option. In this section we shall examine its use more fully, together with the options to use bold characters, high SCript (superscript) and low SCrIpt (subscript).
HELP press F1
PROMPTS press F2
TYPEFACE To change typeface press key
Slold), Hligh), Llow) or UlnderLine)
COMMANDS press F3
ESCAPE press ESC or
P
to paint or change existing text
.... :,., .1 .. ,.: .. , .2., .. :,., .3 .... : .. , ,4,.,.:.,. ,5., .. : .... 6.... :,., .7 .... : .... 8
In the beginning God crea t ed the heaven and the earth And the ea rt h was wi thout form, and void, and darkness was upon face of the deep And the spirit of God moved upon the face of the \fjaters.
And God said, [ilet there be light: and there was light.
And God Saw the Light from the darkness.
,
that it was good : and God divided the Light
And God caL Led the Light Day, and the darkness he caL Led
Night.
And the evening and morning were the first day.
And God said
•
•
TYPEFACE>
MODE: INSERT
TYPEFACE: UNDERLINE
Figure 4.1 Selecting a typeface
WORDS: 95 LINE: 4 PAGE: 1
DOCUMENT: no name
In general you can select any of these options by pressing F4 and then the appropriate letter - Bold, Underline, High SCript or Low script If one of these options is currently switched on, you can turn It off again by exactly the same method as you used to turn it on by pressing F4 and then the appropriate letter.
Note that any text that you type will always appear in the typeface shown in the status area. If you move the cursor into a region which IS in bold type, for example, the status area will show Bold typeface, and any further text that you type Within this region will also be in bold type. The typeface changes automatically as soon as you move to a region containing a different typeface.
Of course, you can only use one of High SCript or Low script at anyone time. If you select one of thesE\ the other IS automatically switched off.
There are three ways In which you may want to use the typetace option:
Insert new text in a particular typeface,
Alter eXisting text to a new typeface,
Change or remove an existing typeface.
If you want to type in some text In a particular typeface you should press F4 and select the typeface you want Any text that you then type In will appear In the typeface you have selected. When you want to return to normal text you should switch off the typeface by pressing F4 followed by the appropriate typetace letter(s).
12/84
•
•
•
It is easy to change the typeface used in existing text The method is known as
painting
since you use the cursor like a paint brush, changing the Iypeface of any text over which it moves.
First you must move the cursor to the start of the text to be changed, press F4 and then press the P key. Next, select the combination of typefaces you want. Use the fight and down cursor keys to move the cursor across the text to be changed. When you reach the end of the text you want to alter leave the option by pressing ENTER. You do not need to switch off the typeface selection; It will revert to the correct typeface as soon as you mDVe away from the area painted in the new typeface. Figure 4.2 shows the appearance Df the screen while painting text with underlining.
HELP press F1
PROMPTS press F2
TYPEfACE To change typeface press key
BCold), Hligh), Llow) or Ulnderline) then use.
--> to paint existing text
ENTER to end
COMMANDS press f3
ESCAPE press ESC
.... : .... 1.... : .... 2.... : .... 3.... : .... 4.... : .... 5.... : .... 6.... : .... 7.... : .... 8
In the beginning God created the heaven and the ea rt h And the earth was without form, and void, and darkness was upon face of t he deep And the spi ri t of God moved upon the face of the waters.
And God said, Let there be light: and there was light.
And God saw the light , that it was good : and God divided the light from the darkness.
And God called the light Day, and the darkness he called
Ni ght.
And the evening and morning were the first day.
And God said Let there beD
Texl Formatting
•
TYPEFACE>
MODE: INSERT
TYPEFACE: UNDERLINE
WORDS: 95 LINE: 4 PAGE: 1
DOCUMENT: no name
Figure 4.2 Painting underline typeface
You can change, or remove, an existing typeface in the same way In which YDU add a new typeface tD existing text Again you should move the cursor tD the start of the text before pressing F4. Press the P key and then select (or switch off) the typeface combination YDU require. Move the cursor through the text you wish tD change and then press ESC.
When you change text frDm an existing typeface tD a new one, Quill does nDt remember the original typeface. Suppose. for example. you change text which was originally underlined tD being in bDld characters. If YDU later remove the bold typeface, the final text will be in plain characters, and will not revert to being underlined.
YDU change the widths of the margins with the margin command. Each new margin position takes effect from the current paragraph and remains in force fDr all following paragraphs, until you make another change to the pDsitlDn of the margin.
Press the command key (F3) and then the M key to start thiS command. In addition to other changes in the control area you will see that three chDlces - LEFT INDENT and RIGHT will appear and that the LEFT Dption is highlighted. These options represent the three margins, and the Dne that is highlighted is the Dne that you can move YDU can step the highlighting from DptiDn to option by pressing the space bar or YDU can select a particular option by pressing the key cDrrespDnding to ItS first letter. When the name Df a margin is highlighted in the CDntrol area YDU can move that margin with the left or right cursor keys.
Suppose you wish to move the left margin to the fight by three characters, starting with the second paragraph of YDur document.
MARGINS
12/84 11
12
Text Formatting
First move the cursor to any point in the second paragraph and then type:
~M
As indicated by the highlighting, the left margin IS the one you can move, so you Just have to press the right cursor key three times. The change In the margin takes place
Immediately, so that you can see the effect before you leave the command.
You can leave the command straight away by pressing ENTER, or you can continue to make further margin changes. Press the space bar until the correct margin IS selected and move it with the left and right cursor keys. You can use the up and down cursor keys to move the cursor to another paragraph and make further changes to the margins.
After you have made all the changes you want you can leave the command by pressing
ENTER.
The Indent margin marks the character position which is used for the start oj a new paragraph. For an 80 character display It IS initially set at the fifteenth character POSition.
There is no restriction on the relative positions oj the Indent and left margins. If you do not want to use indented paragraphs you may move them so that they are both In the same place. You may even place the indent margin to the left of the left margin. This is useful for producing numbered paragraphs as shown in the follOWing example.
Indent Margin
I
I
I
1)
Left Martin
I
ThiS is the frrst of two paragraphs to show how you can use Indent margins
2) The indent margin is three characters to the left of the left margin.
In this case, starting a new paragraph (by pressing ENTER) will allow text to be typed at the "indent" position. All following text will be displayed between the left and right margin positions until you press ENTER again.
JUSTIFICATION
The justify command allows you to alter the type of justification used in your document.
Like the margins command, all changes take effect from the current paragraph (that containing the cursor) and remain in force until the end of the document, or until the next change of Justification. When you select this command you will see that you are offered the choice of left, right or centred justification.
Initially, it assumes
nght
Justification, the text is aligned on both the left and right margins, producing text With an appearance like that of this manual. If there are not sufficient characters on a line to make the margins match, extra spaces Will be added between the words unlit they do. The final effect is very professional. However, if you use an unusually large quantity of extra-long or hyphenated words In a document, unpleasant-looking spaces may result.
To choose left justification, press the L key after calling the Justify command
This will produce text which looks like the text In thiS paragraph. The left margin is aligned, but the spacing of the text Within a line is not adjusted, so that the right hand margin is left uneven.
Centre justification, selected by uSing the C option of the Justify command, causes the text of each line to be centred between the left and right margins. The text could then appear as shown in thiS paragraph.
Centre Justification IS useful, for example, in centering headings and titles, or for adding labels to diagrams
As with the margins command, you may press the up or down cursor keys to move to another paragraph and make further changes of Justification. Press ENTER to leave the command.
•
•
•
•
12/84
•
•
•
CHAPTER 5
COMMAND
EDITING
This chapter will extend your knowledge of the editing facilities to include block copies, moves and erasures. In addition, the extremely powerful technique of search and replace editing will be introduced. These facilities are available through the Quill editing commands
copy, erase, search and replace.
In addition to copying a block of text from one place in the document to another, the copy command also allows you to move blocks of text
The only difference between copying and moving text is that, in the case of a copy, the anginal text IS left in position so that you end up with two caples: You would use this, for example, if you wanted to create a table, with a piece of text repeated a number of times, or if you wanted to see the best place to include a particular paragraph.
If you move some text, the new copy is inserted and the old copy is deleted, so that you are left with only one verSion.
The copy command gives you the option of either keeping or deleting the old copy and therefore gives you both facilities in a single command.
When you select the copy command (by pressing F3 and then the C key) you must first move the cursor to the beginning of the text you want to copy, and then press ENTER.
Move the cursor to the end of the text to be copied. When you move the cursor the text that will be affected by the command is highlighted so that it is easy to see how much text Will be copied.
If you accidentally mark too much text you may use the left or up cursor keys to move backwards, but you may not pass the start of the marked text After you have marked the text you should again press ENTER.
In response to the next prompt you should move the cursor to the point where you want the selected text to be inserted and press the C key. The copy will be made and inserted immediately. You are then asked if you want to delete the old copy. You shoutd press the K key to keep the old version (to produce the effect of a copy) or press ENTER to accept Quill's suggestion to delete it
You can then end the command by pressing ENTER, which will take you back to the main display.
However, you also have an option of making further copies of the same text at other places in your document. All you have to do is to move the cursor to the point where you want another copy and press the C key. You can repeat this as many times as you want. While you are making these extra copies you are not asked whether to keep or detete the old copy. When you have finished making copies you should press ENTER to leave the command.
As is normal in Quill, pressing ESC will cancel any partially completed action, but will not undo anything that has been completed. All copies that you have made will be left in the text if you press ESC.
COpy
ERASE
You should use this command (press F3 and then E) if you want to remove any large blocks of text from your document Remember that it is simpler to delete small bits of text with the cursor editing facilities described in Chapter 3.
As with the copy command, you are asked to move the cursor to the start of the text to be erased and then to press ENTER. You then have to move the cursor to the end of the text - again the text which will be affected is highlighted. When you are satisfied that you have marked the correct amount of text you should press ENTER and the marked text will be erased immed·lately.
SEARCH
The search command allows you to look for a particular word or phrase, through all or part of your document You can use it, for example, to check whether you have used a particular word or phrase too often. The first search will start at the beginning of the text, but can then be continued from the current cursor position.
The search command is in the second command menu so you select it by pressing
F3, 0 and then S
When you use the command you are asked to type in the text which you want to find, finishing with
ENTER.
QUill will immediately start searching your document from the top until it finds the first occurrence of the text. The cursor is left positioned at the start
12184
13
of fhe found text If this is the occurrence you want you can leave the command by pressing ENTER.
However, once you have given the search command some text to look for, you can use it again to find the next occurrence of that text Instead of pressing ENTER, fust press the C key. If you do this Quill continues to search from the current cursor position until
It finds the next occurrence of the given text You can repeat this as many times as you like, finding successive occurrences. Press ENTER to leave the command when you have found the occurrence you want
If, at any stage, Quill does not find another occurrence of the text in your document it tells you so and waits for you to press the space bar and will then return to the main display.
REPLACE
The replace command is similar to the search command, but also gives you the ability to replace some or all of the occurrences that are found. The command IS In the second command menu, so you select it by pressing F3, 0 and then R.
You are asked to type In the text to be found. When you press ENTER at the end of the text, Quill immediately finds the first occurrence and asks you to type in the replacement text (don't forget to press ENTER at the end) ,
QUill then asks if you want to replace the found text Press the R key to replace the text
- if you press the N key the text is not replaced. In either case Quill then continues the search for the next occurrence and offers you the same choice of keeping or replacing the found text This continues until no further occurrences are found, or until you press
ENTER.
If, at any stage, Quill does not find another occurrence of the text in your document it tells you so and waits for you to press the space bar and will then return to the main display.
You can use the command to make multiple replacements, insertions or deletions as illustrated in the following examples:
To replace occurrences of 'river' by 'stream: give 'river' as the text to be found and
'stream' as the replacement text
To Insert br stream: give 'river' as the text to be found and 'river or stream' as the replacement text
To delete 'river: give 'river' as the text to be found and give no replacement text
Uust press R).
•
•
•
12184
•
•
•
•
•
In this chapter we shall cover the remaining options for modifying the appearance of the text. It includes setting tab stops and page breaks, and uSing bold characters, underlining, subscripts or superscripts. In addition there is a section on the design command, which you can use to change the settings of vaflous optionS (such as the page size) that control the overall appearance of your documents.
CHAPTER 6
MORE
FORMATTING
TABS
Using Tab Stops
A very common way of controlling the layout of a document IS by tab stops. These are marked positions, at particular columns of the text of your document. When you press the TABULATE key, the cursor will move to the right, from ItS present POSition, to the next tab stop In the line. If you have passed the last tab stop, then pressing the TABULATE key will move you to the start of the following line.
So that you know where the tab stops are, QUill draws the tab positions and their types
(as described below) in the line Immediately below the ruler.
Quill allows you to use several different types of tab stop, and to position them In any column. You can have up to sixteen tab stops In a line.
There are four different types of tab stop.
The most common type is known as a left tab stop and this works in exactly the same way as the tab positions on a normal typewriter When you press the TABULATE key the cursor will move to the next tab position and any text you type in will start at the tab column. It is called a left tab since lines of text at such a tab stop are aligned at their left hand edges.
A second type is a right tab stop. When you move to such a tab stop and start typing, the cursor will remain at the tab position and the text will appear to the left, so that it ends at the tab position. ThiS will continue until the text to the left of the tab position has filled the space available or until you press the TABULATE key again to move to the next tab position. Lines of text at such a tab stop are aligned at their fight hand edges.
There IS also a centred tab stop. Text typed at such a tab position will be adjusted so that its central character is positioned on the tab stop. Again the aligning of the text will continue until the available space (to existing text or to the left margin) is filled, or you press the TABULATE key again.
The fourth type of tab stop is a decimal tab, and is used for typing in numerical values.
When you type a number at such a tab stop it is positioned so that its decimal point is at the tab column.
If you do not type a deCimal point In the text, it will behave like a Right tab.
Figure 6.1 shows the appearance of text typed at each of the four different types of tab stops.
Left
I a piece of text
I
I
12.345
123.4
123456
Figure 61 The four types of tab stop
Centre a
I piece of text
,
12345
123.4
1234.56
I
Right a
I piece of text
12345
I
123.4
1234.56
,
Decimal
, piece of a text
I
12.345
123.4
123456
I
Tab Stop Types
The Tabs Command
Initially tab stops are set at every tenth character position and are all Left tabs. You can change the number position and type of tab stops with the
labs
command.
You can place tab stops at any point in the line and mix the different types in any way you like. The only limit is that you may not have more than sixteen tab stops in the line.
The new tab stops take effect from the current paragraph (that containing the cursor when you called the of tab positions.
labs
command) to the end of the document, or to the next change
15
12/84
More Formatting
16
When you select the tabs command (F3 and T) the positions are drawn in the display,
Immediately beneath the ruler.
Each tab stop is marked by a letter (L, C, R or D) to indicate ItS type. The cursor is positioned at the beginning of the line and you can move it to the left or right using the appropriate cursor keys.
You can make as many changes to the tab stops as you like. You may also press the up or down cursor keys to move to another paragraph and make more changes to the tab stops. When you have made all the changes you want, press ENTER to leave the command and return to the main display.
Inserting a Tab
To insert a tab stop, select the type you want, use the left and right cursor keys to move the cursor to the position the tab is required, and press T
When you have selected the Tabs command the types are shown In the control area.
The control area contains the words (L)eft, (R)ight, (C)entre and (D)ecimal and the word
(L)eft IS highlighted. ThiS shows that the next tab stop to be Inserted will be a Left tab.
You can change the type of tab stop to be inserted either by pressing the space bar
(each time you press It the highlight moves from one type to the next) or by 'pressing the key corresponding to its first lette, For example, If you want to change to a Right tab, you can either keep pressing the space bar until the word (R)ight is highlighted, or Just press the R key.
Deleting a Tab
Remove a tab stop by moving the cursor until it IS over the tab marker that you want to delete and pressing the X key.
DESIGN
You use the Design command to change features in the main display, such as: characters per line line spacing lines per document page
The command is illustrated in figure 6.2 and a full description of each option appears in Chapter 8.
Press F3 and then D to select the design command. Quill then shows the lisf of options.
If, for example, you want to select a 40 character display, press the D key, for the 'Display
Width' option. ThiS option will be highlighted and Quill waits for you to press 4, 6 or
8 to select a display width of 40, 64 or 80 characters. It will not allow you to select any other option until you have chosen one of these three.
HELP press F1
PROMPTS press f1
DESIGN the fORMAT of the printed page
Press the first letter of option
When finished press ENTER
COMMANDS press f3
ESCAPE press ESC
Bottom ma rg i n (t ype No.
& ENTJ •• "" ••.. , •••••.•• " •••• " ••.•• , •••• , ••. , 3
Display width 80.64.40. (8.6.41 ••• " ..••• " ...• "." ••••.•••••••••••.••• 8
Gaps between lines <0.1.1.1 ••• , •••••••••••. " " " .•. , ••••• , •••••••• , •••• 0
Page size (type No. lines & ENTJ •••••. , .•.•••••.. , ••• , ••••• , ••..••••• , •.• 66
Start page no. (type No.
& ENTJ , ••••••••••••• , ••• , , •. , ••••• , ••.. , •••• , •••
Type colour-Green or White GRN
Upper margin (type No. & ENTJ ••• " , ••• , •.•••••••.•••••• , •••.••••••••••.• 6
Figure 6.2 The design command
You then have the option of changing any or all of the items listed In the display. When
you have made all the changes you want you should leave the command by pressing
ENTER.
12/84
•
•
•
•
•
•
•
More Formatting
If you move the right margin so that the number of characfers in a line is greater than the screen width, Quill cannot show the full width of your document on the screen. In this situation the display area acts like a window, through which you see only part of the full document. As you move the cursor along a line, the window will slide across the width of your document, so that it always shows the region containing the cursor
One of the oplions in the design command is to set page Size, in terms of the maximum number of lines of text that can appear on a page of your document. In addition to the text. this number of lines Includes the upper and lower margins, any header or footer and the lines of space between them and your text.
Suppose, for example, that you have an upper margin of 3 lines, a header separated by 2 blank lines from your text. a footer separated from the text by 4 blank lines and a bottom margin of 5 lines. This takes up a total of 3+1+2+4+5~16 lines. If you have a page size at 66 lines then there will be 66-16=50 lines of text on each page. If you were then to use the design command to set the gaps between lines to be 1 (double spacing) you would have only 25 lines of text on each page.
A page break marks the point In your document where a new page will start, dependl~g on the length of the page that IS set in the design command. It is shown as a horizontal line across the screen and includes the page number. Quill allows for the upper and lower margins, headers and footers when calculating the length of a page. In the above example, With the gaps between lines set to zero, Quill will Insert a page break after each block of 50 lines of text.
If you set a page size that does not leave space for five or more lines of text per page,
Quill will turn off the paging. No page breaks are shown and Quill treats the whole document as a single page. You can make sure that automatic paging is turned off by setting the page size to zero.
You can use the page command to force a page break to occur at a particular line.
This is very useful for making sure that a section of text. such as a list or a table, is started at the top of a new page and is not shown in two parts on different pages.
You can set a page break in your text at any time by using the page command which is in the second command menu - press F3, the 0 key and then the P key. You should then position the cursor anywhere in the line at which you want the page to end and press the P key. Quill will insert a page break after the end of this line.
You may set several forced page breaks, at different positions, but you may not set more than one forced page break in anyone line of your document. When you have finished, press ENTER to leave the command.
You can remove a forced page break from your document at any time - you do not use the page command for this purpose. Remove a forced page break by moving the cursor with the up cursor key until It lies on the page break. Then press CTRL and, while holding it down, press the left cursor key.
WIDE DOCUMENTS
Paging
Page, Breaks
Forced Page Breaks
17
12/84
18
CHAPTER 7
FILE
OPERATIONS
When you have produced a document you will probably want to save a copy of It on a Mlcrodrive cartridge. At some later date you may want to make some changes and keep a copy of the new version. If you have a printer, you will cerealnly want to produce printed copies.
Each document is saved on a Microdrlve cartridge in the form of a file - a named chunk of information. This chapter describes the commands provided to save, load and print files.
SAVE
You use this command to save a copy of the text of a Quill document on a Mlcrodrive cartridge. If you do not save a document aher you have wrihen it, you will lose ItS contents when you leave Quill.
When you use the save command (F3 and then S) you are asked to type In a name for the document, The simplest way to use the command IS, therefore, to type In something like the following sequence.
[N] S my Let t e r
" I
E"'N"'T"EOi'R"1
This saves your document with the name 'myleher_doc' on the cartridge In M,crodrlve 2.
If this name IS the same as that of a document which IS already saved on Microdrlve
2, Quill will remind you that the document already exists and ask If you want to overwrite it with the new one. Press Y (yes) to replace the document or ESC to save the document with a different name.
When the document has been saved Quill asks you if you want to continue editing the document press ENTER to continue and the space bar If you want to change to another document
When you name a document to save it, or if you load a previously saved document,
QUill displays the document name in the status area. If, at some time later, you want to save the document again, QUill suggests the current document name as the name to be used. If you type In a name of your own choice, It will replace the one suggested.
Alternatively you may ac~ept QUill's suggestion by Just pressing ENTER. In such a case you can Just type In:
IF31 S I ENTER I
The new version will then be saved on the Mlcrodrive cartridge, replacing the old one.
LOAD
You should use the load command when you want to copy a document trom a Microdrive cartridge Into the computer's memory so that it may, for example, be edited.
You are first asked to type In the name of the document you want to load. If you have forgotten it you can type in a question rnark, plus ENTER. QUill will then display a list of all the documents on Microdrlve 2 and again asks you to type in the narne.
If the name you type in does not correspond to the name of an existing document,
Quill will tell you that the document does not exist and give you another chance to type the name.
FILES AND MERGE
The files command includes four options
Backup - to copy a Microdrlve document or other Microdrive file
Delete - to erase a Mlcrodrive document or other M,crodrlve file
Forrnat - to format a Microdrlve cartridge
Import - to insert a Microdrlve file, exported from Abacus, Archive or
Easet, into the current document at the position of the cursor
The merge command allows you to insert a docurnent from a Mlcrodrive cartridge Into the current docurnent at the position of the cursor
With these commands you Will ohen want to use a second data cartridge. For example, you will usually want to make a backup copy ot a document on a different cartridge, and an import file will not usually be on the same cartridge as your Quill document
You can remove the QUill cartridge In Microdrlve 1 and replace It with another cartridge but remember to replace the QUill cartridge before printing a document or asking for
Help. If you are using additional Microdrives then normally it will be necessary to remove the QUill cartridge in Microdrive 1.
12/84
•
•
•
•
•
•
•
This command is used to produce a printed copy of all or part of a Quill document
It is, of course, necessary that you have a printer and that it is correctly connected to the computer, otherwise nothing much will happenl
QUill suggests that you print the document you are currently working on and waits for you to press a key. Press ENTER to accept this suggestion, or type In the name of the document to be printed (which must be a document on the cartridge In Microdrive 2).
Quill will ask you If you want the whole document to be printed. Press ENTER to accept the suggestion. Otherwise you type the number of the page of the document at which you want printing to start and also the page number of the last page you want printed, terminating each number by ENTER.
You can only print complete pages of your document
The print command has an option to print to a Microdrlve file instead of to the printer.
Press ENTER to use the printer, or type a new file name if you want to send the text to a file. The file produced will contain all the characters and control codes that would otherwise have been sent to the printer.
The simplest use is to print all of the current document The keys you press in this case are:
[N] p
I
ENTER t
I
ENTER
II
ENTER
I
To print pages 2 to 4 Inclusive of a document called "myletter_doc" to a new file
"myletter_lis" (both on drive 2) you should type:
[N] P my lette r
I
ENTER
I
2
I
ENTER
14 rol
E=N~T=E=R~t my Lette r
I
ENTER
I
Before starting to print QUill will read the current printer driver from the Quill cartridge in Microdrlve 1. This will tell QUill what facilities are available on a particular printer and how they can be used. Quill will work with most makes of printer and you will find details of how to make changes for a particular type of printer in the Informalion section, where the printer driver program IS described.
You may also wish to change things such as the line spacing and the number of lines per page of the printed document These are all included in the design command, which is described in Chapter 6.
12/84
19
20
CHAPTER
QL QUILL
8
REFERENCE
THE FUNCTION
KEYS
In addition to the standard use of F1, F2 and F3, function key 4 is used as follows:
F4 change typeface
SHIFT & F4 switch between insert and overwrite
Quill does not use function key 5.
Select a command by pressing F3. This switches QUill to display a command menu.
You can stili move the cursor but you are not allowed to Insert or delete text.
The control area display changes to show a list of the commands available. You select a command by typing its first letter. A second set of commands (COMMANDS II) is available and you can SWitch between them uSing the Other command.
Since there are commands In the two sets that start With the same letter you must always make sure that the command you want is shown In the control area before you, select it.
In general, you can leave any partially completed command by pressing ESC.
At the end of most commands QUill returns to the main display The exceptions are those commands that have their own Internal menu (e.g. Files). In these cases you are left in the Internal menu and must press ESC to go back to the main display.
In any command that requires text input (e.g. save, load, files, replace) you may edit the text with the line editor, described in the QL Program Introduction.
THE COMMANDS
The following commands are available-
They are listed in alphabetical order. If they are part of the second command menu then this is shown by a II symbol after the command nama
COpy
Use this command for either moving or copying text from one place in the document to another.
You are first asked to move the cursor to the start of the text to be copied and then to press ENTER. Next move the cursor to the end of the text you want to copy. You can move the cursor backwards with the up and left cursor keys but you cannot move it back past the starting point. The affected text IS highlighted. Press ENTER when you have finished. Press ENTER again to delete the original marked text or press K to keep it. Move the cursor to the position where you want the marked text to appear and press the C key to insert the text at the new position.
You can make further copies of the text at any other point in your document. POSition the cursor where you want another copy to appear and press the C key. You may make as many copies as you like. When you have finished press ENTER to end the command.
DESIGN
This command allows you to set or change a number of features which control the overall appearance of your document. Within the command you are asked to choose, by pressing the appropriate key, from the following options:
Bottom margin
Display width type In the number of lines to be left blank at the bottom of each printed page of your document. Press ENTER when you have typed in the number The Initial setting IS for a bottom margin of 3 lines.
type in 4, 6 or 8 to select a display of 40, 64 or 80 characters per line. Quill will not accept any other characters. The initial setting
IS for either 80 or 64 characters depending on whether you are using a monitor or a teleVision.
Gaps between lines type in 0, 1 or 2 to select how many blank lines will be printed between each line of text in your document Quill will not accept any other characters. The initial setting is 0.
Page size type in the total number of lines to be used for each page of your document and press ENTER, This number includes the blank lines in both the upper and bottom marg Ins. If you type
12/84
•
•
•
•
•
•
• in a zero the document will not be spilt into pages. The Initial setting is 66. (You can normally pnnt 66 lines on a standard A4 page.)
Start page number
Type colour type in a number, followed by ENTER. This number is used to number the first page of your document. Successive pages are numbered consecutively from this value. You may want to change it if your document is a continuation of another document. The initial value IS 1.
to change colours used for normal and bold text. Each time you select this option the normal and bold text colours switch between green and white. The initial setting is for ordinary text to be green and bold text to be white.
Upper margin type In the number of lines space to be left blank at the top of each page of your document and press ENTER. The initial setting is for 6 lines.
At the end of each option you may select another option, or press ENTER to leave the command.
ThiS command allows you to erase text from your document. You are first asked to move the cursor (with the cursor keys) to the first character that you want to erase, press ENTER, and then move the cursor through the text you want to erase. The marked text IS highlighted. When you have marked the text you should press ENTER again and the text is erased immediately.
ERASE
FILES II
There are four options provided in this command.
Delete to delete a named document or file from a Microdnve cartridge.
You are asked to type in the name of the file you want to delete.
The file is deleted when you press ENTER.
Format to format a cartridge In Microdnve 2. Since this erases all the information on the cartridge, you must confirm your selection.
Backup
Import
Warning: all Information on the cartndge is erased when you format it.
to make a second, security copy of a document on a Microdrive cartridge. You are asked to type in the name of the document and the name you want to give to the new copy. You would normally make the copy on a different cartridge and could therefore use the same name again.
to insert another file from a Microdnve cartndge Into your document, at the position of the cursor. The file must be a file exported from either QL Abacus or QL Archive, or a text file produced, say, from SuperBASIC. See the Information section.
This command allows you to specify a line of text to be used as the bottom line on each page. It does not appear on the display screen-only on the printed page
You are first asked to select the position of the footer from the four options:
None no footer text
Left at the left margin
Centre- centred in the page (the initial setting)
Right - at the right margin
Press the space bar until the required option is highlighted and then press ENTER.
You are then asked to type the text for the footer, ending by pressing ENTER.
If you have previously specified a footer then this list IS shown in the status area. You have the option of altering it with the line editor. rather than typing in the whole of the revised text.
You can Include a page number anywhere in the text. The POSition and type of number is marked by a th ree character code:
FOOTER
12.'84
21
22
Characters nnn or NNN rrr or RRR aaa or AAA
Page Number Style
Arabic Numerals e.g. 1, 2, 3, 4
Roman Numerals e.g. I, II, III, IV
Alphabetic e.g.
A, B, C, 0
You are finally asked to type in a number from 0 to 9 to Indicate the number of lines to be left between the bottom of the text and the footer.
GOTO
You may use this command to move the curSOr to the top, bottom or to a specified page
In your document. You are offered three options:
Top
Bottom a page number to move the cursor to the beginning of your document.
to move the cursor to the end of your document.
typing In a number, followed by ENTER moves the cur~or to the start of that page of your document. If there are nO page breaks in your document this option will move the cursor to the end.
HEADER
This command allows you to specify a line of text to be used as the first line on each page. Note that the header does not appear in the display of your document on screen.
Quill does not automatically provide a header for your document.
You are first asked to select the position of the header from the four options:
None
Left
Centre
Right nO header text (the initial setting) at the left margin centred in the page at the right margin
You press the space bar until the required option is highlighted and then press ENTER.
You are then asked to type the text for the header, ending by pressing ENTER.
If you have added a header at an earlier stage the existing text is shown in the status area. You then have the option of changing with the line editor, rather than typing in the whole of the text.
You can include a page number anywhere in the text. The position and type of number is marked by a three character code:
Characters nnn or NNN r r r or RRR aaa or AAA
Page Number Style
ArabiC Numerals e.g. 1, 2, 3, 4
Roman Numerals e.g. I, II, III, IV
Alphabetic e.g. A, B, C.
0
HYPHENATE (II)
This command allows you to specify a point within a word where it can be split, With an automatically inserted hyphen, if it extends beyond the end of a line Words not marked in this way will, if necessary, be moved to the next line in their entirety.
Hyphenation is particularly useful when you are using right justification, to avoid large gaps being left between the words.
Move the cursor to the first character following the position where you want to allow a split to be made and press the H key. You may repeat this process as many times as you want. Press ENTER to leave the command.
The command will have nO apparent effect on the word if it is not at the end of a line,
•
•
•
•
12/84
•
•
•
Use this command to select the type of Justification you want. It takes effect from the
JUSTIFY
start of the paragraph containing the cursor, and remains In effect to the end of the document, or to the next change of Justification.
You are offered the following options, selected by pressing the key corresponding to its first letter:
Left
Centre the text is aligned at the left margin, but the right margin is uneven.
the text of each line IS centred between the margins.
Right additional spaces are inserted between words In each line so that the text is aligned at both the left and right margins.
You may make changes of Justification to more than one paragraph. Press the up or down cursor keys to move up or down by a paragraph and change the justification as described above. Press ENTER to end the command.
LOAD
This command allows you to load a document into memory from a Microdrive cartridge, ready for printing or editing.
Type In the name of the document (the name you gave It when you saved it). If you just press '?" plus ENTER, Quill will show you a list of the names of all the documents saved on Microdrive 2. Edit the suggested text, Microdrlve 2 - if you want a list of the files from a different Microdrive. When Quill has shown the list, you are again asked to type In a document name.
Use this command to set or change the pOSItions of the left, Indent and right margins of your document. All changes in the margins are shown in the text as you make them.
The oontrol area shows the words left indent and right and on first entering this command the word left is highlighted. This means that you can use the left and right cursor keys to move the left margin.
You can select any of the three margins by pressing the space bar until the correct margin name is highlighted. You can move the selected margin by pressing either the right or left cursor key.
The change in each margin takes effect from the paragraph containing the cursor It remains In effect to the end of your document, or to the next change of position of that margin.
You may make changes of margin positions to more then one paragraph. Press the up or down cursor keys to move up or down by a paragraph and change the margins as described above. Press ENTER to leave the command.
MARGINS
The merge command takes a copy of a named Quill document from a Mlcrodrive cartridge and inserts it at the position of the cursor, in the document currently In memory.
This command allows you the option to replace the Quill cartridge with a data cartridge.
You must replace the Quill cartridge in Mlcrodrive 1 at the end of the command.
POSition the cursor at the point where you want the document to be inserted before selecting the command. Quill asks you to type in the name of the file you want to insert.
If you insert the document in the middle of a paragraph, Quill Will split it Into two paragraphs at the position of the cursor and insert the document between them.
MERGE (II)
This command allows you to switch to the display of a second set of commands in the control area. The list of commands in the control area alternates between the two lists each time you use Other.
Since several commands start with the same letter, you must make sure that the command you want is one of those displayed, before you choose it.
You can use this command to mark a point in your document where you want a new page to start.
Move the cursor to the point where you want the new page to start and press R
You may add such page breaks at several points in your document. Move the cursor
to the point where you want another page to start and press the P key. Press ENTER to leave the command.
OTHER
PAGE (II)
23
24
Do not use the page command for deleting a forced page break. You can cancel a page break by moving the cursor to any point on the page break line and then pressing
CTRL and the left cursor key together
This command pnnts all or part of the document currently in the computer's memory, or any other document on the cartridge In Microdrive 2.
Press ENTER to print the current document, or type in the filename at the document to be printed, followed by ENTER.
QUill then suggests pnntlng the whole document. If you reply by pressing ENTER the whole document will be printed. If you only want to print some of the pages, type In the number of the first page you want printed, followed by ENTER. Then type the number of the last page you want printed, again ending by pressing ENTER.
Finally, press ENTER to send the text to a printer, or type the file name of a new file, followed by ENTER to send the output to a Microdrive file.
Before printing, Quill will read a "printerdat" file entenng the pnnter driver information.
QUIT
This command allows you to leave Quill and return to SuperBl\SIC You have three OptiOns:
ENTER
A
ESC to save your current document before returning to SuperBASIC
You are given the further option of typing ,n a name for the saved document. If you Just press ENTER the document will be saved with its old name, replacing the onginal verSion of the document on the Microdrive cartridge.
to abandon your current document and return to SuperBASIC without saving it.
to cancel the command and return to your document.
REPLACE (II)
You can use thiS command to replace some or all occurrences of one piece oj text by another
First type in the word(s) to be replaced, followed by ENTER. Then type in the replacement word(s), again followed by ENTER.
Quill searches from the start of the document until the first occurrence of the old text is found. It then offers you the option of replacing the old text with the new. Press the
R key to replace the text, or N If you do not want to replace it.
QUill will then search for the next occurrence and again offer you the option to make the replacement. This process will continue until you reach the end of the document or until you end the command by pressing ENTER.
SAVE
You use this command to save a copy of your document on a Microdrive cartridge.
Type in a name for your document, so that it can be identified. The document is then saved under that name. If, instead of typing in a name, you Just press ENTER, the document will be saved with its old name, replacing the onginal version.
Quill then asks you il you want to continue editing the document you have Just saved.
If you press ENTER, the text of the document remains in the computer's memory and you can continue working on it.
Alternatively, press the space bar if you want to work with another document.
SEARCH (II)
This command searches your document for a particular word or phrase.
First type in the text which you want to find. When you press ENTER Quill starts at the top of your document and searches for the first occurrence of the text.
You may press the C key to continue the search to find the next occurrence of the text.
Press ENTER to end the command when you have found the occurrence you want.
t.
,
--" c
C
(;
•
•
. The tabs command allows you to specify the positions and types of tab stops on a line of text The tabulate key will then take you straight to the next tab stop along the rule which you have set Each change of the tab stops will take effect from the start of the current paragraph (the one containing the cursor). It will remain in effect to the end of your document, or until the next change of tab stops.
There are four types of tab stop provided:
Left
Centred
Right
Decimal the tab stop behaves like a left margin; the text is positioned to the right of the tab stop.
the text will be centred around the tab stop.
the tab stop behaves like a nght margin; the text IS posItioned to the left at the tab stop.
this is used for aligning decimal numbers. Each number will be positioned so that ItS decimal pOint IS at the tab stop. Until a decimal pOint IS encountered It behaves like a right tab.
The tab positions are drawn on the screen, below the ruler using the following symbols:
L - left
C - centred
R - right
D - decimal
The cursor IS positioned at the start of that line. You can move the cursor along the line by uSing the left and nght cursor keys.
You can remove a tab marker by moving the cursor With the left and right cursor keys until it is over the tab marker in the line under the ruler and then pressing the X key.
To insert a tab marker you should first select the type you want by either pressing the space bar until the correct type is highlighted in the control area, or pressing the L,
C, R, or D key. Then move the cursor to the appropriate pOint and press the T key.
You can mix Inserting and deleting tab markers in any combination. You may also press the up or down cursor keys to move to another paragraph and make further changes to the tab stops. When you have made all the changes you want you should press ENTER to leave the command and return to the main display.
TABS
This command deletes the whole of your current document, Without saving It on a
Microdrive cartndge. It allows you to discard your current document and start again.
ZAP
TYPEFACE
You can change the typeface of the text in your document by pressing F4 and then the first letter of one of the four options listed below The selected typeface affects all text subsequently typed in.
Alternatively you may press F4 and then the P key to paint new text in a new style.
You are offered the following options:
Bold
High script
Low scnpt
Underline text IS converted to a bold, or heavy, typeface.
text is printed In the upper half of the line.
text is printed in the lower half of the line.
text IS underlined.
You may select any combination of these options except, of course, that you can not have both high and low scripts selected together If you select either of these, the other will be switched off automatically.
If you want to select a combination of typefaces, you should select them one after another by pressing F4 and the appropnate letters.
If you press the P key to select the paint option, Quill allows you to select one or more typeface styles. Move the cursor to 'paint' the text to the new style and press ENTER when you have finished. Note that the original typestyle IS restored after painting.
You can switch off any of the typeface options In the same way that you use to turn it on - that is by pressing F4 and then the appropriate key (B, H, L or U).
INSERT AND
OVERWRITE MODES
Initially Quillin Insert mode and any text that you type In will be inserted into your document at the position of the cursor Any surrounding text will be spread out to make room.
It you hold down SHIFT and press F4, Quill will sWitch to overwrrte mode. In this mode any text that you type In will replace, character by character, any text from the cursor position onwards.
You can switch back to insert mode by the same method, that IS by holding SHIFT down and pressing F4.
THE START·UP
PARAMETERS
When you tirst load QUILL it is in the state described by the toll oWing list. You can change each of the properties by the method indicated in the right hand column
Feature
Mode:
Display width:
Lell margin:
Indent margin:
Right margin:
Upper margin:
Bottom margin:
Justification:
Tab stops:
Page size:
Gaps between lines:
Page header:
Page footer:
Start page number:
Text colour:
Normal
Bold
Typeface:
Bold
Underline
High script
Low script
Initially insert
80(mon) 64(TV)
10
15
70
0
5
64
6
3
Right
Lell, cols 10,20, .,80
66
0 none centred, "page nnn"
1 green white off off off off
Change By
SHIFT & F4
Design
Margins
Margins
Margins (max 160)
Design
Design
JUStify
Tabs
Design
Design
Header
Footer
Design
Design
Design
F4
F4
F4
F4
f"-
QLAbacus
FOR SERViCE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVlCEf www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
:( by Dick d ©1984 PSION LIMITED e Grandls-Harnson (P S/on Limited)
OL Abacus IS a spreadsheet which can be used for planning, budgeting, tabulating data, calculation, Intormalion storage or for presenting Intormation. This Information IS represented on a tabulated gnd divided Into 255 rows and 64 columns. The data area you see on the computer screen is a window through which you can see part of the grid. You can move this window across the grid. The Interseclions of the rows and columns represent more fhan 16,000 cells or boxes In the grid. You can enter text Into any cell or cells, or the cells may be used for the storage of numbers or data.
The real power of Abacus, however, comes from the use of rules, or lormulae, which can connect different blocks, rows or columns of cells, or even Individual cells of the grid. This means that Information Inserted In one area can immediately be evaluated and represented In another form elsewhere.
For example, you can use twelve of the columns to represent months of the year and you can then enter sales data along a 'sales' row The next two rows can contain formulae to calculate the cost of sales (as a percentage of sales plus a fixed cost, say) and the profit, The monthly profits will then be evaluated automatically each time you type In a sales figure. The yearly totals can also be summed by another formula, so that a change in the sales of, say, March Will immediately lead to a completely different profit profile and total for the year All the figures are evaluated by Abacus automatically.
You can also represent the data from Abacus as graphics or In a table In the word processor through the export commands of the Pslon OL package.
In many respects Abacus Is like a visual programming language, but one which IS easy to use. You may manipulate text, data, or formulae, use Input and output statements and text variables.
If, at any time, you are not sure what to do, remember that you can ask for Help by pressing F1. Also remember that you can cancel any partially-completed operation (e.g.
typing in a number or using a command) by pressing ESC.
CHAPTER
1
ABOUT
QL ABACUS
12/84
CHAPTER 2
GETTING
STARTED
LOADING
QL ABACUS
Load OL Abacus as described In the Introduction to the OL Programs, don't torget that Abacus requires a formatted cartfldge In M,crodflve 2 When loaded the tollowlng message will de displayed:
LOAOING QL ABACUS version x.xx
Copyright © 1984 PSION SYSTEMS spreadsheet where x.xx represents the version number (eg. 102).
The program will then walt tor a tew seconds betore starting.
,
The Help information IS not loaded Into the computer's memory together with the program. It IS only read from the Abacus cartfldge when it is needed. You should therefore not remove the Abacus cartridge from Microdrive 1 if you intend to use the Help facility.
When Abacus is first loaded the appearance of the screen IS as shown in Figure 2.1.
Th IS IS the main display
GENERAL
APPEARANCE
Abacus can display 80, 64 or 40 characters per line of the display. If you are using a domestic television the display may not be clear enough for you to see 80 characters per line and you should use 64 or 40 characters. The 64 character display IS very similar to that for 80 characters but the 40 character display IS arranged slightly differently.
This is shown in figure 2.2.
HELP CURSOR
I
f-C;p",r",es",s=F
1----11
pre 5 S
<--
H
--+
PROMPTS GO TO CELL press
F2
press
FS
DATA & FORMULA enter di reet Ly
& press ENTER
TEXT type" followed by text & ENT.
COMMANDS press F3
ESCAPE press ESC
2 ceu
Al GRID USED At :Al MEIIORY 23K
CONTENTS EMPTY
Figure 2.1 The main display with a monitor. (80 characters)
Abacus initially selects either an 80 or a 64 character display depending on whether you started from SuperBASIC In the Monitor or the TV
12184
Apart from the difference In appearance. Abacus works in exactly the same way with all three display formats. Most of the diagrams In this manual are shown for the 80 character display.
CURSOR press ..... ·1---+
GO TO CELL press fS
HELP f1
DATA & fORMULA enter directly
& press ENTER
PROMPT f2
8
COMMANDS f3
TEXT type" followed by text & ENT.
ESCAPE ESC
Getting Started
12/84
MEMORY 23K CELL At GRID USED A1 :A1
COl/TENTS EMPTY
Figure 22 The main display lor 40 characters
The central area of the screen contains the Window shOWing part of the grid.
Across the top of the window you will see a line in which a number of letters appear
These letters label vertical columns of cells making up the grid.
As you can see, columns
A, B,C and so on are Visible. Down the side of the window there IS a series of numbers, from 1 to 15. These numbers label the rows of cells In the grid.
BDDDB BDDDB
,
, . .
" .
I
.
.
The Window
~====='JII
Figure 2.3 The window
'v
1,===1= = =
Figure 2.4 The grid labels.
A combination of a letter and a number will therefore Identify one particular cell, and is known as a cell reference.
For example, Al This refers to the cell which is in column
A and row 1, (the top left hand cell in the window).
You will see that this cell IS different from all the others In that it IS filled by a large red rectangle. ThiS is known as the cursor and it marks the current cell, that is the cell which will receive any data you type in,
3
Gettng Started
BDDDB
I
BDDDB
I
u
Figure 2.5 The cursor Figure 2,6 The status area
The Status Area
The bottom section of the display contains the about the current state of the grid.
status area,
which gives Intormafion
It contains the cell reference of the current cell and its contents. This cell IS empty when you have just loaded Abacus. In addition, the status area shows the extent of the used portion of the grid (as the cell reference of the bottom fight cell of the used portion) and the amount of memory left.
The Control Area
The control area shows the normal options to obtain Help (F1), to turn the prompts on and off (F2), to select a command (F3) and to cancel an incomplete selection (ESC).
In addition there are three options that are specific to Abacus. These are: move the cursor type in data or a formula, type in text
BDDDB
I
4
Figure 2.8 Moving the cursor Figure 2.7 The control area
MOVING THE
CURSOR
The four cursor keys move the cursor around the grid. Press the right cursor key once.
The cursor moves one column to the right and the current cell indicator now shows
81. If you then press the left cursor key once the cursor returns to cell At Pressing the left cursor key again Will have no effect because you are at the extreme left hand edge of the grid.
Move the cursor to the extreme right hand edge of the grid. Pressing the right cursor key again will not move the cursor but the letters across the top of the window will change. When you attempt to make the cursor leave the visible area of the grid the window will move across the grid so that the cursor remains In View.
The cursor keys are a useful way of moving the cursor, provided you only wish to move it one or two cetls. They are very inefficient for making large movements across the grid. For such large movements it IS more convenient to go directly to the reqUired cell. You can do this by pressing F5, to select the goto option, and then typing the required cell reference, followed by ENTER.
12184
Getting Started
As an example of using the goto option, ask Abacus to move the cursor to cell 011.
First press F5 to select the goto option. The words 'goto > A1' will then appear in the line immediafely below the window Abacus is suggesflng that the cursor be moved to the top left hand corner of the gnd. If you accept this suggestion (by Just pressing
ENTER) the cursor will move to that pOint To move the cursor to another cell, type in the cell reference In this case type: d11 and press ENTER. Note that the 'd' may be In upper or lower case - Abacus will accept either. The cell reference you type in replaces that suggested by Abacus and the cursor moves directly to the cell you have specified.
You should now move the cursor back to the top left hand corner of the grid by using this option again. This time you can accept the suggested cell reference (A1) so all you have to type is: t
F511 ENTER
I
You will find that you go back to the onginal state of the display, with the cursor at the top left hand corner of the window, In cell At
Now move the cursor to cell Y1, by typing in
I
F51 y 1
I
ENTER t
Look at the letters labelling the columns across the top of the window and you Will find the column to the right of column Z IS labelled AA, the next one is labelled AB, and so on. This enables you to refer to more than 26 columns.
There are 64 columns in total and, after AZ, the columns are labelled BA, BB and so on. The last column in the grid is labelled BL.
You can also move down the gnd to find the last row but you will have to go a long way; there are 255 rows in the grid.
Return the cursor to cell A1 and then type
100 but don't press ENTER Just yet The 'Data or Formula' option box in the control area is now highlighted, to confirm your action. The prompt value>, followed by the number
100 will also have appeared in the line immediately below the window.
All typed input, and the text that Abacus shows while you are uSing a command, appears in this line. It IS the input line.
The small rectangle in the input line marks where the next Input character will appear, and IS known as the input cursor, to distinguish it from the main cursor In the window.
IJ you make a mistake at any time during typing to the input line, you can correct it by using the line editor, described in the Introduction to the OL Programs.
ENTERING
NUMBERS
ENTERING TEXT
When you press ENTER the value 100 will be transferred to the current cell (A1) and the Input line Will clear, ready for more Input. You will see that the value 100 also appears
In the status area, at the bottom of the display.
Putting text into a cell IS the same as entering a number except that text is preceded by double quotation marks. As soon as you type the quotation marks, Abacus responds by emphasising the TEXT option box In the control area and showing text>" in the input line. You then type in exactly what you want to appear in the cell, followed by
ENTER. There IS no need for a closing quotation mark. Try entenng text into a few cells and, in particular, notice the difference between entering, say:
1000
I
ENTER
I
(a number) and
"1000
I
ENTER
I
(text)
A number is shown at the right of the cell, whereas text IS placed at the left The status area also shows the type of information; text, numeric and so on, in the current cell.
12:84
5
GeWng Started
THE COMMANDS
You select a command by first pressing F3.
The central part of the control area shows a list, or menu, of the available commands and IS known as the command menu, Illustrated Figure 2.9.
Most of the commands are described In later chapters but we can take a quick look at two of them. These are Zap, which you use to clear the whole grid, and Quit, which allows you to stop uSlnq Abacus and return to SuperBASIC.
Try the Zap command first Press F3 and locate the Zap command In the displayed menu. If you press the Z key, the word Zap will appear In the Input line - you need never type more than the first letter of any command. Also, the command box In the control area changes to show the menu tor Zap. Try pressing ESC first, to cancel the command.
Now return to the command menu by pressing F3 and then press Z to call the Zap command again, but this time press ENTER next, to clear the grid. You will be left with a blank grid and with the cursor in cell A1, ready to start afresh.
Whenever you want to leave Abacus and return to SuperBASIC, you must use the Quit command. ThiS works in a similar way to Zap, (press F3 and then the first ,letter of the command (Q)). QUitting causes you to lose the contents of your grid, so you are again given the option of going back to the main level by pressing ESC
HELP COMMANDS
I
f--'p~r:::eS~S~F~1~---j
I
Am end
PROMPTS Copy press
F2
Design
Echo
F i l es
Gri d
Justify load
Merge
Order
Pri nt
Quit
Rubout
Save
Units
Window
Xecute
Zap
COMMANDS press F3
ESCAPE press ESC command>
I
~
A1 GRID USED At :At MEKORY 23K
EMPTY
Figure 2.9 The command menu
6 12/84
Getting Started
CHAPTER 3
CELLS,
ROWS,
COLUMNS
AND RANGES
Much of the power of Abacus lies In its ability to handle whole rows, columns or ranges of cells In a single operation You do this by uSing simple expressions which allow you, for example, to fill all or part of a row of cells The values In the cells may all be made the same or they may vary In a regular way,
This chapter describes some of the properties of cells and the ways In which you can reter to them,
The cell is the basIc unit for holding Information ,n Abacus, Each cell can contain one
Item of information which may be text a number or a formula,
For each cell that contains Information, Abacus also keeps a record of how that information is to be displayed, You can, for example, display numbers or text at the left, centre or right of the cell, and you can display numbers in several different formats,
You use the Justify command to change the pOSition of the display within a cell. It allows you to select the position of numbers or of text Within a cell or group of cells,
Put a value of 100 In cell A1 and then use the Justify command by pressing F3 and then the J key, Abacus first asks you to select between a Cells and a Defaults option; select the Cells option by pressing ENTER, Abacus then asks you to choose between either text or numbers, Select numbers, by pressing the N key, Next you must select
Left, Centre or Right fustiflcaton, Since Left IS suggested by Abacus, select It by pressing
ENTER.
Finally Abacus asks you to speCify the range of cells that are to be affected, In this case just press ENTER, You will see that the value of 100 in cell Al Will move to the left hand side of the cell,
Note that you can change the numeric format or numeric justification of a cell which currently contains text Nothing Will appear to happen, If, however, you later change the contents of the cell to be numeric, it will be displayed With the format and justification that you speCified, This also applies to a change of text fustlfication for a cell which currently contains numeric information.
Cells that contain no information do not exist as far as Abacus is concerned, and use no memory, They can therefore have no properties, If you attempt to use the Cells option of either the Justify or the Units command on an empty cell they Will have no effect
Numbers subsequently placed into such a cell Will be displayed in the general default format
If you want to change these defaults you must use the Defaults option of either the Justify or the Units command (or both), For example, use the Defaults option of the Units command (press F3, U and then D) to select a default of percent format With one deCimal place, The choices are similar to those In the Cells option, but you are not asked for a cell range,
The Defaults option of the Justify command works in the same way, Again you are not asked to type in a cell range because Abacus will use the new default each time you put informatonlnto any preViously empty cell.
The new default settings Will remain In effect until you change them again, or until you finish using Abacus and return to SuperBASIC
To restore the detaults to their original state - numbers fustlfied right text justified left and numbers displayed in General format use the following sequences:
I
F31 J D N R [number right justified]
I
F31 J D
I
ENTER
II
ENTER
I
[text left fustified)
I
F31 U D G
I number displayed in general format]
CELLS
Justification
Empty Cells
Very often you will want to fill several cells in a particular row with a particular value, or with values that vary in a regular way Abacus provides Simple ways of dOing this,
One method IS to refer to the cells of a row with a range Ident!IJer, There are two range
ROWS
7
12.184
Cells. Rows. CdLlllns and Ranges
8 identifiers, row and col. They refer to the cells of the current row or column - the row or the column that contains the cursor.
As an example, let us fill the first row, from column B to column D. with the value 100.
We shall use the range Identifier row as follows. Place the cursor In cell A1 and then type: row
=
100 I ENTER I
As soon as you press ENTER a prompt appears in the input line suggesting that the row be filled starting at column A (the column containing the cursor). The system will always make a reasonable suggestion for the starting pOint and this can be accepted simply by pressing ENTER. In thiS case, however, we want to start at column B so you should press:
BIENTERI
The input line changes to show that the filling of the row is to start at column Band a further prompt appears with a suggestion of BL (the last column in the grid) for the end column. Again thiS will have to be changed, Since we want to end at column D, so you should press: .
o I ENTER I
The Instruction IS now complete and will be carned out - the value 100 will appear
In each of the cells from Bl to D1 inclusive and the input line will clear ready for your next input.
COLUMNS
Filling a column follows a very similar pattern except. of course, that you refer to a column by one or two letters rather than the number that identifies a row. Suppose we want to put the text 'helld in each of the cells of column D, from row 5 to row 11. We can do this by using fhe second range Identifier col. Move the cursor to cell D5 and type: co l = "he llo"
I
ENTER
I
This time Abacus suggests the correct starting point (row 5) as this row contains the cursor, and you can accept fhis suggestion by pressing ENTER. Row 255 will then be offered as a suggested end poinf and you should change thiS by typing:
11
I
ENTER I
The text will appear in cells D5 to D11 inclusive and the input line will clear ready for the next Input.
Each time you use col you will be asked to specify the first and last row to be affected.
You may, as usual, accept or replace the values that Abacus suggests.
In addition to this way of uSing the range identifiers row and col, you can also use them to specify the range of cells for any function that needs such a range. For example:
For example put some numbers in all the cells of the rectangular area whose top lett hand corner is the cell A1 and whose bottom right hand corner is the cell C3 (nine numbers in all). Now move the cursor to cell D1 and type: col = sum (row) I ENTER I
ThiS fills each cell of column D with the total of the values ,n the cells of the corresponding row. Abacus needs to know the ranges for both row and col. It will therefore ask for the range of columns for row (Abacus suggests column D to column D, which is correct
- accept each by pressing ENTER) and then for the range of rows to be used by col. Abacus suggests from row 1, which is correct. to row 255 (or to row 11 if you type
In this example immediately atter the prevIous one). Accept the first by pressing ENTER and type the correct value, 3 (don't forget to press ENTER) for the second. Abacus will then calculate the total for each of the three rows and display the results in the cells of column D.
LABELS
The previous examples referred to rows and columns by an explicit use of their number and letter cell references. An important alternative for identifying rows or columns is to use labels, that is names which you may choose yourself. These labels are then used to refer to specific rows, columns or cells.
Any text that you put Into a cell can be used as a label. You can use labels in anY command or formula where you would otherwise use a letter and number reference.
The advantage is it is much easier to remember names than numbers and letters when you want to refer to a particular cell.
12/84 l
CellS. Rows, COh.mnsand Ranges
This IS an extremely powerful and flexible method which you can use to great advantage to simplify the setting out and operation of a grid The following two sections explain how you can use these labels.
A label may reter to either a row or a column. depending on the contents of the other cells in the grid. The baSIC rule when you use a label to identify a row or column of figures IS that Abacus searches below and to the right from the cell containing the label.
HELP press f1
PROMPTS press F2
CURSOR press <---il---'
GOTO CELL press FS
B
DA TA & fORMU LA enter directly
& press ENTER
C
TEXT type" COMMANDS press f3 fa llowed by ESCAPE text & ENT.
press ESC
Rowand Column
Labels
100 00
CELlA'
WW,t. . "
GRID USED A1 :C4
EMPTY
Figure 3,1 Labelling a row
MEMORY23K
HELP CURSOR
EPccre"s"'sccfo-'_---i1 press +-U-
PROMPTS GOTO CELL press f2 press fS
DATA
& fORMULA enter directly
& press ENTER
MARCH
'0000
TEXT type" followed by text & ENT.
COMMANDS press f3
ESCAPE press ESC
CELLA1 GRID USfD A1:C4
CONTENn EMPTY
Figure 3.2 Labelling a column
MEMORY 23K
9
CellS. Rows. Cdumns and Ranges
The closest cell that contains a number, below or to the right of the position of the label, determines whether the label refers to a row or to a column, Figures 3,1 and 3.2 should help make this clear In Figure 31 the label refers to a row and in Figure 3.2 It refers to a column
In more complex cases, for example where there are numbers both to the right and below the label, the nearest number (measured by the number of cells separating the number from the label) determines whether it IS a row or a column reference. If the two numbers are the same distance from the label, Abacus shows the message
Cannot teLL whether name ;s a row or col and walt for you to press the space bar. Abacus will then put the text of your formula back into the Input line so that you can correct It with the line editor
You should replace the unresolved reference with either row or col and press ENTER again You should consider rearranging the labels so that Abacus can resolve the reference In future.
HELP
PROMPTS press F2
CURSOR
~"j ~
GOTO CELL press F5
DATA & FORMULA enter directly
& press ENTER
TEXT type rt fa llowed by text & ENT.
COMMANDS press F3
ESCAPE press ESC
10
CELL At GRIP USED A1: C4 cONTENTS EMPTY
MEMORY 23K
Figure 3.3
Labelling a cell
Labelling Cells
You can also use labels to refer to single cells, but in this case two labels are needed.
In the following example the labels 'March' and 'Costs' can be used to refer to cell C4.
The reference is made up of the names of the two labels, separated by a full stop (eg.,
March.costs). It IS not necessary to give the full names, and no distinction IS made between upper and lower case letters. Also Abacus needs only enough letters at each name to make sure that the Identification IS unique. In the above example 'marcos' would be perfectly adequate. The order of the labels IS also irrelevant, so you could also use cos. mar' to refer to the same cell.
RANGES
In addition to being able to refer to a whole row or a whole column, you can make an Instruction work on a rectangular block, or range, of cells.
A range reference is made up of two parts. The first part IS the row and column reterence of the top left hand cell of the range. This IS separated by a colon from the second part, which is the row and column reference of the bottom right hand corner of the range.
An example of a range reference is:
A2:D27
12/84
''''
...
r
An example of fhe use of a range reference would be fhe use of the Copy command to copy the confents of a range of cells to a similar range at a different place In the grid.
Many of the commands ask you to type In a range reference, to identify the cells on which they are to work. Since a range reference has a much wider set of possibilities than a row or column reference, Abacus can not suggest a possible range. You must type In the entire range reference yourself. You can specify the range In anyone of four ways. These are
1 With expliCit row and column numbers and letters, e.g. A1:C7
2.
With labels, e.g. January.sales:march costs
3.
With a combination of the above two methods, e.g. Almarch.costs
4.
With a range identifier, e.g.
row (or col)
ThiS refers to the cells of the row (or column) that contains the cursor. In thiS case,
Abacus can suggest sUitable start and end pOints.
HELP
EP~re~s~s-cF~l_--j1 new loeat i on
PROMPTS Enter the range to be copied as press F2
COPY-contents of a block of cells to a
(Top left cell) : (Bottom right cell)
COMMANDS press F3
ESCAPE press ESC
Cells, Rows, Columns and 8anges command> copy, from range b3 dsl
CElL A1 GRmUSEDA1:DS HEMORY23K
CONTENTS EMPTY
Figure 3.4 A range reference
Now that we have seen how the position of a cell or range of cells can be specified to Abacus, we can go on to show how the appearance of the contents of these cells can be modified. First we must explain the way In which numbers are stored. Move the cursor to cell A1 and type in the number 123.456.
Abacus stores all numbers to an accuracy of 16 significant figures and it can display up to 14 significant figures - the extra two figures are used to make sure that the calculated value is displayed accurately. Although Abacus calculates and stores all numbers to thiS accuracy, you do not have to display all the significant figures.
Select the Units command (by pressing F3 and then the U key). There are two options:
Cells or Defaults. In this case press ENTER to select the suggested Cells option.
Abacus offers you several different forms of display.
MORE ABOUT
NUMBERS AND
TEXT
12J84 11
ceUs, ReM's. Cdt.mns and Ranges
12
Press the M key to select the Monetary form of display. Abacus asks you to choose how you want it to show negative values. Abacus suggests that they are displayed with a leading minus sign and you can accept this suggestion by pressing ENTER
Alternatively you can display negative values ,n brackets by pressing the B key Instead.
In this example It does not matter which we choose, but we shall assume the minus sign option.
Abacus then asks you to specify the range at cells which are to be affected. You could reply by typing In a range reference (e.g. A1:B3) or Just the reJerence to a single cell.
Abacus will always try to anticiPate the range you require Howeve, in some circumstances
Abacus IS unable to do this and will simply suggest the range AtAt This range reference
IS identical to the single cell reference A1 You can either accept the suggestion by pressing
ENTER or type in your own reference choice tollowed by ENTER.
We will assume that Abacus makes the default range suggestion A1 :A1 and the complete sequence of keypresses is:
I F31 U I ENTER I Ml r;
E"'"N""T~ER""II
ENTER I
Just before you press ENTER for the third time the input line should contain:
Command>units,ceLLs,monetary,minus sign,range A1 :A1
When you press ENTER the display In cell A1 Will change to £123.46, even though the actual value (123.456) is still kept, and shown in the status area. Abacus automatically takes you back to the main display.
The monetary form of display always shows the number rounded to two deCimal places, with a leading currency sign. (You can change the sign to $, or anything else, by uSing one of the options In the Design command.)
Let us now change the display in cell A1 to Integer (whole number) format, by calling the Cells option of the Units command again, but this time pressing the I key. This format also allows you to choose whether to use a minus sign or brackets to show negative numbers and this time we can choose the bracket option by pressing the B key followed by ENTER (again we are only affecting cell A1).
The full sequence of keypresses in this case is:
I
F31 U
I
ENTER
II
B
I
ENTER
I and the input line shows:
Command>units, cells, integer, brackets, range A1 :A1
The cell display now shows 123 - the deCimal point and all figures following It are not shown in integer format
We can now try Decimal format For this, and the remaining formats, you do not have the option of displaying negative values in brackets. Instead (except for the General format) you must specify the number of figures you want to be displayed after the decimal pOint, let's use tive decimal places. Select the Cells option of the Units command. Decimal is the default format and can be selected simply by pressing ENTER, then speCifying five deCimal places. Finally, in response to the 'range' prompt, press ENTER to accept the detault suggestion. The full sequence of keypresses and the corresponding Input line contents are:
I
F31 U
I
ENTER
II
ENTER 15
I
ENTER
II
ENTER
I
Command>units,ceLls,decimal,decimal places S,range A1:A1
Cell A1 will now show 123.45600, as required.
Now use the command again, but thiS time press the P key, to specify the Percent format
Use one decimal place and select cell At The full sequence of keypresses is:
I
F31 U
I
ENTER
I
P 1
I
ENTER
II
ENTER
I
The display will now show 12345.6%. The percent option shows a number multiplied by 100 With an added % sign. Note that the stored value, as shown in the status area, is still 123.456, regardless of the cell display.
We can now try the Exponential format, with three deCimal places, by typing:
I
F31 U
I
ENTER
I
E 3
I
ENTER
II
ENTER
I
12184
'"
Before you press ENTER for the th"d time the Input line should contain:
Command>units,ceLls,exponent,decimaL places 3,range A1 :A1 and, after pressing It, the cell display will be 1.235E +02.
The exponential format is used to display numbers which are too large or too small to be written in decimal format The number IS written as a value between 1 and 10, multiplied by the appropriate power of ten. The number 2 300 000 000, for example, can be written as 2.3 multiplied by 1 000 000 000 and 1 000 000 000 is ten raised to the ninth power (nine tens multiplied together). So 2 300 000 000 could be written in exponential format as 2.3 E+09. Very small numbers are written uSing negative powers of ten. Thus, the number 0.000123, which is 1.23 divided by 10000 (ten raised to the tourth power), can be written In exponential format as 1.23 E-04.
The remaining option is the General format, which you can see in cell A1 by typing:
IF31uIENTERIGIENTERI
The input line contains:
Command>units,ceLLs,general,range A1:A1
This format again does not require you to specify the number of decimal places. Using the General format lets Abacus choose a sensible form for the display of each number
It does the best it can to display each number as accurately as possible In the space that is available.
Before we leave the Units command, try displaying the number in cell A1 in decimal format, with nine decimal places. Type:
I F3
I
U I ENTER
II
ENTER I 9 '"I
E'"N=T=ER~II
ENTER
I
Cell A1 now shows # # # # # # # # # # indicating that the display will not fit in the space available Whenever you see this, you should then either change the display format or increase the width of that column.
Now clear the grid by using the Zap command. With the cursor at cell A1, type:
"This is a Long bit of text
Although the text is too long to be contained in one cell, it is all shown. It overflows across the following cells. Now put the number 1 into cell B1. The text is cut off at the end of cell A1 as it is not allowed to overflow across another filled cell. Move the cursor back to cell A1 and verify that the whole of the text is still stored by looking in the status area.
Move the cursor back to cell B1 and use the Rubout command to erase. When you use this command you are asked to specify the range of cells whose contents you want to delete. In this case we only want to delete the contents of cell B1 and can do so by pressing ENTER. The full sequence of key presses is:
I F31 R
I
ENTER
I
Now that cell B1 is empty, the full text in cell A1 appears again.
CEJ's. Rows. CcJL.<T1ns and Ranges
12/84
13
14
CHAPTER
4
FUNCTIONS
AND
FORMULAE
FUNCTIONS
Abacus contains a number of pre-defined functions which are used to perform specific calculations on the contents of one or more cells. A function takes a number of input values, known as arguments, and from them calculates a specific result. The result IS said to be the value that the function returns.
In Abacus you must supply the arguments In brackets after the name of the funclion and, If there IS more than one argument. you must separate each with commas. Most of the functions prOVided return a numeric value, for example, the function sum( ). This takes, as an argument, a range reference and returns a numeric value equal to the sum of the numeric values contained in all the cells within the range.
Some functions, such as month(), return a text value. (month(1), for example, returns the text January'). A few functions require no arguments, but you must still include the brackets. For example the function pi( ) returns the numerical value of the mathematical constant
IT
(approximately 3.14).
.
Two particularly useful functions are col( ) and row(). These return the number of the column (or row) which intersect at the cell that contains the function. They are used extensively in the examples In the next chapter.
For example, col() will return a value of 1 from column on. The function row() Simply returns the row number
A.
2 from column B, and so
As an example we can use the two functions month( ) and col() to label columns of the grid. The object will be to place the headings January, February, and so on at the top of columns B to M. We use the funclion col() to supply the number that month() needs as its argument. so that It gets a different value ,n every column. Type In: row
= month(coLO) and then press ENTER. Select the range from B to M when Abacus asks for the start and end columns. You will see that the result is not quite what we want in that. although the labels start at column B, the first label is February and not January. This IS because, in column B, col( ) returns the value 2 and month(2) IS the text 'February: All we have to do is to alter the Instruction so that 1 IS subtracted from the value returned by col(), before calculating the month. Type In: row = month(coL 0-1J
(Don't forget to press ENTER to mark the end of the Input.) Select the column range from B to M, as before.
FORMULAE
A formula is usually used to relate the contents of one cell to the contents of one or more of the other cells in the grid. The idea of formulae is very important in the use of Abacus as it allows you to describe even the most complicated calculations ,n a Simple way.
You enter a formula into a cell uSing the same method employed for entering numbers, that is, by moving the cursor to the cell, typing It and then pressing ENTER. Abacus assumes that anything it does not recognise as a number (starting with a numeric digit) or a text value (starting with quotation marks) IS a formula.
Move the cursor to cell B3 and enter the number 100, move the cursor to cell C3 and enter 200. Now move the cursor to cell D3 and type In the following formula
83 + C3
When you press ENTER you will see two things happen. First the value 300 Will appear
In cell D3; the formula's result has been calculated by adding together the contents of cell B3 and cell C3 and the total placed In cell D3. In addition you Will see that the status area at the bottom of the screen shows the formula used to calculate the value in this cell. A cell which contains a formula will always show the result of the calculation. If you position the cursor on the cell then Abacus will show the formula Itself in the status area at the bottom of the screen.
12/54
Functions and FormlJae
The rest of the examples uSing formulae make use of the labelling facility and the rOw and col range Identifiers. They allow much more efficent methods of entering Information into the grid than the direct use of letter and number cell references
Note that any numeric formula that does not contain any cell references is not stored as a formula. In such a case Abacus calculates its value and stores the result as a pure number. For example, 37 + 100/20 IS stored as the value 42, and not as the original formula.
A
3
4
1
2
5
Sales
Costs
Profit
Figure 4,1 Simple cash flow analysis
B
January
£1000.00
£722.00
£278.00
l e o
February March
£1050.00
£749.50
£300.50
£1102.50
£778.38
£324.13
I E
Apri L
£1157.63
£808.69
£348.93
Start thiS example with a grid containing month headings In cells 81 to M1. If you have anything else In the grid you should clear it With the Zap command.
Now move the cursor to cell A2, enter the text 'Sales' and then put the value 1000 in cell 82. Now move the cursor to cell C2 and type In the formula: row=saLes.january*1.0S
Accept the range selection given by Abacus (column C to column M) by pressing ENTER twice. Note that Abacus knows the end of the row is at column M because that is where the previous row ended. When you press ENTER a second time you will see a whole series of values appearing in row 2, from column C onwards, and the formula 82
*
1.05
will appear in the status area at the bottom of the screen.
If you move the cursor along row two you Will see that the formula for each cell IS slightly different. In each case the formula takes the contents of the cell on the Immediate left and multiplies it by 1.05 to obtain the value to place in the current cell. For example, the formula in cell E2 refers to cell 02, and the formula in cell H2 refers to cell G2, and so on.
In Abacus all formulae work in thiS way unless you specify otherWise. Each formula remembers the relative positions of all cells to which it refers. When such a formula is used in more than one cell the references are adjusted to maintain a relative cell reference.
It may prove helpful to pOint out that the initial value of 1000 placed In cell 82 was necessary for two purposes; to ensure that fhe label 'Sales' was recognised as a row reference and also to specify the first value to be used by the formula.
Now position the cursor at cell A3 and enter the text 'Costs: Without moving the cursor, type In the formula: costs = sales
*
0.55
+ 172
ThiS formula calculates the cost from two components. They can be regarded as manufacturing costs (55% of sales) and fixed costs totalling £172.00.
Use the suggested start and end points of column 8 and column M. Since the contents of the row is defined in terms of the row reference 'Sales: the label 'Costs' will also be taken as a row reference, with the same range as 'Sales:
Again you should move the cursor along the row, examining the different formulae shown at the bottom of the screen, In order to understand how the results have been calculated.
Finally, put the text 'Profit' in cell A4 and type In a further formula profit = sales-costs
A SIMPLE CASH
FLOW EXAMPLE
12/84 15
Functions and Formulae with the same range selection as betore (I.e columns B to M). Abacus will do all the rest of the work for you, producing a simple, but complete, example. If you now change the display to monetary format with the command:
IF31
Units,CeLLs,Monetary,Minus sign,Range 82:M4
you should find that the first few columns appear as in Figure 4.1.
AUTO·CALCULATION
When you have typed In the simple cash flow application described In the previous sedon, try changing the number in cell B2 (Sales.January).
Move the cursor to this cell - the easiest method is to press F5 and then type in the cell reference (either B2 or sal.Jan) followed by ENTER. Now type in any number you like. When you press ENTER you will see that all the numbers in the grid will change l
All the formulae In the cells of the grid are recalculated automatically each time you make an entry to a cell. Since all the formulae in thiS example refer, directly or Indirectly, to the value held In cell B2, all their values will change when you alter the contents of this cell. (Remember that we assumed that sales would Increase by 5% per, month, based on the January figure.)
You can switch off the auto-calculate facility by uSing the Design command. ThiS IS useful.
for example, when you have many complicated formulae In the grid and do not want to wait for a recalculation each time you change a single value.
Select the DeSign comand by pressing F3 and then the D key. The display changes to show a list of the options, as shown in Figure 4.2. You can select anyone of these options by typing ItS first letter. Select the auto-calculate option by pressing A and the auto-calculate slate changes automatically. You leave the command by pressing ENTER.
HELP press F1
PROMPTS press F2
DESIGN allows modification of options
Press first letter of option
Press ENTER when finished
COMMANDS press F3
ESCAPE press ESC
AUTO-CA LCULATE on i npuL __________ __________ ___ ______ __________ ______ YES
BLANK if 'ero NO
CALCULATION order row or column
DISPLAY 80,64,40, co Lumns (8,6,4)
FORM feed between page'-
GAPS between lines on printer
LINES per page of printer paper
MONETARY symbol (e,g. f ,$)
PRINTER paper width (characters)
ROW
64
YES a
66
£
80
Figure 4,2 The design command
If you now change the contents of cell B2 you Will see that there is no change in the contents of any of the other cells.
You can also force a recalculation of all the formulae in the grid at any time by uSing the Xecute command. While you have the auto-calculate turned off, try using thiS command. Make sure that the command menu IS displayed in the control area (press
F3) and then press the X key. The values ,n the cells of the grid will be recalculated.
.
...
16 12/84
Before you go any further you should restore the auto-calculate faCIlity by uSing the Design command again. Select the auto-calculate option by pressing the A key, as before, and leave the command by pressing ENTER.
Functions and Formulae
12/84
17
18
CHAPTER 5
THE
EXAMPLES
The following sections illustrate the use of Abacus by developing a number of examples.
In addition to explaining the way a number of features work, the examples have been chosen to show some of Abacus's wide range of applications. The best way to learn about Abacus is to use it The examples have been written with this in mind.
You are recommended to work through all the examples yourself, typing them In as you go along. Each contains some additional information, as well as giving more pracllce with the topics covered In earlier examples. You may well be able to think of modifications and Improvements and they should give you ideas about how to construct applications of your own.
In all the examples In this chapter, text, numbers and formulae are shown exactly as you would type them In. If a cell range IS required, it will be given In brackets at the end of the line. In many cases the range you need will be the one that Abacus suggests and you can select it simply by pressing ENTER. In other cases you will have to type
In the range yourself. If the cursor needs to be positioned on a particular cell, its cell reference is shown In square brackets at the beginning of the line - do nor type in any such cell reference. For example, the line:
IMj ro.,=month(colO-ll IcolumnsBtoMj should be read as: move the cursor to cell A4, and then type In ro.,=month(col()-1)
If necessary, modifying the range suggested by ABACUS to be from column B to column M.
Where you have to type in an explicit range reterence, e.g. b3:e15, It will be given In that form.
When commands are given in full they are shown exactly as they will appear on the screen. Remember that you only need to type in the first letter of each option - the rest is filled in by Abacus. If you want to use the default option you should Just press ENTER.
Each example assumes that you start with a completely blank grid. If necessary clear the grid with the Zap command before starting to type In the example.
CASH FLOW
MODELLING
This is a more complete version of the simple cash flow example of Chapter 4. When you have finished the grid it should look like Figure 51.
The first two cell entries produce an underlined title for the grid.
[C1]
"CASH FLOW
[C2] reptC"=",len(c1)
The second entry uses the rept( ) function which needs two arguments. The first is text, or a reference to a cell which shows a text value and the second is numeric. The function produces that number of repetitions of the first character of the text In thiS case It underlines the 1I1Ie with '=' signs, to the exact length of the title. If you decide to change the title there IS no need to alter the formula in cell C2 since it uses the len( ) funclion to read the length of the text in cell C1.
[M] row=month(col ()-1) [columns B to MI
[ASI ro.,=rept("-",width()+1) [columns A to Mj
These row entries produce month headings, and rule a line across the whole of the used part of the grid. The function width( ) gives the width, in character spaces, of each column. It can therefore be used to rule lines across a grid With columns of different widths. There is one extra character space separating each column of the grid, which
IS why the additional +1 is needed.
[A6] "SALES
[B61 4000
[C61 rO"=50
1.
j on*1 .02
Icolumns C to MI
12/84
•
• lill,,'" entries fill In the sales figures for the year, assuming that the January sales were
40111 I .md that sales are increasing at 2% per month.
E
!
1
I,
';
I
6
7
1
A B
I
C D
1
1
I
I
I
1 SALES
I
COST OF SALES
CASH FLOW
=======
January February March Apri L
1---------------------------------------------------
4000.00
2750.00
4080.00
4161.60
4244.83
1---------------------------------------------------
GROSS PROFIT 1250.00
2790.00
1290.00
2830.80
1330.80
2872.42
1372.42
8
9
•
17
18
19
20
16
10
11
12
13
14
15
21
1
I
EXPENSES
I wages 700.00
700.00
700.00
700.00
1 advertising 100.00
100.00
100.00
100.00
I
1
I rent eLectricity
200.00
50.00
200.00
50.00
200.00
50.00
200.00
50.00
depreciation 90.00
90.00
90.00
90.00
1---------------------------------------------------
I
TOTAL EXPENSES 1140.00
1140.00
1140.00
1140.00
1---------------------------------------------------
I
NET PROFIT 110.00
150.00
190.80
232.42
1===================================================
-=:,gure 5.1.
The completed cash flow grid (first five columns)
(A7] "COST OF SALES cos=saL*0.5+750 [columns B to Mj
(The costs are assumed to be half at the selling price plus a fixed amount of £750.00.)
(A8] row=a5 [columns A to
[A9] "GROSS PROFIT gro=sal-cos [columns B to
M]
M]
This rules off the grid again and calculates the monthly gross profit tigures.
[A11] "EXPENSES
[A12j "wages row=700 [columns B to
MI
IA13] "advertising row=100 [columns B to MI
(A14] "rent row=200 [columns B to Mj
[A15j "eLectricity row=50 [columns B to M]
[A16] "deprec i at i on row=90 [columns B to M]
These entries fill in the expense figures, assuming them to be constant throughout the year. You can, of course, change the expense headings and"amounts to suit yourself.
You can Include more or fewer entries, as long as you make the necessary changes to the cell references in the rest of the example. You may want to have different values for each month, but it IS faster to set up the table with fixed values and modify them later
[A17] row = as [columns A to Mj
[A18] "TOTAL EXPENSES
(B18] row=sum (co I) [rows 12 to 16, columns B to Mj
[A19] row=a5 [columns A to M]
You now have the totals of the monthly expenses.
The sum( ) function adds the contents of all the numeric cells In the range specified as ItS argument. All empty cells. together with those containing text. are Ignored. The range could be given as an expliCit range reference B12:816 for example. In this
Exampes
19
Examples case, however, each range is only a single column so we have used the range specifier
'col: All you need to do IS to answer the range questions asked by Abacus, and just press ENTER if the suggested range IS what you want.
Note that thiS formula uses the range Identifiers row and col in the two different ways.
Firstly, row IS used to Indicate that the formula IS to be placed in several cells of the current row. Secondly, col IS used to specify the range of cells over which the addition should take place. Both of the range identifiers need you to confirm (or change) their beginning and end points. In this case Abacus deals with the range for the sum( ) function first
[A20] "NET PROF IT net=gross-tot [columns B to M]
IA21] row= reptC"=",width()+1) [columns A to
MJ
The table IS now complete, with the net profit figures calculated as the difference between the gross profits and the total expenses. All you have to do now IS to adjust the appearance of the table by uSing a few commands. Remember to press F3 each time you want to use a command.
First we change the width of column a (note that the Grid command has its own menu of options).
Grid>Width, 15 FROM a TO a
Then we change the Justification and numeric display format for a few cells:
Justify,CelLs,Text,Right,Range a4:m4
JustifY,CelLs,Text,Right,Range a12:a16
Units,Cells,Decimal,Decimal places 2,Range Range a1 :m21
We have chosen to display the figures in decimal format, with two decimal places. If you prefer the pound sign to appear you should replace the last command by
Units,CeLLs,Monetary,Minus sign,Range a1 :m21
It is very simple to alter any of the figures. Suppose you want to increase the February advertising figure. All you have to do is press F5 (go to a cell) and type the cell reference feb.adv
The cursor will move to that cell and you can type a new value.
Remember that the sales figures were calculated by a formula which assumed a 2% increase each month. If you change one of these cells to a numeric value you will destroy the formuia In that cell. The formulae in the other cells of the row will, however be unchanged. The amounts in the following cells will stili Increase by 2% per month, starting from the new val ue.
MULTIPLICATION
TABLES
ThiS simple example may prove useful to a child who wants to learn the multiplication tables. It lets you request a particular table and then displays It.
When you have typed in the example you use it by forCing a recalculation of the grid with the Xecute command, i.e. you type:
IF31x
Abacus then asks you to type in a number and displays the corresponding multiplication table.
The table in Figure 5.2 shows an example of the display it produces.
First title the application as normal:
[B1] "MULTIPLICATION TABLES
[B2J rept("=",lenCb1»
The next three lines give a heading to the table.
[B3] "The
[C3] askn("Which multiplication table do you want")
[03J
"times table t
20 12/84
Here we have used the askn( ) function to request Input; it allows you to choose which table you want. by typing in a number.
A
8
9
6
7
3
4
1
2
5
10
11
12
13
14
15
Figure 5.2 A multiplication table.
I B I C I
MULTIPLICATION TABLES
0
==================
7 times tabLe
6 *
7 *
8 *
9 *
10 *
11 *
12 *
The
1 *
2 *
3 *
4 *
5 * 7
7
7
7
7
7
7
7
7
7
7
7
=
=
=
E
35
42
49
56
63
70
77
84
7
14
21
28
F
This function takes a text string as Its argument and displays the text in the input line, followed by a question mark. It then walts for you to type in a number, ending with ENTER.
The number that you type In will be displayed in the cell which contains askn( ).
Note that askn( ) will not wait for input during a normal auto-calculation of the grid. It will only display the message and request input when first put the fomula into the cell, or when you force a recalculation of the grid by using the Xecute command. Once you have input a value to the cell it will be retained until the next lime you force a recalculation with the Xecute command.
The remaining grid entries use the column-filling facility to produce the body of the multlplicalion table.
[84] col=str(row()-3,2,Ol+" *" [rows 4 to 15)
This is the most complicated formula of the example. It is used to display the multiplier
In each row of the table. The number IS converted to a text string so that we can combine it with the multiplication sign and display them both in a single cell.
The s1r( ) function converts a number to the equivalent stnng of digits. It takes three values; the number to be converted, a code for the format (0 ~ deCimal, 1 ~ exponential,
2 ~ Integer, 3 ~ general) in which the number IS to be displayed, and the number of deCimal places to be shown. In this case the number is converted to integer format.
In this case the value is obtained from the expression 'row( )-3', whose value is 1 ,n row four, 2 In row five, and so on, up to 12 In row 15. The next value (2) selects display as an Integer (whole number). The third number normally specifies how many decimal places are to be used. Its value must always be given but is ignored for integers. It has been given a value of zero (any other value could have been used).
Finally the result is concatenated (the correct term for adding one text string to another) with the string
*, so that both the multiplier and the multiplication sign are displayed in a single cell.
[C4] co L=$c3 [rows 4 to 15]
Column C contains copies of the value typed in in answer to the askn( ) function. The cell reference is preceded by a $ sign to make it an absolute cell reference.
When you have entered the formula, move the cursor up and down the cells of column C and look at their contents. You will see that they all contain the cell reference $C3. The reference has not been adjusted in each row An absolute cell reference always refers to one particular cell, from any position in the grid. You can make any cell reference absolute by adding a leading $ sign.
[041 co L="=" [rows 4 to 15]
[E4] coL=$c3*(row()-3) [rows 4 to 151
These last two column entnes are almost self-explanatory. They are used to produce the equals sign and the answer for each row of the table. The last formula multiplies
Examples
21
Examples the value from the askn( ) function in cell C3 (another absolute cell reference) by the row( )-3 expression which, as we saw earlier, gives a value of 1 in row four, 2 In row five, up to 12 in row fifteen.
We now need to use a few commands to change the display of the table to a more convenient form. Use the following commands:
JustifY,Cells,Text,Right,Range b3:b15
JustifY,Cells,Text,Right,Range d4:d15
Justify,CeLLs,Numbers,Centre,Range c3
Grid>Width. 5 FROM b TO b
Grid>Width. 3 FROM c TO c
Grid>Width, 2 FROM d TO d
Grid>Width, 4 FROM e TO e
You use the table by forcing a recalculation of the grid with the Xecute command. The text of the askn( ) function Will appear in the Input line - and you should type In a number between one and twelve.
CHEQUE BOOK
RECONCILIATION
This example allows you to keep a check on your bank account. You enter .details of your cheques in the spaces provided. At the end of the month you add the details of your salary, standing orders etc. You are then provided With a balance which you can compare With your bank statements.
The result, with a few figures added, is shown In Figure 5.3.
24
25
26
27
20
21
22
23
28
29
30
31
13
14
15
16
17
18
19
10
11
8
9
12
3
4
5
1
2
6
7
I
I
I
A
I
I
I
I Opening baLance
I Satary
I B
CHEQUE BOOK RECONC I tIATION
======================
I
I
I MisceLLaneous income
CREDIT
I
I
I Standing orders
I Charges
I
I
I
I Cheques Date
3/01/84
10/01/84
14/01/84
Month
200.00
527 . 35
0.00
727.35
Cheque no.
123456
123457
123458
I
I
I
I
I
I
I
I
I
I
I DEBIT
I
I Closing balance
17/01/84
24/01/84
31/01/84
123459
123460
123461
315.14
Janua ry
C
130.00
0.00
Amount
50.00
50.00
32.21
50.00
50.00
50.00
412.21
Figure 5.3
Cheque book reconciliation
[B1] "CHEQUE BOOK RECONCltIATION
[B2] rept(II=II, len(b1»
[C4] "Month
[D4]
askt ("Enter month")
..
1
, .
12/84
The askt( ) function works in the same way as askn( ), but the expected input is text instead of a number When you use Xecute Abacus will display the message in the input line and then wait for you to type In some text You should type in the name of the month for your balance,
[A6] "Openi ng ba lance
[A7] "Salary
[A8] "Mi sce llaneous income
IC6] askn(a6+" for "+$d4)
The prompt string for askn( ) is constructed from the text of other cell entries, using both relative and absolute cell reterences.
We now use the Echo command to copy the formula from cell C6 into cells C7 and
C8. Instead of typing the range reference C7:C8, we can use the range Identifier col.
Echo,ceLL c6,over range coL (rows 7 to 8)
[810] "CREDIT
[C10] sum(col) [rows 6 to 81
Cell C10 IS used to contain the total of all credits for the month. This cell is labelled;
ItS reterence IS 'credit month':
The cell's contents are calculated uSing the sum( ) function which we met in the tirst example in this chapter This function adds the numeric contents of all cells in the range specitied by its argument Remember that it Ignores any cell ,n the range that is empty or that contains text
In this case we have again used it as sum(col), which specoies that the cels to be summed lie in the current column. As normal, Abacus asks you to speCify the exact range, suggesting reasonable values based on your previous work.
IC11] rept("=",len(str<credit.month,O,2)))
Cell C11 underlines the total, using the usual rept( ) and len( ) tunctlons. In this case, however we do not know in advance the number of characters to underline. We therefore have to convert the number to a string of characters with the str( ) function, assuming that it is to be shown in decimal format with two decimal places, The length of this string gives the correct number of characters to underline,
[A13] "Standing orders
[A14j "Charges
[013] askn(a13+" for "+$d4)
[014] askn(a14+" for "+$d4)
These allow you to enter the monthly debits In response to prompts, uSing askn( ) in the same way as described earlier
[A16] "Cheques
[816] "Date
[C16] "Cheque no
[016J "Amount
[817] row="---" [columns 8 to OJ
These cells set up an area of the grid which you Will later use to enter the details of your cheques,
[828] "DEBIT
[028] sum (co l) [rows 13 to 261
ThiS calculates the total of the debits, Remember that sum( ) only adds numeric values in the cells of the specified range. Cells containing text and empty cells, are not Included.
The sum will therefore ignore all unused entries in the list of cheques, as well as the table heading In column 0
[A30] "Closing balance
[C3~ credlt.month-debit.amount
The calculation of the closing balance completes the grid entries, You should now use the commands to tidy up the appearance of the application,
First we can use the Echo command to fill the rest of the cheque table and complete the underlining of the totals. ThiS command makes copies of the contents of a single
12,'84
Exampjes
23
Examples
24 cell Into all the cells ,n a range The first of the following three uses, for example, copies the contents of cell 817 into all the cells ,n a rectangle whose top leff and bottom right corners are 818 and 026 respectively.
Echo,CeLL b17,over range b18:d26
Echo,CelL c11,over range d29:d29
Echo,Cell c11,over range c31:c31
Next we need to set the numeric display to deCimal, with two deCimal places, for the whole of the application, with Integer format for the cheque numbers:
Units,CeLLs,DecimaL,DecimaL pLaces 2,Range a1:d30
Units,Cells,Integer,Minus sign,Range c17:c26
We have already explained that empty cells do not exist as far as Abacus IS concerned and sc a change of format will therefore only affect non-empty cells. We can fill the cheque table with' --- ' before making the change to ensure that these cells are changed to deCimal format An alternative method IS to change the default format
Finally we can modify the Justification of the text, Including the underlining, to Improve the final appearance.
Justify,CeLLs,Text,Right,Range b16:d26
Justify,Cells,Text,Right,Range c11
JustifY,CeLLs,Text,Right,Range d29
Justify,Cells,Text,Right,Range c31
The part of the gfld that IS used is too large for It all to be VISible In the Window at once,
In order to see the final results, together With the values entered via the askt( ) and askn( ) functions, you might like to use the split window facility. The Window command splits the Window, either vertically or horizontally, into two windows, uSing the position of the
Cursor to determine the position of the split
A vertical split IS most SUitable for this grid and you can set it up by moving the cursor to the centre of the window and then using the command:
Window,Vertical,Separately
You can move the curSOr from one window to the other by pressing F4. For this example you should use the cursor to adfust the leff hand Window to show cell A1 at its top leff corner, and cell 815 at the top leff corner of the fight hand window
STANDARD
DEVIATION
ThiS example calculates the mean and standard deViation of a set of numbers. It makes use of the labelling facilities of Abacus so that the formulae used in the calculations are mostly self-explanatory.
11
12
13
14
15
16
17
18
9
10
6
7
8
1
2
3
4
5
Mean
A I B
Value
5.00
6.00
7.00
8.00
9.00
10.00
11 .00
12.00
13.00
14.00
9.50
Figure 5.4 Standard deviation calculation
I C
STANDARD DEVIATION
===============
Variance
Std.
Dev.
D
Deviation Square
-4.50
20.25
-3.50
-2.50
-1 .50
12.25
6.25
2.25
-0.50
0.50
1.
50
2.50
0.25
0.25
2.25
3.50
4.50
6.25
12.25
20.25
of dev_
8.25
2.87
---------
E
In addition It uses a grid layout which requires calculation In column order, rather than the normal row order,
12/84
'-/
Examples
In general, a formula should only refer to cells that are in the region above and to the left of the cell containing the formula, including the row and column containing the formula.
If you do not follow thiS rule, as ,n this example, it is likely that the results may be incorrect.
In most cases you can obtain a correct result by forcing a recalculation of the gnd With the Xecute command or, as in thiS case, calculaflng the gnd In column order
[B1] "STANDARD DEVIATION
[82] rept<"=". Len(b1))
[B4J "Va Lue
[C4] "Dev i at i on
[04] "Squa re of dev.
[B5J co L=ro_ () [rows 5 to 14]
This last formula Inserts a set of dummy values in the cells of column B for testing the application. When the gnd entnes are complete you can replace them with other values.
The table described In this example will only hold ten values - you can change thiS to cope with more if you want.
[A16] "Mean
[816] ave(vaLue) [rows 5 to 141 deviation=vaLue-$mean.vaLue
trows 5 to 14] square=dev*dev [rows 5 to 14J
[C16J "Vari anee
[016] ave (square) [rows 5 to 141
These formulae show that the variance of a set of numbers is defined as the average of the squares of the deviations from the mean,
[C17] "Std. Dev.
[D17J sqr(varianee) [columns 0 to 0] and that the standard deViation can be calculated as the square root of the variance.
[D18J rept("-". Len(str(std.sq.3.Q)))
The numbers In this example are left in general format so that it can handle any range of values. The underlining uses the length of the text string corresponding to the number in the cell above (with cell reference "std.sq') expressed in general format.
You can improve the appearance of the display by changing to centre Justification for the text in the range B4:04, and using left justified numbers in the range B16:017.
If you try using this example by putting different values In the cells of column B, you will find that it does not give the correct answers. The reason is that the recalculation of the grid is performed row by row, from the top downwards. Any alteration you make will therefore be worked out on the basis of an incorrect mean value (since the new mean will not be calculated until after the deViations from the mean). The solution is to make the recalculation of the grid be in column order from left to right. You do this with the Design command.
Use the 'C' option to change the column order and leave the command by pressing
ENTER, as Indicated in the control area. When you next change a value in column
B, the calculation will be correct, since the new mean is now calculated before the deViations. Although this ability to change the order of calculation IS very useful, you should not get into the habit of using It too often - calculating in column order IS much slower than row order
If you save a gnd to a Microdnve file, the current settings of all the Design options are saved with it and they are used whenever you reload the file.
This example will allow you to plan your household expenditure over the yem You can enter your estimated expenditure under a number of headings for each quarter. You are then provided With quarterly totals, your expenditure for the whole year and the averaged monthly cost.
Do not type any numbers Into the table until you have completed it. ThiS allows you to change the form of numeric display, With the Defaults option of the Units command, as descnbed later.
AHOUSEHOLD
BUDGET
12/84 25
Examples
26
9
10
11
13
4
5
6
7
8
12
1
2 I
I
3
I
I
I
I
I
I
I
I
I
I
I
14
15
16
17
18
19
20
21
22 I
23
24
25
26
I
I
I
I
27
28 I
1
I
I
I
I
I
I
I
I
I A
!
I t em
B
I
Mortgate
IRates
I
Rent
!
Gas
J
Electricity
I Water rates
I
TeLephone
I
I Insurance
CLothing
IHire-purchase
I Car tax
!Petrol
I TV licence
!Savings
Quarterly tots
Ic I o lEI
HOUSEHOLD BUDGET
=============
I
740.00
Yearly
F
MonthLy
Payments £3300.00
£275.00
==================
IGI H J IK
I
ESTIMATED EXPENDITURE
I Jan-Mar I Apr-Jun I Jul-Sep ! Oct-Dec I
I
I
I
400.00
150.00
40.00
150.00
I
400.00
I 400.00
450.00
80.00
30.00
35.00
60.00
30.00
150.00
I 150.00
11145.00
I
640.00
I
I 400.00
I
I
I
150.00
I
40.00
I
35.00
I
150.00
I
775.00
I
Figure 55 Home budget example
[01] "HOUSEHOLD BUDGET
[02J rept ("=", len (d1l)
Now we can set up the structure ot the table with its ruled diVisions.
[A4J row=rept("-",width(J+1l [columns A to KJ
[AS] co l="
I "
[rows 5 to 20j
The following commands complete the table structure.
Gri d>Wi dth, 16 FROM b TO b
Grid>Width, 8 FROM d TO j
Grid>Width, 1 FROM a TO a
Grid>Width,1 FROM c TO c
Grid>Width,1 FROM e TO e
Grid>Width, 1 FROM g TO g
Grid>Width,1 FROM i TO i
Grid>Width, 1 FROM k TO k
Echo,CeLL a5,over range c5:c22
Echo,CeLl aS,over range e6:e22
Echo,CelL as,over range g6:g22
Echo,CeLL as,over range i6:i22
Echo,Cell as,over range kS:k22
Echo,Cell a4,over range b7:j7
Echo, Ce l L a4, over range b21: k21
Echo,CeLL a4,over range c23:k23
[A7]
"1-
[F5j "ESTIMATED EXPENDITURE
[B6] "Item
[06] "Jan-Mar
[F61
"Apr-Jun
[H6j
"JuL-Sep
[J6] "Oct-Dec
FOR SERViCE MANUALS
CONTACT:
MAURlTRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844·351694
Ff'0(: 01844 - 352554
12/B4
Exampes
IB81 "Mortgage/Rent
[B91 "Rates
[Bl01 "Gas
IB11] "Electricity
IB12] "Water rates
[B131 "Te I ephone
[B141 "Insurance
[B15] "Clothing
[B16] "Hi re-purchase
IB171 "Car tax
[B18] "Pet ro l
IB19] "TV licence
[B20] "Savi ngs
[B22] "Quarterly tots
[0221 sum(col) lrows 810 20J
[F22] sum(col) Irows 8 to 201
[H22] sum(colJ [rows 8 to 20]
[J22] sum(colJ [rows 8 to 201
[025] "Yearly
[F25] "Mont h l y
[B27] "Payment s
[027] sum(d22:j22J
[F271 year.pay/12
[028] rept("=",len(str(year.paY,0,2J)+1)
[F28] d28
Note that the underlining at the two final figures assumes a monetary format. The length of the underlining is for a number In decimal format. with two deCimal places, plus one
(for the currency symbol).
You also should use a few more commands, to Justify text nght In the range B22:B27
(quarterly tots and payments) and to Justify numbers left over the cells containing the yearly and monthly payments.
You must also modify the numeric display format. Since many of the cells are still empty,
Simply changing the format will have no effect. You must change the default format of the cells to make the effect permanent.
The following command will change the display default to monetary Units over the whole of the budget application.
Units,DefauLts,Monetary,Minus sign
The display of Figure 5.5 uses deCimal format. with two deCimal places, except for the yearly and monthly payments, which are in monetary format The appropnate commands are:
Units,DefauLts,DecimaL,Decimal pLaces 2
Units,Cells,Monetary,Minus sign,Range d27:f27
ThiS last command can use the Cells oplion since the cells concerned already exist.
You can enter values in this table by moving the cursor to the appropriate cell and typing
In the number. The easiest way of moving the cursor is to press F5 (Go to cell) and then use a cell label, such as: apr.gas
The chart displays twelve values, labelled by month. The values are read from twelve cells above the chart. The vertical scale is adjusted automatically to make sure that all values will fit the display. It IS only suited to displaying positive values.
First you should set the column Widths to five In column A, one in column B and three in columns C to N, uSing the Width option of the Grid command.
[C2]
row=O [columns C to N]
AN AUTO·SCALING
BAR CHART
'2'84
Examples
28
A I
B
I C D E F G H I I J K L M N
11
12
13
14
15
9
10
7
8
4
5
6
1
2
3
3 4 3 2 3 4 3 4
SCALED BAR GRAPH
2 3 2
5
4.5
4
3.5
3
2.5
2
1 .5
1
0.5
0
I
***
***
*** *** ***
***
***
***
***
*** *** *** ***
*** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** ***
*** *** ***
*** *** ***
*** *** *** *** *** *** *** *** *** *** *** ***
*** *** *** *** *** *** *** *** *** *** *** ***
--------------------------------------------
Jan Feb Mar Apr May Jun J u l Aug Sep Oct Nov Dec
Figure 5.6
A scaled bar chart
Row two will contain the values to be displayed initially filled with dummy dots.
[F3] "SCALED BAR GRAPH
[P2] intCmax(c2:n2)/5+1)*5
[021 int(min(c2:n2'/5)*5
Cells P2 and 02 contain the maximum and minimum values for the vertical scale of the graph. These cells are chosen so that they do not appear In the final display at the chart. Their initial values are tive and zero respectively.
The max( ) function finds the maximum, or largest, numerical value in the range of cells specified by its argument Similarly, the min( ) function finds the minimum, or smallest, value in the range.
Let us first examine the formula in cell 02. The mini ) function finds the minimum, or smallest, value ,n the specified range which IS then divided by five. The int( ) function then removes the fractional part of the result of the diVision. If, for example, the minimum value is 13, dividing by 5 gives a value 2.6, and int(2.6) is 2. When this IS multiplied by 5 we end up with a value of 10, which is the largest multiple of 5 that IS less than the minimum.
The formula in cell P2 is similar except that it finds the largest value in the range and adds 1 to the number before the final multiplication by 5.
If, as an example, we assume that the maximum value is 21, you can verify that the formula will give a value of 25
- the smallest multiple of 5 that is greater than the maximum.
The two values ,n these cells will therefore always bracket the values ,n the cells from
C2 to N2. Their difference IS always a multiple of five.
The next formula displays the vertical scale of the graph in column A
[A4] col=$q2+(14-rowO)*($p2-$q2)/10 [rows 4 to 14)
The interval between successive numbers in the scale is (P2 -02) /10. Note that we made the difference between the contents of P2 and 02 a multiple of five so that this
Interval always has a simple value.
This Interval is multiplied by a number ( 14-row( ) ) which starts at zero in row fourteen and increases by steps of one to a value of ten in row four The result is added to the smallest value, from cell 02, to produce the number for each cell.
The net result is that the value in cell 02 IS displayed in A14, the value from P2 IS displayed in A4 and the intervening cells contain a set of equally spaced values between these two limits.
[84] co l="I" [rows 4 to 14J
[8141 row=rept("-",widthO+1J [columns 8 to N)
[C15] row=month(colO-2) ( to 3) [columns C to Nj
These draw the axes for the chart and add the horizontal axis labels, uSing the months of the year Note that
we
have used the string slicing operator, similar to that of SuperBtlSIC, to display only the first three characters of each month.
12/84
~.-.
l
Examples
[C4J ;f(index(1,row()) > index(coLO,2) ,"11,"***")
This is the formula that does all the work at producing the bars themselves. It must be copied into every cell in the display area:
Echo,CeLL c4,over range c4:n13
The formula itself needs some explanation. It uses the if( ) function to decide whether to display part of a bar. The if( ) function takes three arguments. The first is an expression which must give a numeric result If this result is non-zero the cell displays the second argument, which may be text or numeric. If, however, the result IS zero the third argument is displayed In the cell. Again this may be text or numeric.
In each cell the formula compares the number In column one of that row (the value labelling the vertical axis) with the number In row two of that column (the value to be displayed in the graph). If the aXIs label IS greater than the display value, the condition is true (it evaluates to 1) and nothing is displayed. If the axis label is less than or equal to the display value, the condition results in a value of zero, and three asterisks are shown
In the cell. The net result is that a bar is drawn to the correct height in each column.
Since a single formula is used for all the cells ,n the display, the cell reference can be neither absolute nor relative. The reference to the display values must change as we move from column to column (i.e. it must be relative along a column) but must always refer to row two as we move down, from row to row We need a form of cell reference which IS relative With respect to columns, but absolute with respect to rows.
Fortunately the index() function can be used to produce thiS effect It takes two parameters, a column number and then a row number, returning the contents of the specified cell. With this we can construct any combination of absolute and relative references. For example:
Function index(5,5) index(col( ),5)
Index(5,row( » index(col( ),row(»
Column Ref.
absolute relative absolute relative
Row Ref.
absolute absolute relative relative
The function index(col( ),2) therefore returns the contents of the cell in row two of the current column, and index(1,row()) returns the contents of the cell in column one (A) of the current row
Try putting different values in cells C2 to N2 and see what effect they have on the display
ThiS example enables you to calculate the monthly payments due on a repayment mortgage. You are asked to type in the amount of the loan, the interest rate, the length of the loan in years and the month of the first payment The required repayments are calculated and displayed, together with a complete repayment table for the whole period of the loan. This table shows you the outstanding sum at the beginning of each month until the loan is repaid.
Several of the calculations in the grid make use of values that are input by use of the askn( ) function.
MORTGAGE
CALCULATOR
In this section we shall produce the part of the grid that accepts your Input and calculates the monthly repayments. When you have typed in the formulae and added a few figures in response to the askn( ) functions, it should look like Figure 5.7
[C1] "MORTGAGE REPAYMENT CALCULATOR
[C2] repH"=", I en (c1 ))
[84] "Loan
[C4] askn ("Amount of loan")
The next three entries request the input at the interest rate. The original input is to a cell (H4) well away from the displayed portion of the grid so that you do not normally see it You type in a percentage value, e.g. you type 12 to mean 12%. The value needed by the rest of the formulae is a fractional value (e.g. 12% must be converted to 0.12) and this is calculated from the input value by the formula in cell C5.
Mortgage Repayment
Calculations
12/84 29
•
~xamples
10
11
8
9
12
6
7
4
5
1
2
3
A B
I
C
MORTGAGE REPAYMENT CALCULATOR
=========================
Loan
Int rate
Term
Figure 5.7 Calculating the repayments.
E
£25,000.00
14.00%
25 Start
REPAYMENTS
Mnth
4
(April)
Annual
Monthly
I
0
£3637.46
£303.12
[H4J askn(
II
Percentage interest rate")
[B5] "Int rate
[C5] h4/100
[B6] "Term
[C6] askn(IIPeriod of Loan in years (maximum 35]")
[E5] "Mnt h
[06J "Start
[E6] askn("Month of first payment [Jan=1, Feb=2, etc]")
[E7] ' ( ' + month(e6) + ")"
In this last formula we enclose the literal text with single quotation marks If the first character had been a double quote, Abacus would have interpreted the follOWing characters as text Input, rather than a formula.
[08] "REPAYMENTS
[09] rept("-", len(dB))
[C10] "Annua L
[0101 mor.Loan*mor.int/(1-(1+mor.intJ
A (-mor.term))
This formula, which calculates the annual repayment, assumes that the interest IS calculated annually and added to the loan before the twelve monthly repayments are made.
[C11] "MonthLy
[011] ann. rep/12
[012] d9
The grid is now sufficiently complete to calculate mortgage repayments. Try uSing the
Xecute command and enter the figures requested, so that you can see it working.
To make the example look better we can change the format of some of the numbers with the Units cOMmand. In this example there is no need to alter the default numeric format since you do not need to make new entries In any grid cell once the application is completed.
Units, CeLLs, Percentage, DecimaL pLaces 2,Range cS
Units,CeLLs,Monetary,Minus sign, Range c4
Units,CeLLs,Monetary,Minus sign,Range d10:d11
In addition it Improves the appearance If we move the numbers in rows 4, 5 and 6 to the left hand side of the cells:
Justify,CeLLs,Numbers,Left,Range c4:e6
Mortgage Repayment
Table
This section describes how you can add a repayment table to the mortgage calculator.
The first part of a repayment table for the values appearing in Figure 5.7
IS illustrated in Figure 5.8.
30 12/84
•
•
•
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
A
I B I C
REPAYMENT TABLE
=============
D E
Yea r 2
----------------------------------------
Apr i L
May
June
July
August 27287.51
September 26984.39
October
November
December
January
February
March
Year
28500.00
28196.88
27893.76
27590.63
26681.27
26378.15
26075.03
25771.90
25468.78
25165.66
28343.30
28040.17
27737.05
27433.93
27130.81
26827.69
26524.57
26221.44
25918.32
25615.20
25312.08
25008.96
2
28164.65
27861 .53
27558.41
27255.29
26952.17
26649.04
26345.92
26042.80
25739.68
25436.56
25133.44
24830.31
3
3
End-af-year baLance 24862.54
24705.84
24527.19
Figure 5,8 The repayment table
If you have a mortgage, type in your own figures Don't spend too much time over the results tor the first few years - they make rather depressing readingl
[C15] "REPAYMENT TABLE
[C16] rept("=".Len(c15))
[B18] "Year
[C18] row=co L() -2 [columns C to AK)
[B19] row=rept("-".widthO+1) [columns B to AKj
[B20] coL=month(rowO-20+$mnth.startl
Irows 20 to 31]
These entries set up the headers for the table: now we must add the formulae that will calculate the values. We start with the first Item which IS the Initial amount due. It is calculated by adding the first year's interest to the amount of the loan.
[C20] mor.loan*(1+mor.int)
Then the rest of the first row IS calculated by subtracting the yearly payment and adding the interest for the current year These values should not be calculated beyond the year in which the loan IS repaid and we allow for this by using the if( ) function. If the year number (given by col( )-2) is greater than the term of the mortgage, zero IS placed
In the cell.
[D20] row=if«col()-2»$mor.term.0.(c20-$ann.rep)*(1+$mor.int))
[columns D to AKI
The remainder
at
the table can be filled with a single formula. We fill the first cell with a formula which Just subtracts the monthly repayment from the amount In the cell above.
Again we use the if( ) function to prevent the calculations extending beyond the year in which the loan is repaid.
[C21] i f « co 10 -2) >$mo'r. te rm. O. c20-$mon. rep)
You can then use the Echo command to copy the formula from cell C21 to the range
C21AK31.
Ec h
0 • eeL L c 21 •
0 verr an9e c 21 : a k31
We can now complete the table by adding a final row to give the outstanding balance at the end of each year It is probably a good idea to add a copy of the year, from row
18, for easy reference.
[B33] row=year.term
[columns B to AK]
[A35] "End-of-year ba Lance
[C35] row=i f « co l 0 -2) >$mor. term. O. c31-$mon. rep)
[columns C to AKI
12/84
Exampes
31
Examples
The entire table, and the end-of-year balances should be set to either monetary format or to decimal format with two places of decimals. The ranges for these changes are C20:AK3l and C35:AK35.
FOURIER ANALYSIS
The French scientist FOUrier showed that a repetitive wave of any shape can be built up from a set of sine or cosine waves of the correct amplitudes and frequencies. The building up of complex waves from pure sine and cosine waves is known as FOUrier synthesis and is employed, for example, in many of the mUSIC syntheslsers in use today.
The opposite process, decomposing a complex wave shape Into a number of pure sine and cosine waves, is known as Fourier analySIS. This example allows you to perform a Fourier analysis of any shape of wave. All you have to do IS type in the height of the wave at sixteen equally spaced intervals and let the formulae in the grid do the rest.
The formulae assume that the wave repeats its shape after the sixteenth value, i.e. that the seventeenth value is the same as the first, the eighteenth is the same as the second, and so on.
Calculating the
Fourier Transform
The Cosine
Components
Since the calculation takes an appreciable time it is worth turning off the auto-calculate, by use of the Design command, before typing in the example.
[Cl] "FOURIER ANALYSIS
[C2] rept("=",len(c1»
[83J "Function:
[Al] "Input
[AB] "Va Lues
The input values are placed in the sixteen cells from 89 to 824 Inclusive.
co L=row 0 -9 [rows 9 to 24]
We shall now set up the headings for the table which will calculate the cosine components of the wave. The result contains the amounts of all cosine-like waves in the Input.
[E3] "Transform:
[E4] "Cosine
[06] "Cycles row=co L0 -5 [columns E to
[08J "Samp I e
TJ
Surprisingly, the entire cosine transformation can be performed by a Single formula. In each row the input value is multiplied by the cosine of an angle (in radians) which is calculated as follows: angle = 2 * pi() * rownumber * colnumber / 16
The row number and column number are the values given in the row labelled 'Cycle' and the column labelled 'Sample' respectively. They each count up from zero to fifteen.
The final divisor is simply the number of points in the input (or output).
[E9] index(2,rowO)*cos(pi O*(rowO-9)*(coLO-5)/S)
Now use the Echo command to copy the contents of cell E9 to the cells in the range from E10 to T24.
The final result is calculated by summing the contents of each column to produce the sixteen output values.
[A26] "Component s
[E26] row=sum(coL) [rows 9 to 24, columns E to TJ
The Sine Components
The calculation of the sine components follows exactly the same pattern as for the cosine ones. The resulting values are the amounts of all sine-like waves in the input.
[X4J "Sine
[X6] row=colO-24 [columns X to AM)
[X9] index(2,rowO)*sin(piO*(rowO-9)*(coLO-24)/S)
[columns X to AMI
32 12/84
Examples
Now Echo the contents of cell X9 over the range from X10 to AM24, to fill In the rest of the table, and Echo the contents of cell C9 to column
V.
from V9 to V24 (this makes a copy of the 'Sample' values).
[X26] row=sum (co I) [rows 9 to 24, columns X to AM)
Any input wave that IS not a pure sine or pure cosine wave will generally produce components in both the sine and cosine transforms. Furthermore, when you calculate the transform of many types of wave, some of the components will turn out to be negative.
In order to obtain results which combine both transforms, and are never negative, we shall make one more calculation. This will add the squares of the sine and COSine components. In the case of a real wave this result shows how much power (energy per second) IS present In the wave at each frequency, irrespective of whether It is in the sine or the cosine components. It is usually called the power spectrum (a spectrum records how much of each frequency IS present). In this case we shall calculate the square root of the power spectrum, to avoid having too large a range of values for the simple graphical display we are uSing.
[C28] "Power
[E28] row=sqr(cos.comp*cos.cornp
+ s;n.comp*s;n.comp)
[columns E to T)
The Power Spectrum
The results of this calculation can be made clearer by presenting them in graphical form.
If you would like high-quality graphs the best way is for you to use the Export command to create files that can be read by Easel, containing the input and output values of the calculation. The following additions to the grid will allow you to see very simple graphical results.
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
*
*
* rna x mi n =
·
·
·
·
·
=
A
*
*
*
·
·
·
· .. -
*
*
*
*
*
*
*
B
10.00
I
C
I
80.00 = max
D
*
*
-10.00
0.00
= min
*
................. *
*
*
*
*
*
*
*
INPUT POWER SPECTRUM
Figure 5.9 Simple graphical output
The output graphs are only half the size of the input graph, since the highest detectable frequency is numerically equal to half the number of input pOints. All the information is present in the first half of the results.
The first part produces a bar graph of the input values.
[A30] "G raph
[A31] "max=
[631] max (co L) [rows 9 to 24]
[A32] "mi n=
[632]min(col) [rows 9 to 24]
[A.33] col=rept(II.I', (func.max-$func.min)
*181 ($func. max-$func . mi n+1
»
+"*" [rows 33 to 48)
Graphical Display of the Fourier Transform
12/84 33
Examples
The second set of entries graphs the power spectrum.
[031] "= max
[C31] max(e28:t28)
[032] "= mi n
[C32] 0
[C33] co l=rept (".", (i ndex (row () -28, 28) -$pow. mi n)
*18/($pow.max-$pow.min+1»+"*" [rows 33 to 40J
The next set of entries graphs the cosine components.
[F31] "= max
[E31J max(e26:t26)
[F32] "= mi n
[E32] min(e26:t26)
[E33] coL=rept(".",(index(row()-28,26)-$cos.min)
*18/($cos.max-$cos.min+1»+"*" [rows 33 to 40J
The final set of enfries gives a graph of the sine components.
[Y31] "= max
[X31] max(x26:am26)
[Y32] "= mi n
[X32] min(x26:am26)
[X33] coL=rept(".", (index(row()-9,26)-$sin.min)
*18/($sin.max-$sin.min+1»+"*" [rows 33 to 40]
Using the
Fourier Transform
As was mentioned earlier you should put the Input values in cells 69 to 624 Inclusive.
You may try any set of values you like, but here are a few suggestions,
[69] coL=10*cos(pi ()*(row()-9)/8)
[69] coL=10*cos(pi ()*(row()-9)/4)
[69] col=10*sin(pi ()*(row()-9)/8)
[69] coL=10*sgn(cos(pi ()*(row()-9)/8))
[69] coL=10 [rows 9 to 241
[rows 9 to 24J
[rows 9 to 24]
[rows 9 to 241
[rows 9 to 241
Remember that, since the auto-calculate is turned off, you must use Xecute to calculate each result.
A further advantage of including lots of labels is that you can move the window to most of the Interesting pOints in the grid by using the goto (F5) facility, followed by a cell reference in its label form,
34 12/84
•
•
•
CHAPTER 6
QL ABACUS
REFERENCE
THE FUNCTION
KEYS
In addition to the standard use of F1, F2 and F3, function keys 4 and 5 are used as follow.;:
F4 move cursor between the two halves of a spilt window
F5 Go to a cell
You can refer to single cells. rows, columns or ranges either by using expliCit letter and number references or by uSing text labels.
A reference to a Single cell consists of two parts, a column and a row reference.
There are 64 columns in the grid and they are labelled from A to rows, numbered from 1 to 255 Typical cell references are
6L.
There are 255
A1 AC13 80200
A range reference IS made up of two cell references, separated by a colon. You must always type In the colon to separate the two parts of the reference. The first cell reference specifies the top leh hand corner of the block and the second one identifies the bottom right hand corner. Examples of range references are:
85:09
AZ23:8A155
CELL REFERENCES
Single Cells
Range References
A part of a row or column can be considered as a range that is only one column wide
(or one row deep). You can therefore use a range reterence to specify part of a row or column, such as:
A3: L3
07:OLL
[cells A to
[cells
L of row 31
7 to 11 of column OJ
There are two range identltiers: row and col. They refer to the cells of the current row or the current column respectively (those that intersect at the cell containing the range identifier).
Each time you use one of them In a formula you Will be asked to specify the exact range of cells within the row or column. Abacus Will suggest reasonable starting and ending points for the range and you can either accept this chOice or change it.
There are two ways in which you can use range identifiers. You can fill the current row or column by use of either row = (formula) or col = (formula)
You can also use them as the argument for any function that requires a range, for example, count(row). You can, of course, only use them in this way when you Just want to refer to the cells of a single row or column.
You can mix the two methods freely, for example, col = ave(row)
Each occurrence In a formula Will result in Abacus asking you for a particular range.
Rowand Column
References
Range Identifiers
Abacus normally assumes that all cell references are relative, i.e., that the important thing is the difference In position between the cell containing the reference and the cell to which you refer When you copy such a reference into another cell, the references are modified to keep this relative difference. For example, imagine that a formula In cell 62 contains a reference to cell A1 (one column to the leh and one row above).
If the formula in cell 62 is copied into cell 04 it will, in this new location, refer to cell C3 (again one column to the leh and one row above).
This is illustrated In Figure 6.1. A formula in cell X contains a reference to the lightly shaded cell. If this formula is copied to cell Y it then refers to the heavily shaded cell. The two cells in each pair have the same relative positions.
Relative and Absolute
Cell References
35 12/84
Reference
36
!
I
B[JCDI~IIBDCIDEII
' I .
I
I,---------~
, I
I
U rc~~==
Figure 6.1 Relative cell references
.
===="J
II
Figure 62 Absolute cell references
Suppose we put the tormula A1'2 into cell A2, and then use the Echo command to copy the formula into cells in the range 62:02. Examining the cells of row 2 will show that they have the following contents:
Cell: A2
Contents: A1'2
62
61'2
C2
C1'2
02
01'2
E2
E1'2
F2
F1'2
02
01'2
You can make any cell reterence absolute by pretaclng It with a $ sign. Such a reference will not be modified when the formula is copied to other cells. For example, if a reference in cell 62 was to $A1, any copy of the formula will also contain the reference $At You can also use labels to give an absolute cell reference (e.g. $march.costs).
Figure 6.2 shows the effect of an absolute cell reference. A formula in cell X contains an absolute reference to the shaded cell. A copy of the formula in cell Y refers to the same cell.
Let us try the prevIous example, but this time we shall use an absolute reference. Put the formula $A1'2 in cell A2 and Echo It to cells 62 to 02 inclusive. You will then find that the cells contain the following:
Cell A2
Contents: $A1'2
62
$A1'2
C2
$A1'2
02
$A1'2
E2
$A1'2
F2
$A1'2
02
$A1'2
See also the index( ) function.
Cell ranges, in any form (including the range identifiers, row and col) are always relative.
LABELS
Rowand Column
Labels
A label is a cell containing text The text must only Include letters and digits. Any such cell can be used to identify a row or column in the grid. You can also use labels to refer to a single cell, but you may not use them to replace a range reference or to refer to a whole block of cells.
Whenever you refer to a label in an expression or formula, Abacus uses a set of rules to determine whether it refers to a row, a column or a cell. The rules for rows and columns are:
2
The row and column Intersecting at the label are scanned (to the right and below) to find the numeric entry.
a) If only a row entry IS found, the label refers to the row, starting at the found entry.
b) If only a column entry is found, the label refers to the column, starting at the found entry.
c) If entries are found in both the row and the column, the entry closest to the labelled cell is used to make the choice.
If no decision can be made under 1), but the label is used on the left hand side of an expression, it will be given the type of any label(s) used on the right hand side. For example, if "Costs" is a row label:
12/84
Reference
•
•
•
Sales
=
Costs
*
0.5
then "Sales" will also be a row label.
If both of these rules fall, you are told that Abacus cannot decide the meaning of the label.
BDDDB
CK:J~
~
APPLES
- - - -
FRUIT
!
•
I L l
11,====='1
Figure 6,3 Labelling a cell
You need to use two labels to identify a single cell and you make the cell reference by giving both labels, separated by a full stop. For example, if you have two labels '~ruit" and "apples': you can refer to a cell as fruit.apples
(or by any unique abbreviation, such as frap). The order of the two labels is unimportant so you could also use apples.fruit, ap.fr and so on.
Such a reference refers to the cell at the intersection of the row s and columns containing the labels but, as Figure 6.3 shows, there are two such cells (labelled X and Y).
The cell that is selected is the one in the right-most column and the lower of the two rows. In the previous example, the cell labelled Y will be selected. You should, therefore, always place labels above or to the left of the cells to which they refer
Cell Labels
FORMULAE
A formula is any allowed combination of functions, cell references, labels and arithmetic operators. Examples are:
A1 *63 month(colO-1l
; f ( ins t r (86, II; s") , 1 ,0) rept("=/I, Len(G23»+":1I
Each new formula, in addition to being used in one or more grid cells, is stored separately in a list of master formulae. Each master formula may therefore appear in one cell or
,n many. When you fill cells by use of the row and column fill operations, or by uSing the Copy or Echo commands, all the filled cells share a Single master formula. If a master formula contains relative cell references they are adjusted, in each cell using the formula, to be valid for that particular location. The formulae may therefore appear superficially different but are all based on the one master formula.
You can modify all copies of the formula by editing only one of the copies. If you use the Amend command to change any copy of a master formula, the master is also modified and all copies are changed Simultaneously.
Master Formulae
This section contains a full description of all the commands available In Abacus.
THE COMMANDS
AMEND (A)
This command allows you to change the contents of a cell. The contents of the cell containing the cursor are copied to the input line, ready for editing with the line editor described in the IntrOduction to the OL Programs. When you press ENTER the edited version replaces the original cell contents.
Reference
38
COpy
(C)
You use this command to copy a range of cells from one area of the grid to a similar range in another place. Abacus first asks you to give the range reference of the cells to be copied, e.g. A1:B3, and you should fhen press ENTER. Abacus next asks you to specify the cell reference for the top left hand corner of the area to which the range of cells IS to be copied. When you then press ENTER the range will be copied to the new location.
DESIGN (D)
You use the Design command to modify a number of the features of Abacus that affect the appearance of the whole grid, such as whether the display should be set for a domestic television or a monitor The choices remain In force until you modify them again, or until you leave Abacus. When you save an application these choices (except for the
Display option) are saved with it so that they are used every time you load the application.
Changing the defaults, however, does not affect Abacus itself. You must set them to the values you want each time you load Abacus from SuperBASIC
When you are: have finished you return to the main display by pressing ENTER. The options
Auto-calculate on input used to specify auto-calculate or no auto-calculate Each time you press the auto-calculate option switches between YES and NO
A key the
If you choose YES, the whole spreadsheet will be recalculated after each entry Selecting
NO, however means that the spreadsheet will only be recalculated when you use the
Xecute command. The Initial value is YES.
Blank if zero
SWitches between two ways of treating zero values in the grid. The original option is to display the value zero in the appropriate format for that cell. You may select the alternative, which IS to display a blank cell If its contents evaluate to zero.
Note that in thiS option, a blank cell will only be shown if the value is truly zero. Suppose you have selected deCimal display format, with two deCimal places, and the value in such a cell IS 0.003. The cell will show 0.00, rather than being blank, since the true value is non-zero.
Calculation order selects between calculating the spreadsheet In ROW or COLumn order. The option changes each time you press the C key (as for auto-calculate). The specified order will be used for both auto-calculate and the Xecute command. The Initial value is for row order
Display 80,60,40 columns selects the number of characters displayed across the screen. You are asked to type in 8, 6 or 4 (followed by ENTER) to select an 80,64 or 40 character display. The Initial value IS either 80 or 40, depending on whether you select the Monitor or Television option when you load Abacus from its Mlcrodrive cartridge.
Form feed between pages selects whether or not a form-feed is issued at the end of each page of printed output in the same way as for auto-calculate. The initial value IS YES.
Gaps between lines on printer sets the line spacing on printed output by specifying the number of gaps between the lines of text You are asked to type In 0,1 or 2 (no ENTER is necessary). You can set ordinary double-spaced printer output for example, by specifying one gap between each line. The initial value IS zero.
Lines specifies how many lines on a page of printed output You should type In a number followed by ENTER. The initial value IS 66 and the maximum is 255.
Monetary specifies the currency sign to be used in the display of monetary values. You should type in the Single character that you want (no ENTER is necessary). The initial value is the pound sign.
Printer
sets the number of characters per line of printed output You should type in a number,
followed by ENTER. The initial value is 80 and the maximum IS 255.
12184
Reference
The Echo command makes a copy of the data or formula In a particular cell to all the cells in a specitied range.
You are given the option of specifying the cell reterence ot the cell to be copied, or pressing ENTER to copy the current cell. You then should type In the range over which the cell contents are to be copied, tollowed by ENTER.
This command allows you to modlty Abacus files, previously saved on a Mlcrodrive cartridge. The options ask you to type In the names of files. Each time you are asked tor a file name you can press? for a list of all files on Microdrive 2.
You are offered the following options:
Backup used to make a backup copy of an Abacus file. You are asked for the name of the file to be copied. You are strongly recommended to make copies of all your files, to protect yourself against accidental loss of, or damage to, the cartridge.
Delete deletes a named file from a Microdrive cartridge. Note that this command is NOT reversible and should therefore be used with GREAT CARE.
Export exports a named file. The file is saved in a form suitable for being Imported by Archive,
Easel or Ouill.
Abacus first asks you whether you want to export to Quill, Archive or Easel. Accept the suggestion of export to Quill by pressing ENTER, or select export to Archive or Easel by pressing either the A key or the E key
In all cases you are then asked to type in the range reference for the section of the grid that you want to export, ending your Input by pressing ENTER.
It you have chosen to export to Archive or Easel you can export the file by rows or by columns. Abacus asks you to press ENTER to accept the suggestion of exporting by rows, or to press the C key to choose export by columns. You are not given this option if you choose to export to Quill. In thiS case the data IS always exported by rows.
Abacus tinally asks you to type in a name for the exported file If you do not specify a file name extension Abacus will supply an extension of _expo
Format formats the cartridge in Microdrlve 2. Abacus gives you the Mlcrodrive specifier, mdv2_ and you must type in a volume name for the cartridge.
Make sure that the cartridge in Microdrive 2 contains no files thaf you want to keep ~
ALL the contents ot the cartridge are erased.
Import imports a named fite. It allows Abacus to read files exported from Archive or Easel. There is a full description ot Import In the Information seelion in the User Guide.
You may Import a file in either row or column order, and are asked to select which. You are also asked for the cell reference of the top left hand corner of the area of the grid into which the data IS to be imported.
If you do not specify a file name extension Abacus will assume an extension of _expo
The Grid command is used to make changes which affect the entire spreadsheet.
tt allows you to insert or delete an entICe row or column, or to change the number of characters displayed in one or more columns.
The options are:
Insert allows you to insert empty rows or columns into the grid. You are first asked if you want to insert rows (press ENTER) or columns (press C).
You are then asked to give the number of rows or columns to insert, and a row (or column) reference. When you then press
ENTER empty rows or columns are inserted before the one specified. The last rows
(or columns) will be lost trom the grid. If, for example, you Insert three rows, the last three rows of the old grid will be lost.
You will not be able to recover any of the data that these lost rows contain, unless you type it in again.
ECHO (E)
FILES (F)
GRID (G)
12/84
39
Reference
Delete allows you to delete one or more rows or columns from the gnd. You are first asked if you want to delete rows (press ENTER) or columns (press C).
You are then asked to give the reference of the starting row (or column) of the region you want to delete, followed by ENTER. You are then asked for the row (or column) reference of the end of the region.
When you then press ENTER the selected region is deleted and the following rows (or columns) close up to fill the gap. Empty rows (or columns) will be Inserted at the bottom
(or at the extreme nght) of the grid.
In both of these options all formulae In the rows or columns that are moved will be adjusted to correct them for their new positions
Width allows you to change the width (number of characters) of one or more columns. You are first asked to specify the number of characters in a column, and then to specify the starting and ending columns over which you wish the change to take effect.
JUSTIFY (J)
The Justify command IS used to modify the positioning of text and numbers in a range of cells.
It has two main options; to modify existing cells, or to set the default Justification that Abacus will use when you put data in a cell which is currently empty. You should press ENTER to select the Cells option, or the D key to select the Defaults option.
You are then asked to specify whether you want to modify the Justification of text (by pressing ENTER) or of numbers (by pressing the N key). In either case you can then select left (ENTER), right (R) or centre (C) Justification
In the case of the Cells option you are finally asked to give the range over which the change IS to act.
You do not have to give a range in the Defaults option. The new default will apply to all newly created cells, at any point in the grid, until you make a further change In the default justification.
Some of the different types of justification, together with the original settings (text justified left and numbers Justified right) are shown in Figure 6.4.
HELP CURSOR r,;;P '",e;:os S=F
1~~
I press ..- n---->
PROMPTS GOTO CELL press F2 press F5
DATA & FORMULA enter directly
& press ENTER
TEXT type" fa llowed by text & ENT.
COMMANDS press F3
ESCAPE press ESC
~~"::==r=~=r==;'!====r=~~~~
LEFT 12340
DEFAULT
RIGHT 12340
12340
(text left, numbers right)
40
GItJ't'O';
'~'SI,OAl
:05 MEMORV 23K
EMPTY
Figure 6.4 Justification
LOAD
(L)
This is used to load a file from the Microdrive. You are first asked to specify the file name; pressing the? key at this point gives you a list the files on Microdrive 2.
12184
Reference
•
•
•
If you do not Include an extension in the file name you type In, Abacus will assume an extension of _aba.
This command IS used fo combine, or consolidate, data from a previously saved file wlfh the data In the current grid. You are first asked for the name of the file to be merged from the MIcrodnve cartridge and will then have to indicate whether the data In this file is to be added to (press ENTER) or subtracted from (press S) the data In the current grid.
Whenever a cell (in the file) containing a number or a formula matches a corresponding data cell in the grid, the value from the file will be added to or subtracted from the grid data. The contents of any other cells are not affected The command will not have any effect on grid cells containing text. which are therefore protected against alteration.
The resulting grid contains purely numeric values ,n each cell that have been affected by the merge. The formulae that produced these values in the onglnal grid cells will be destroyed. These formulae would not have any meaning in the consolidated gnd.
This command offers a fast and easy method of combining the data in two similar models.
It IS, of course, essential that you have laid out the two gnds in exactly the same way, uSing the same cell locations, for the results of the command to make sense.
You use this command to sort the rows of the gnd into ascending order, based on the contents of one particular column
You are first asked to specify the column on which the sorting is to be based. You are then asked for the first and last rows to be sorted. The exact ordering sequence that
Is used IS:
Empty cells
Numenc cells, in ascending numeric order
Text cells in alphabetic order
Only use the Order command on rows or columns which contain data. It IS likely to invalidate any formulae present in the affected portion of the grid, as they are not adjusted for their new locations.
This command is used to send a selected portion of the grid to a printer or to a Mlcrodrive file. You are first asked whether you want the pnnted grid to show the values or the formulae in each cell. Press ENTER to show the values, or press the F key to show the formulae. Abacus next asks you to specify the range of cells which you want pnnted.
Then you are asked iJ you want the grid border to be Included (press ENTER) or not
(press the N key). Following this you should specify whether the output should be sent to the printer (press ENTER) or to a MIcrodrive file (press the F key). If you choose to send the output to a file, you are also asked to type in a file name (ending with ENTER).
The selected portion of the grid Will be sent to the chosen destination. You can stop the pnntlng at any time by pressing ESC.
If you have asked for a display of the formulae, Abacus will first print a numbered list of all the formulae used In the gnd. It then prints the grid itself. The formula number is shown in any cell that contains a formula.
If you do not, in the case of the option to print to a file, specify an extension when you type In the file name, Abacus Will assume an extension of _lis.
You use this command to leave Abacus when you have finished using it.
When you leave Abacus the current gnd contents are lost. You are asked to confirm your request so that you have the chance to change your mind. You can cancel the command and return to your spreadsheet by pressing ESC. If you press ENTER you will confirm your Wish to leave Abacus and return to SuperBASIC
This command is used to rub out. or delete, tne contents of one or more cells in the grid. When you use this command you will be asked to specify a range of cells. All the cells in that range will be cleared.
This is used to save a file on a Mlerodnve. You are first asked to specify the file name; pressing the? key at this point gives you a list of the files on Microdnve 2.
If you do not Include an extension when you type in the file name, Abacus will assume
an extension of _aba.
The Units command is used to change the way that numbers are displayed within a cell, or group of cells. It does not affect the values of the numbers in any way.
MERGE
ORDER
(P)
OUIT (0)
RUBOUT
SAVE (S)
(M)
(0)
UNITS (U)
(R)
Reference
'flINDOW 0N)
You are first asked to select whether you want the command to affect eXisting cells Uust press ENTER) or to set the default format that Abacus wl[1 use for all subsequently created cells (press the D key).
In either case you are then asked to choose the dlsp[ay format trom the following list:
Decimal
Numbers are displayed in a fixed pOint deCimal notation. that IS, all numbers are shown in fhe same way, with a fixed number of deClma[ places. Numbers which actually contain more decimal places than are displayed will be rounded up or down as necessary. You are asked to type In the number ot deCimal places you require. [t wll[ not accept a value greater than 14.
If you want the cell values themselves to be rounded, rather than just being displayed
In rounded form, you must do the rounding yourselt For example, to round a value to two deCimal places:
1.
2
3.
4.
multiply by 100 (1000 tor rounding to 3 decimal places, and so on) add 05 discard the decimal fraction with the Int() function divide by 100 (or 1000)
The tollowlng formula wll[ round the value ,n cell C3 to 2 deCimal places' int(c3100+05)/100
Integer
Numbers are shown as Integers, or whole numbers, as for the int( ) funellon. You are given the option for negative values to be enclosed in brackets, rather than with a leading minus sign. Press the B key for bracketed negative values, or enter for a leading minus sign.
Use fhe int( ) function if you want the cell values to be converted to integers, rather than just being displayed in integer format:
Exponent numbers are displayed In exponential, or sCientific notation The option asks you to type in the number of decimal places you want to be shown. It will not accept a value greater than 14. Again the displayed number IS rounded as necessary, to the number of deCimal places that you select:
Percent this displays numbers as percentages so that, for example, the value 0.55 is displayed as 55%. The option asks you to type In the number of decimal places you want to be shown. It will not accept a value greater than 14.
General thiS is a general numeric format In which any of the prevIous formats is chosen, depending on the value of the number, to make best use of the space available in the cell.
Monetary numbers are displayed in fixed-point decimal format, with two deCimal places and a leading currency symbol. You are given the option for negative values to be enclosed in brackets, rather than With a leading minus sign. Press the B key for bracketed negative values, or ENTER for a leading minus sign.
In the case of the Cells option Abacus asks you, at the end of any of the above choices, to specify the range over which the change is to act: You can type in any form of cell or range reference (including labels or range identifiers). Press ENTER to mark the end of the reference.
Abacus does not ask you fo specify a range It you selected the Defaults option. In thiS case the selected format will be used for all new cells, as they are created.
You use thiS command to control whether the display IS a single window or is split into two windows which can be used to show two separate portions of the grid.
You are first asked to choose between a vertical
M split, a honzontal (H) split, or to JOIn
(J) a split display back Into a single window. If the window IS initially split and you want to change from, say, a horizontal to a vertical split you must first join the two windows
before making the new split
If you choose to split the window then the split Will occur at the column or row containing the cursor. You should therefore position the cursor at the point where you want the split
12/81
Reference
•
•
• to occur before making the spilt Whole columns will always be displayed Each window in a vertical spilt will never be less than ten characters wide.
You then are given a further choice as to whether the two windows should move fogether
(T) or separately (S). If you specify the T option, this means that any change In the position of one window - In the direction parallel to the split ~ will cause a corresponding change in the position of the other Movements at rrght angles to the split are not related In this way. The S option allows the two windows to move around the surface of the grrd
Independently.
This command is used to force a recalculation of all formulae appearrng in the grrd.
A recalculation IS normally performed automatically when you make any new entry in the grid. You will only need to use this command if you have switched off the aufomatic recalculation option or if you want to activate any askn( ) or asks( ) functions stored in the cells of the grrd.
This command clears the entire contents of the grid and returns you to the beginning ot Abacus for a fresh start. Since this command IS drastic (and irreversible) in its action, you will be asked to confirm your request If you press ESC you will return to the command menu without any deletion taking place. You should press ENTER to confirm your wish to clear the grrd.
XECUTE
ZAP (2)
(X)
FUNCTIONS
Think of a function as a kind of recipe which converts a number of values, known as the function's
arguments
Into a different value, which is said to be the value that is returned by the function. In Abacus this IS the value which would be shown In a cell containing the function.
The functions provided by Abacus may take three, two, one or no arguments which are placed In brackets after its name. You
must
not leave a space between the name and the opening bracket. but spaces are allowed between Items within the brackets.
If a function takes more than one argument. then they are separated by commas. All functions
must
be followed by the brackets, even if they take no arguments. The presence of the brackets is a useful reminder that you are referrrng to a function.
In the descriptions of the functions:
n
is either a numeric expression or a reference to a cell displaying a
numerrc
value, text Is either a text expression or a reference to a cell display'lng a text value,
range
is a grrd range reference.
A numeric expression IS either a number or an expression which gives a numerrC result
A text expression is either a text strrng (enclosed in quotes) or an expression which gives a text result
The following functions are provided.
ASS(n)
Returns the absolute value (that is, the value Ignorrng any minus sign) of the argument
For example, abs(3) returns 3 and abs( -7) returns 7.
ASKN(text)
This function IS used for the input of numeric data. It displays the given text (which may be up to 40 characters in length) as a prompt in the input line, followed by a
?: and walts for a reply to be typed in. The reply is shown in the cell containing the function.
Input will only be requested when you first put the function Into a cell, and when you recalculate the grid by use of the Xecute command. It is not asked for during an autocalculate after each grrd entry
ASKT(text)
This function is used for the Input of text strings. It works ,n exactly the same way as askn(), except that it expects you to type in text Instead of a number
ATN(n)
Returns the angle,in radians, whose tangent is n.
12/84
43
Reference
44
N~~
Returns the average of the numeric values contained in all the cells in the specified range.
Empty cells and cells containing text are Ignored In the calculation of the average.
If there are no numeric cells in the range it will return a value of zero.
CHR(n)
This function returns the ASCII character whose code is n. A character with an ASCII code less than 32 has no effect on the screen, but IS sent to the printer (when you print the portion of the grid containing It) if preceded by an ASCII null For example,
Chr(O)+chr(13) passes the ASCII character for a carriage return to a printe( when the cell containing it is printed.
You can show an i'\ on the screen With chr(65).
CODE(text)
This returns the ASCII value of the first character found in the speCified text
COL( )
Returns the number of the current column.
COS(n)
Returns the cosine of the given (radian) angle.
COUNT(range)
Returns the number of non-empty cells in the specified range. Both text and numeric cells are included in the count.
DATE(n)
Returns today's date as a text string In one of three forms: n date string o
"YYYY/MM/DD"
1 "DD/MMIYYYY"
2 "MM/DDNYYY"
You must first have set the system clock, as described in the SuperBASIC keyword gUide.
DAYS(text)
Returns a number of days, from the first of January 1583, to a date given by a text expression of the form YYYY/MM/DD: The conversion assumes the Gregorian (modern) calendar is being used. The formula is therefore only valid for dates after 1582.
DEG(n)
Takes an angle, measured in radians, and converts It to the same angle In degrees.
EXP(n)
Returns the value of e (approximately 2.718) raised to the power will be in error if
n.
The returned value
n
lies outside the range from -87 to +88, Since the result Will then exceed the numeric range at Abacus.
IF(expression ,true,false)
The value at the expression is calculated and used to determine which of the following two arguments should be returned.
expression: ~ n true: ~ n false: ~ n
I
I text text
If the expression evaluates to 0 it is considered to be false and the 1alse' argument is returned. Any non-zero value for the expression is interpreted as being true and causes the true' argument to be returned. The true' and 1alse' arguments may be either text or numeric in nature. Thus all the following examples are valid uses of the function; if (A1 =B1, "equa L", "not equa lll)
;f(A1,1,O)
You can also mix a text and a numeric argument as in the following example. Try thiS one out if you are not sure how if( ) works.
[A1] 1
IB1] 0
[C1] ;f(A1 or B1,"either",O)
12184
•
•
•
•
You should see the word 'either' appeanngln cell C1 since the frrst parameter of if( ) returns a non-zero (true) value if either cell A1 or cell 81 contains a non-zero value. If you change the contents of cell A1 to be zero then you will see a zero displayed in cell Cl
INDEX(co/umn,row) co/umn:~ row:= n n
Returns the contents of the cell at the Intersection of the specified column and row.
INSTR(main,sub) main:= text sub:= text
This finds the first occurrence of sub within main and returns the position of the first character of sub In main. It will return a value of zero If no match IS found. The match is case-dependent.
i nst r <"January", "Jan") instr("January","an") instr(IIJanuary","AN")
[returns 1)
[returns 2]
[returns OJ
INT(n)
Returns the integer value of the number by truncafing at the decimal pOint. The truncation always makes the number less positive. Thus; i nt C3.
7) returns 3
; nt< -4.8) returns -4
IRR(range,perioa) period:= n
Calculates the Internal Rate of Return for the numeric data in the specllied range, which may be either a row or a column.
The data in the range represents a cash flow for each of a series of periods, separated by
n
months. Negative values represent cash outlays and pOSitive values represent cash returns.
IRR(range,perioa) penod:~ n
Calculates the Internal Rate of Return for the numeric data In the specified range, which may be either a row or a column.
The data in the range represents a cash flow for each of a series of periods, separated by
n
months. Negative values represent cash outlays and posllrve values represent cash returns.
The function returns the rate of interest necessary so that investment of your outlay would match the proposed returns.
For example, suppose you are offered a return of twenty thousand pounds at the end of each of the next seven years, in return for an initial outlay of one hundred thousand pounds. Is this a good dear
[A1] "flow
[A2] -100000
[A3] co 1=20000 [rows 3 to 9)
We can refer to the range of the data by the label 110w' and the interval between successive periods is twelve months:
[C2] ;rr(fLow,12) [rows 2 to 9)
The completed grid should look like Figure 6.5, showing that the Internal rate of return is 9.1%. If you can invest your hundred thousand pounds at a higher rate of interest you should do so, and forget the deal.
Nofe that the first Item in the range is counted as period zero, the next is period one, and so on. The function assumes that each amount is payable in full at the end of the relevant period.
12/84
Reference
45
46
Reference
A
3
4
1
2
5
6
7
8
9 fLow
-100000.00
20000.00
20000.00
20000.00
20000.00
20000.00
20000.00
20000.00
Figure 6.5 Internal rate of return
B
c
9.10
LEN(text)
Returns the number of characters In the specified text
LN(n)
Returns the natural, or base e, logarithm of
n.
An error results If
n
IS negative or zero, since logarithms are not defined in this range
LOOKUP(range,oltset, value) altset:~ n value:~ n
This function Implements a look-up table in the grid. Two tables of values are assumed to be present The first table occupies the specified range (which can be In a row or a column). The second table runs parallel to the first in the following row or column.
For example, if the first table IS In column G, from G10 to G25, the second will be assumed to be from H10 to H25. Every entry In the first table should have a corresponding entry
In the second. The first table IS searched for the largest value that is less than or equal to the specified value. The function returns the corresponding entry from the second table. Note that It IS assumed, for the correct operation of thiS function, that both tables contain numeric values, and that those in the first table are arranged In ascending order
The first value in the first table is a dummy. It must be less than the second value, which
IS the lower limit for the table lookup process. It is otherwise ignored. The first value in the second table is the value that IS returned if lookup( ) is called with any number less than the lower limit
MAX(range)
Returns the largest numeric value found in the cells In the specified range. If there are no numeriC cells in the range the function will return the smallest possible number
(1.7
-E +38).
MIN(range)
Returns the smallest numeric value found in the cells within the speCified range If there are no numeric cells ,n the range the function will return the largest possible number
(-17 E+38).
MONTH(n)
Returns, as text, the name of month n.
For example month(3) returns the text "March".
If an argument larger than 12 is used, it is replaced by the remainder after diVIsion by
12 so that, for example, month(13) and month(1) will both give the result ~anuary'.
N PV(range ,percent,penad) percent:~ periad:~ n n
Calculates the Net Present Value for the cash flow data in the specified range. Percent is the annual interest rate (14 represents a 14% rate). The data is assumed to refer to a series of periods, separated by equal intervals of period months.
The net present value is the amount of money reqUired now to produce a given future cash flow, assuming an Interest rate. For example suppose you are given the opportunity to buy, for a Single payment of seventy thousand pounds, a ten-year lease on a shop which is currently producing a yearly net income of ten thousand pounds. You expect the income to increase by 10% per year If you did not buy the shop your seventy thousand pounds would earn 14% interest What should you do?
12/84
•
•
•
•
•
•
•
You should calculate the net present value of the income and compare If with the sum you are asked to pay
[A1] "flow
[A2] 0
[A3] 10000
[M] co l=a3*1.1
[rows 4 to 12]
[A14] npv(flow.14,12) [rows 2 to 12J
The result is shown in Figure 6.6
B
10
11
8
9
12
13
14
3
4
1
2
5
6
7 f low
A
0.00
10000.00
11000.00
12100.00
13310.00
14641.00
16105.10
17715.61
19487.17
21435.89
23579.48
75088.51
Figure 6,6 Net present val,ue
The net present value (in cell A14) of the cash flow from the shop is more than the asking price, so you should go ahead.
The first item in the list is for period zero, the second is for period one, and so on. This is consistent with the assumption, made by the function, that the returns are received at the end of each period. You therefore have to wait for one period before you obtain any return on your investment. In a real situation of this type you would probably work on a monthly basis, rather than on twelve month periods.
PI()
Returns the value of the mathematical constant
7t.
RAD(n)
Takes an angle, measured in degrees, and converts it to the same angle in radians.
REPT(text,n)
This function will fill the current cell with
For example,
n
copies of the first character of the given text.
.
rept ("*",5) [will put five asterisks in the current cellJ rept("abc".3) [makes three repetilions of '\3"J.
ROW()
Returns the number of the current row.
SGN(n)
Returns +1, -1, or 0, depending on whether the argument is positive, negative or zero
SIN(n)
Returns the value of the sine of the specified (radian) angle.
STR(n,type,dp)
num:= n
Iype:= n dp:= n
Converts a number.
num,
to the equivalent text string. Type indicates the form of the converted string as follows; o decimal (floating point)
1 exponential, or scientific, notation
2 integer.
~ general format
12/84
Reference
47
Reference
48
The third parameter, dp, specifies the number of tigures after the decimal point in the converted string. It should always be included, although its value is ignored tor Integer, general and monetary formats.
SQR(n)
Returns the square root of the nurnber n, which must not be negative.
SUM(range)
Note that the value returned by the function IS the surn of the exact values in the relevant cells It does not take Into account any rounding that may result tram use of the Units command. For exarnple, If two cells contain the values 3.44 and 9.73, the sum( )function
Will add them to give 13.17. If you then select a display In decimal format with one decimal place, the two nurnbers will be rounded to 3.4 and 9.7. The sum, whose value will still be 13.17, will be rounded to an apparently Inaccurate 13.2. See the units cornmand.
TAN(n)
Returns the tangent of the specified (radian) angle.
TIME( )
Returns, as text, the time of day In the format "HH:MM:SS': You must first have set the systern clock, as desrlbed in the SuperBASIC keyword guide.
VAL(text)
Val converts the text to its equivalent nurneric value. It will only convert text composed of valid numeric characters and the conversion Will stop at the first character that cannot be interpreted as a digit. For example, val("2.2ABC") will return the value 2.2, and val('~BC") will return 00
WIDTH( )
Returns the Width, in character spaces, of the current colurnn. Note that there IS one space separating adjacent columns.
ERRORS
Grid Errors
Any syntax error in a formula - such as supplying the wrong number of arguments for a function, or mis-matched brackets - will be reported at the time you type in the formula. You are told the nature of the error and the formula is left in the input line. You can then examine it. and then correct it with the line editor.
The possible error messages are listed below.
Message
Missing closing quotes in a string
Badly formed numeric constant
Number too large
Illegal character
All names must refer to columns
All names must refer to rows
Name references may only be relative
(see the section on Cell References, earlier in this chapter)
Badly formed range reference
Badly formed name reference
Name is not a row or column
First name reference undefined
Second name reference undefined
(the text does not appear in the grid, above and to the left of thiS cell)
Function requires a range reference
Illegal range
Syntax error
Mismatched brackets
Type mismatch
Example
"abc"
+ "def
1 . 5e
1.5e99
(rnisslng number after
el
12
5 (underscore instead of minus) a1 : c3.
(see Chapter 3) i rr(1 ,2,3) (see description of irr( ))
1 +
"abc"
12/84
,.
"t.
'.-
Reference
Wrong number of fundion arguments
String bigger than 255 characters
Division by zero
Illegal function arguments
String subscript out of range
(either subscript less than zero or greater than 255, or first subscript greater than length of text) sqd1,2) rept("*",256) sqr(-1)
Reterence out ot range
(to a cell outside the grid)
Reference to an error cell
(the formula refers to a cell containing a formula which produces one ot the errors described below)
Out of memory, use RUBOUT to make more room
Other errors, such as a formula which adds the contents of two other cells, one containing a numeric value and the other containing a text value, will not be detected until the result of the formula is calculated - after the formula has been placed in the grid.
If a formula contains a reference to an empty cell, Abacus will assume that the cell has a numeric value of zero. This may well cause an error when the formula is calculated.
If Abacus detects an error when a formula is calculated it gives a brief error message in the relevant cell. You can then move the cursor to the cell to examine the formula and find out what is wrong.
The possible errors are:
# #TYPE - the formula contains a reference to a cell containing Information of the wrong type, I.e. numeric instead of text, or vice versa.
# # LONG - the formula contains a reference to a text string that is more than 255 characters long.
# #ZERO - The formula is attempting to divide something by zero.
# #ARG - The formula contains a function called with a non-valid value for one or more of its arguments e.g. In(-5).
# #SUB - The formula uses a string slicing operator with an error In one or more of its subscripts.
# # REF - The formula contains a reference to a cell which IS outside the grid. The formula in such a cell will show the word 'ERROR' for each cell reference that is not valid.
# # ERR - The formula contains a reference to a cell which contains an error. You can ignore these messages since they will disappear when the original error, in the cell to which the formula refers, is corrected.
The following error messages will only appear if an error occurs while you are uSing a file-related command e.g. Load or Files.
File does not exist the file name you gave was not found on the cartridge in Microdrive 2.
File 1/0 incomplete the loading or saving of a file has started successfully but has failed at a later stage - this may mean that the data in the file has been corrupted, or that the cartridge has been damaged.
Unable to open file the file can not be opened - for one of the reasons given for the previous error.
File Errors
12/84
49
Reference
Wrong file type the file name extension is not the one that Abacus was expecting - e.g. attempting to load an export file instead of importing it
Illegal file name e.g. "3test" file names must start with an alphabetic character and may not be more than 8 characters.
Illegal import file format thiS is only likely to occur if you attempt to import a file not created with an export command.
50
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
12/84
©1984 PSION LIMITED by DICk de Grandis-Harrison (Psion Limited)
QL Archive
OL Archive is a database program which enables you to create filing systems for any type of information you choose. You are free to decide how this information will be stored and retrieved.
You will quickly discover how Archive can be used for creating simple card index systems such as address lists or customer records. Once you have mastered the creation of stralghrtorward systems such as these, you may wish to develop more complex multi-fHe relational systems where information is shared between, for example, purchase and stock control records.
Information may be presented using the screen layout that Archive provides, or you may deSign your own. Printed forms and reports can be produced from the information in the file in any format you choose.
One of the most powerful features of Archive is ItS command structure. Once you have created a file and stored some records in 11, these commands can be used to find particular records, make searches and selections or display the information in the file
In a particular order.
The commands combine to form a powerful programming language, similar to
SuperBASIC, which can be used to construct a multitude of specialist applications.
At all times you will be guided by an informative set of prompt messages which never leave you in doubt about what your options are or what you are expected to do. If you require further information you can use the Help files. You may ask for Help at any stage, no matter what you are dOing, and will automatically be given the Information that is most relevant to your current needs.
The real power of Archive becomes apparent when you write your own procedures in the command language. You can create a named procedure to do exactly what you want and then use it as an additional command, in the same way as you use the commands provided With Archive.
The mechanics of writing and modifying a program are aided by a full procedure editor which, together with the input line editor (which is available at all times), make editing a simple and painless task.
The data files themselves use variable length fields and records. Not only does this lead to the most effiCient use of available memory and cartridge space, but also to simplified file creation. You never need to decide In advance how large a record needs to be.
This manual contains a number of working examples. Try these out to see some of the range of things that can be done. They contain many general purpose procedures which you might include in your own programs.
If, at any time, you are not sure what to do, remember that you can ask for Help by pressing F1. Also remember that you can cancel any partially completed operation (e.g.
typing in a number, or using a command) by pressing ESC.
Archive has been deSigned to give you the greatest possible ftexibility. As a consequence it cannot give as much assistance with the selection of options as the other OL programs.
If you are not familiar with computers and computer programming you may find it helpful to read the Beginner's Guide to SuperBASIC before attempting to write Archive programs.
CHAPTER
1
ABOUT
QL ARCHIVE
1284
CHAPTER 2
GETTING
STARTED
LOADING
QL ARCHIVE
Load OL Archive as described in the Introduction to the OL Programs. When loaded
Archive will display the following message:
LOADING QL ARCHIVE version x.xx
Copyright © 1984 PSIDN SYSTEMS database where x.xx represents the version number, e.g. 2.00.
The program will then wait for a few seconds before starting.
The Help information is not loaded into the computer's memory together with the program.
It is only read from the Archive cartridge when it is needed. You should therefore not remove the Archive cartridge from Microdrive 1 if you intend to use the Help facility.
GENERAL
APPEARANCE
When you have loaded Archive the screen should look like Figure display
2.1.
This is the main
HElP press fl
PROMPTS press f2
LJ
COMMANDS create delete display look back open alter firs t insert type command
Last next
&
press ENTER (F3 for more) close find quit
COMMANDS press F3
ESCAPE press ESC
>!ill
Figure 2.1
The main display with a monitor. (80 characters)
If you are using a domestic television, the screen is arranged slightly differently. This is because a television is not normally able to show clearly therefore only shows 64 characters.
80 characters per line. Archive
The screen is divided into three sections: the display area, the work area and the control area.
12/84
Getting Started
•
As its name suc)gests, this IS where all Information produced by Archive is shown.
The work area uses the bottom four lines of the screen. All commands that you type in, together with any error messages, are shown here.
BI
IB
BI
IB
The Display and
Work Areas
•
•
Figure 2.2 The display area Figure 2.3 The work area
These two areas almost invariably work together, Since commands typed into the work area produce their results in the display area.
As an example, type in the tollowlng short program, exactly as It is shown below tet x=13:whi le x>O:print x: let x=x-1 :endwhi le
I
ENTER
I
The text of this program will appear in the first line ot the work area. When you press
ENTER, the numbers from thirteen down to one will be printed on successive lines of the display area. The bottom line of the display area will be left blank except for a red cursor indicating the next position at which text will be displayed. The numbers from fifteen to one are displayed which, together with the bottom blank line, occupy all sixteen lines of the display area.
The command: cis I ENTER I will clear the display area completely.
The control area occupies the top tew lines of the screen. It shows the normal options:
Help (F1), to turn the prompts on and off (F2), cancel any incomplete operation (ESC), and use a command (F4).
The Control Area
Figure 2.4 The control area Figure 2.5 The commands
Archive's commands form a programming language and you must type their names in full. ThiS may seem long-winded at first, but later you will be shown how to create procedures which allow you to enter commands with a single keystroke.
USING THE
COMMANDS
12/84
3
4
Getting Started
There are four different lists ot commands which can be displayed by pressing F3. If a command list is already being shown, pressing F3 will display the next list in sequence.
These commands are used simply by typing in the name and pressing ENTER. However some commands need turther information and will ask for it.
You can use any of the commands, even if its name does not appear in the current display in the control area.
THE
MODE COMMAND
You can combine the control, display and work areas Into a single area with the mode command. Used by itself mode will combine the three areas Into a single area. Typing mode 0 will also have the same effect. Try mode IENTER I and the input from the keyboard and anything displayed by a command or program will share the whole of the screen. A value of 1 divides the screen back into three areas.
You can also use the mode command to change the number of characters displayed across the screen. To do this you must supply a second number separated by a comma from the tirst. The second number must be a 4, 6 or 8 to select a 40, 64 or 80 column display. Try typing mod eO. 4 r . 1
E"'N"'T"'E'"'R"I to change the display to 40 characters and to combine all three areas on the screen.
Note that the 0, which originally was optional must be typed to change the size of the display.
Try some different combinations to see the effect on the display. Finish with a command that leaves the screen divided into its three areas, but choose the number ot characters that gives a clear display on your teleVision or monitm
•
12184
•
An Archive file behaves rafher like a card index. A real card Index consists of a box containing a set of record cards, each card containing various items of information. For such a card index to be useful, there have to be rules to determine where each piece of information is wrltlen.
Suppose, for example, that we have a name and address Index. You would normally write the person's name across the top, followed by the address and telephone number
(if any). It would be very difficult to use if some cards had the name writlen at the top and others had it wrltlen near the botlom. You would normally expect to be able to use the index by flipping through the cards, reading only the top line, until you found the name you were looking for.
If you had two sets of record cards, such as a set of name and address records and a set of stock records, you would not normally store them both In the same box. You would use two boxes and label them, for example, "Customer Records" and "Stock
Records':
The card index system contains most of the ideas necessary to understand how an
Archive file works. A file Is like the card index box and is given a name to identify it.
The file Is made up of a collection of records, each of which serves the same purpose as a record card. A file, then, is simply a collection of related records.
Like a card Index, the information In each record is organised In a regular way. Individual items of data, such as telephone numbers might be kept on a specified area of the card. A record in an Archive file is organised in the same way. Each item is stored in a separate region of the record, known as a field.
A record in a customer file, such as that described above, would contain a name field, an address field, a discount field and so on.
If thiS were the whole story there would be litlle point In using an Archive data file in preference to a physical card Index. There are, however, many advantages when you use computerised records. A customer record card index would normally be arranged in alphabetical order of customer names which makes it an efficient way to find the information about a particular customer. Suppose, however you want to send a letler to all your customers who have not placed an order with you during the last six months.
It would be a very tedious task to go through the entire contents of a card index to compile such a list. In Archive you can make such a search by using a few simple commands.
Furthermore, it Is easy to arrange for a set of address labels to be printed at the same time.
You can save a great deal of time and effort by uSing Archive to store and manipulate your records.
CHAPTER
3
QL ARCHIVE
FILES
FILES RECORDS
AND FIELDS
12/84 5
6
CHAPTER 4
EXAMINING
A FILE
The best way to start learning about Archive IS to look through the demonstration file gazet, provided on the Archive cartridge. This is a file which contains information about various countries - the continent, the capital, the currency, the language, the population, the land area and the gross domestic product per capita.
Most of the examples in chapters 4 and 5 refer to the "gazet" file. Before using 11, you should make a copy of It uSing the following procedure:
When you have loaded Archive, put a formatted cartridge into M,crodrlve 2 and type: backup I ENTERI mdv1_gazet_dbf I ENTER I mdv2_gazet_dbf I ENTER I
Wait until the two Microdrives have stopped; be patient as the file is qUite long and can take a while to copy. Use the copy, now on the cartridge in M,crodrlve 2, for experimenting.
From now on we will not always write ENTER at the end of every command but please remember that it must still be used.
The look command opens a file so that you may read ItS contents, but you are not able to make alterations or additions to the file. It IS a safer command than open if you are merely looking through a file because the file IS protected against accidental modification.
You can examine the copy of the 'gazet" file on Microdrive 2 by typing:
Look " gaz et ll
DISPLAYING
ARECORD
To look at the first record type f; rst display
Don't forget to type ENTER alter each command and then the display will show the first record of the file.
Note the first line shows the logical name of the file; Archive automatically supplies the name "main" for a single file. Logical file names are usually used when you are using more than one file at a time and are described later
EXAMINING
OTHER RECORDS
Having looked at the first record of the file, you may want to move on to the following record. Type: next and the display shows the next record In fhe file. When you are typing single commands alter a display command the display area is continuously updated to show the contents of the current record. You can use the next command to step through the file, record by record until you reach the end (it will not pass the last record).
There are three other related commands which you can use to control which record of the file is displayed.
back first last
- which displays the previous record,
~ which displays the first record,
- which shows the last record of the file.
Try uSing these commands to move around the file, displaying any record you like. Note that the four commands first, last, next and back do not themselves display the record.
They merely move from record to record regardless of whether or not you have used display command.
SEARCHING A
FILE
Find
The first and Simplest search command is find. This will search from the beginning of a file, looking for the first occurrence of a specified piece of text in any of the text fields.
12'84
• e
•
Examnlng a File
For example'.
find "africa"
When you press ENTER there will be a slight pause and then the first record containing the word 'africa' in any of its text fields will be displayed. Note that this search IS independent of whether the text is in upper or lower case and will therefore find Africa:
AFRICA' or 'africa:
If the first record that is found containing the text is not the one that you want. you can find the next occurrence by typing:
Continue
continue
The continue command will repeat the prevIous search, looking for the next occurrence of the text in any text field of the following records.
It is possible that you may have to repeat a search several times before finding the record you require. Press F5 and Archive will put the previous command back In the command line. Press ENTER and the command will be executed.
Another method of locating a particular record is to use the search command. This allows SearCh you to find a record by speCifying the contents of one or more specific fields, for example search continent$="EUROPE" and Language$=/IFRENCH" will find the first record in the file which matches both conditions. You must type in the full field name.
Unlike the find command, search will only test the fields you speCify and will differentiate between upper and lower case letters. Use the upper( lor lower( ) case functions to make the search case independent for example: search Lower (cant i nent$)= lieu rope"
Again the continue command can be used to find the next occurrence of the text.
Select
In many cases, you may want to look at a sub group of the records within a file. Suppose, for example, you only want to look at the details of countries in Europe. You can use the select command to pick out from the file all those records which satisfy a certain condition. The file will then behave as though only those selected records are present
Try this command on the 'gaze!" file to see how It works. First type: print count() which will tell you how many records there are in the file. Then type: seLect continent$="EUROPE" print count() and you will see how many records have been selected. The records that are removed from the file are still held in the computer's memory and you can restore them to the file at any time by using the reset command. Type: reset and print the value of count( ) again, to check that the file has been restored to its original state.
When you use the print command from the keyboard, any file shown on the screen will be erased. This IS because, in general, display and print use areas of the screen which overlap. After using print you must type display again to restore the display.
SORTING AFILE
The file records may not always be in the order you need. You can sort the file by the contents of numeric or text fields. Only the first eight characters of text are taken into account by orde.r.
Suppose, for example., you want to sort the records of the 'gaze.!" alphabe.tically by capital city. You can do this by using the. order command as follows: order capitaL$;a
The.
"a' following the. se.micolon specifie.s that you want to sort the file In ascending order
Replace it by the sort ke.y
'\:J" If you want the file sorted In descending order The capital$ field becomes for the file.. You can specify a sort key composed of up to four fields by
12184
7
Examining a Fie
8 giving a list of fields aher the order command. For each of the keys you must specify whether the sort is to be In ascending or descending order. The following command, for example, will sort the file into descending order by population and ascending order by capital.
order pop;d,capitaL;a
Note that a semicolon separates each field name from the '\oj" or 'ij" that specifies ascending or descending order, but that each pall (field name and letter) IS separated trom the next by a comma.
When more than one field is specified for sorting purposes the records are initially sorted according to the contents of the first field In the list. If two or more records have the same contents for this field, they are ordered according to the next field In the list. If records exist which are equal in respect of the contents of both of these two fields, they are ordered according to the contents at the third field, and so on.
LOCATE
When a file has been sorted, you can use the locate command to make any particular record the current record In the file. Its action IS to find the first record whose first sort field is greater than or equal to the given expression. This record becomes the current record In the file.
For example, if the 'gaze1" file has been sorted as described In the last example, the command:
Locate "100"
locates the first country in the sorted file which has a population of 100 million. If there is no such country Archive will locate the first country with a population less than 100 million (remember that the file was sorted In descending order).
Locate is followed by an expression which may be either text or numeric, but must be of the same type as the field used to sort the file. (See the Reference chapter)
You can locate a record With respect to the contents of more than one sort field by using locate with multiple expressions, separated by commas. For example,
Let a="100"
Let b$="O"
Locate a, b$
will find the first country with a population of 100 million or less, and with a capital whose name either starts with "0" or is aher "0" in the alphabet. In this example Archive Will locate Bangladesh, which has a population of 76.1 million and whose capital is Dacca.
The only restriction on the number of expressions that you can use With locate is the number of fields used to sort the file.
You cannot use continue aher locate. Repeating a locate with the same condition will always locate the same record.
Locale is the fastest way of locating a record in a large, sorted, file. Because of the uncertainty in the record that is located, you may have to make a further check on the record to make sure it is what you want.
CLOSING AFILE
When you have finished looking at a file you must tell Archive. You can do this by typing
cLose
ThiS will only act on files and will leave any program or screen layout intact. You can close all your files and clear out your data and display area by typing new
This will clear Archive to its initial state after loading.
This only acts on the data files, leaVing any program, or screen layout, Intact.
Alternatively, if you have finished using Archive, you can go back to SuperBASIC by using quit. This command closes all open files automatically before leaving Archive.
Remember that you should never remove a cartridge from a Microdrive while open files.
it
contains
12/84
..
r
CHAPTER
5
MODIFYING
A FILE
Before typing in examples In this chapter, type new first to ensure that Archive is cleared and ready for a fresh start.
The open command prepares a file for both reading and writing.
If you open a file with the open command, instead of look you will be able to write to the file to change Its contents as well as read it. This means that any additions, deletions or modifications will make a permanent change to the copy of the file when it is closed.
Type: open "gazet"
If you have opened a file for reading w',th look then you must not use any commands which will attempt to modify the data. If you do, Archive will report an errm The commands described in this chapter modify data files and so should only be used with a file opened with open.
Display the first record of the file with: first display
When you have finished modifications to the file you must close the file (using close or new) to ensure that all the changes are recorded.
If you do not close a file properly (for example, if you just turn off the computer when you have finished) the file may be changed and your most recent changes will not be recorded. Always make sure that there are no open files on a cartridge before you remove it from the Microdrlve. Do not switch off the computer without first closing all open files and removing the cartridges from the Microdrives.
CLOSING THE FILE
INSERT
The insert command is used to add one or more records to the current file. When you use insert you will be asked to type in the contents of each field of the new record. Type: insert
The display area will now show:
LogicaL name main countryS continentS capitalS currency$ languagesS pop area gdp
You can now type in the contents of each field. You can step from one field to the next by pressing ENTER or TABULATE or you can step back to the previous field by holding down SHIFT and pressing TABULATE. You can make as many changes as you like to the fields until you are satisfied. The new record can be inserted into the file by pressing
F5. Press F4 to leave insert. Try typing:
SCOTLAND
EUROPE
EDINBURGH
POUND STERLING
ENGLISH
10
30
50
TABIII ATF
TABULATE
TABULATE
TABULATE
TABULATE
TABULATE
TABULATE
TABULATE
12184 9
Modifying a Fie
10
The display area should now show:
LogicaL name main country$ SCOTLAND continent$ capitaL$ currency$
EUROPE
EDINBURGH
POUND STERLING languages$ pop a rea gdp
ENGLISH
10
30
50
When you are satisfied that you have typed in the new information correctly, press F5 to insert the new record into the file. The fields you have just typed in will then be blanked out ready for you to insert a new record. Press F4 when you have finished inserting.
You can also end the entry for each field and move to the next one by pressing ENTER.
The new record is added to the file automatically when you press ENTER after the last value.
If the file has been sorted the new record is inserted at the correct position to maintain the order.
DELETE
You can use the delete command to remove a record from the file. delete removes the current record (the one shown by display) from the file. All you have to do to remove a particular record is to display it, and, having made certain that it is the correct one, type: deLete
CHANGING
ARECORD
it is also simple to modify the contents of any or all of the fields within an eXisting record.
There are two methods.
Alter
Select the record you want to change (use display and find) then type alter. Alter works
In the same way as insert except each field shows its old contents. You can step over those fields you do not want to change (use TABULATE or ENTER). Type In a new value or use the cursor keys to modify an old one. Press F5 to replace the record.
As with insert, the record is replaced automatically if you press ENTER after the last field in the record.
Update
Select the record you want to change then change the contents of the field variables until the displayed record is as required. Type update to change the record.
For example, suppose that you decide that iceland should be in Europe instead of the
Arctic. Find the record by typing find "IceLand" dispLay
Use the let command to change the contents of the contlnent$ field:
Let continentS;:: "Europe"
Finally put this change into the record by typing update.
In both of the above methods the new record will be inserted in the correct position if the file has been sorted. Otherwise the replacement record is inserted in an unspecified position in the file.
The alter command is Simpler to use, but always affects the current record. The update command can be useful when you are using multiple files.
Remember that you must close the fiie with the close, the new or the quit command, before switching off the computer.
~,j
l
12/84
•
•
CHAPTER 6
CREATING A
FILE
If you have been following the examples up to this point you will have been using Archive only to look at the file provided for you. This chapter will show you how to create your own file with your own choice of file names.
If necessary, type new to clear anything In the computer's memory and to close any open files. Make sure that the formatted cartridge on which you are going to create the file IS in M icrodrive 2.
Suppose you want to use ARCHIVE to make a catalogue of your books. To do this, you will have to create a new file called "books': The first thing to do when creating a file is to decide what It is going to contain, that is, what fields you will use in each record.
In this case you will obviously need to record the author, title and subject; you may also like to include other details, such as the type (fiction or non fiction), ISBN (International
Standard Book Number), shelf location, a brief description and so on. In this example we shall simply use three text fields to contain the author, title and subject and one numeric field which will be used to hold the ISBN.
You create a file with the create command. You must specify the name of the file to be created and the names of the fields to be used in each record. The $ sign indicates that the field contains text. When you have finished defining the fields of a record you end the create command with endcreate. You can create a simple book catalogue file, as described above, by typing in the following sequence.
create IIbooks" author$ tit I e$ subject$ isbn
endcreate
Note that you do not have to type in the final endcreate command. You can do so If you want, but you can end the creation of the file Simply by pressing ENTER on a blank input line. You must, however, include endcreate if you use create in an Archive program.
When you have created a file, it is open for both reading and writing, but it contains no records. Records can be added uSing insert. Type: insert and the display area will show: logical name: main author$ : titLe$ : subject$ :
; s bn :
All you have to do is to type In the contents of each field. For example, type:
BLoggs, J
A Bari ng Manua l
Cannon Mak
1234567 i ng fARl1I ATI=
TABULATE
TABULATE
TABULATE the display area should show
Log;caLname main author$ title$
BLoggs, J
A Boring ManuaL subject$ isbn
Cannon Making
1234567
Insert the record into the '100k" file by pressing F5. The fiefd value will be cleared ready for inserting another record.
CREATE
ADDING RECORDS
11
12/84
Creating a Fie
Remember that you can also end the entry for each field and move to the next one by pressing to the file
ENTER and that pressing ENTER after the last value will add the record
When you have finished press F1, and remember to use close or quit to save the file first.
12 12/84
CHAPTER 7
SCREEN
LAYOUTS
When you use the display command on a file that you have created, the records are shown using the standard Archive screen layout
DEFINING A
SCREEN LAYOUT
You can design your own screen layout, better suited to the Information in your data file. Open an existing file and type In: dispLay
You select screen editing with the sed!t command type In: sedit
The display area shows the current screen layout, which will be the one that Archive creates automatically. If there is no screen layout in the computer's memory, the display area may be blank.
You will see that the values of the fields of any file are not Included. The spaces where these values are normally shown are marked by rows of dots. You should think of a screen layout as a background against which the values of a number of variables are shown in speCific positions. Archive shows a screen layout into two stages - first it draws the background text and then If shows the values of the variables at the marked positions on the screen.
You are Initially at the main level of the command and you have three options: type background text Into the screen press ESC to leave sed!l
press F3 to use a screen edifing command
To design a screen layout, press F3 and then C to clear the screen and make a fresh start. Press ENTER to confirm your choice; any other key will return you to the main level of sedi!.
Choose paper and ink colours by pressing either P or I and pressing any key to SWitch between the four available colours. Press ESC to return to the main level to enter background text
Background text might be explanatory, such as:
Andrew Young's World Gazeteer
Or it might consist of a new name for one of the fields In your file:
Population (millions):
You can move the cursor to any point in the display area by using the four cursor keys.
Anything that you type will immediately appear in the display area at the position of the cursor and will become part of the background of the layout The only exception is if the cursor is positioned within an area of the screen reserved for the display of a variable. Archive shows the name of the variable in the work area at the bottom of the screen. You cannot type background text into this area unless you first free the area, as desCribed later
The four screen edit commands enable you to produce attractive and colourful formats for displaying your data. Clearing the screen has already been explained. You may need to experiment to completely master the remaining three so make sure you are using a copy of your data file which is expendable.
SCREEN EDIT
COMMANDS
Mark Variable
(V)
Suppose you want to show the value of the variable country$ at a particular position in the screen. Move the cursor to that point and press F3 and then the V key. Archive asks you to type in the name of the variable. You type: country$
Note that this name does not appear on the screen - you are Just marking the point where the value IS to be shown. When you press ENTER Archive asks you to show
13
Screen Layouts how much space IS to be reserved for showing the value. You press any key except
ENTER to mark the space with a row of dots. CTRL and the left cursor key can be used to delete reserved space When you have reserved enough space you press
ENTER and Archive takes you back to the main level ot sedi!.
It you move the cursor into one of the reserved areas, (marked by dots), Archive shows the name ot the varrable for which space IS reserved in the work area.
Ink (I)
Paper (P)
If you reserve space for a variable in a region which overlaps any area that is already
reserved, you are given the option of cancelling the old area. You can then use the option again to allocate space for a new variable.
Suppose you want to change the Ink colour Move the cursor to the pOint where you want the new colour text to start and press F3 and then the I key. Archive shows the four available colours ,n the control area. The one that is selected Will be the one that
IS highlighted. Press any key to change the selected colour and then press ENTER to record your choice. Any subsequent text that you type will appear in the new colour until the ink command is used again.
Changing the paper colour works in the same way - except that you press F3 and then the P key.
If you want a colour change to affect only part of a line, you should move the cursor to the start of the region and select the paper and Ink colours that you require. You should then move the cursor to the end of the region and make a second selection of paper and Ink colours, returning them to their orrglnal values.
ACTIVATING A
SCREEN LAYOUT
Once you have designed a screen layout and have left sedit, the screen layout will be
active. This means that the values of all the varrables in the screen layout Will be displayed automatically every time Archive completes a command or a program. If, for example, you type the command next Archive moves to the next record of the current file and shows those fields that are Included In the screen layout. Any active screen is deactivated each time you use the cis command.
If a screen layout is not active. you can activate It with the screen command. This displays the background text of the screen layout. but does not show the current values of the varrables.
SAVING AND
LOADING SCREENS
You can save your screen deSign on a Microdrive cartrrdge uSing the ssave command: ssave ufi Lename" where '1ilename" IS a name of your chOice. The screen layout is saved exactly as It appears.
You can reload the screen layout by typing in the command: sLoad "fi Lename"
When you load a screen layout. it is automatically displayed on the screen and made active.
Archive will not automatically update an active screen layout from Within a program.
Suppose you want to show all the records of the current file, one after another, and tried to do so by typing the one-line program: first: Let x=O: whiLe x<count():next:Let x=x+1:endwhiLe
(The while and endwhile commands cause the section of program that they enclose to be performed repeatedly, while the condition following while is true. For correct operation every while command must have a matching endwhite.)
This program would fail to do what you want, since Archive only updates the contents of the screen layout at the end of the program.
14 12/84
Screen Layouts
You can, however, force a display of the values of the variables in an active screen from within a program using the sprint command. The following one-line program will show all the records, as required f 1 r
5 t : Let x =0: w h; lex <c au n t () : 5 p r i n t : next: let x = x + 1 : end
IN hi Le
If there IS no active screen sprint has no effect.
THE SPRINT
COMMAND
Remember that the display command uses fhe standard layout. It will always replace any screen layout with ItS own simple list of the fields of the current record of tile current file. You must therefore ssave your screen layout before you next use display. If you do not, your screen layout will be replaced and you will not be able to get It back again except by redesigning It with sedi!.
THE DISPLAY
COMMAND
12/84
15
16
CHAPTER 8
PROCEDURES
To use the examples In this chapter, first type new to clear the computer then type look
"gazel" to open the example file on your data cartridge, which IS assumed to be in
Microdrive 2.
The commands and functions of Archive together form a programming language which you can use to write programs that will manipulate your files. You will find that Archive programs are simple to write.
An Archive program IS made up of one or more separate sections. Each section is known as a procedure which is Simply a named section of program. You can refer to a procedure by ItS name, like the procedures which you write and use In SuperBASIC.
In Archive you can run a procedure by typing ItS name at the keyboard. When you write a procedure you are effectively adding a new command to Archive
No procedure may contain more than 255 lines, and each line must not contain more than 160 characters.
CREATING A
PROCEDURE
You use the program editor whenever you want to write or change a proced,ure. This editor allows you to change, delete or add to the text of procedures.
The program editor is described In detail in Chapter 9, but in this chapter we will look briefly at some of ItS features so that we can write a few short procedures. We shall assume that initially there are no procedures In the computer's memory.
Type: edit to enter the program editor The control area changes, showing that you should type in the name of the procedure. Entering the editor will always allow you to create a new procedure If none are defined or loaded.
The first thing to do, therefore, IS to decide what the new procedure should do. Let us start With a very Simple task; to make life easier by renaming the display command.
We will save typing by giVing It the name 'd':
Just type d
The left hand side of the display area now shows the name, and the right hand Side a listing of the procedure. The procedure, as yet. contains no commands; the proc and endproc which mark the beginning and end of the procedure were automatically added by Archive.
The body of the procedure must be added; that IS sequence of actions it IS to perform.
The control area shows that you can add lines of text to the new procedure. In terms of the current example thiS text IS the display command. Type: display and Archive will Insert the new text into the procedure below the highlighted line. If you have followed thiS example the display will contain: d proc d display endproc
You could add more lines of text - each line would be inserted below the highlighted line.
In thiS case, however the procedure is complete so you can leave the edit command by pressing ESC twice.
All you have to do to use the procedure is type its name, followed by ENTER. This new procedure will perform the same function as typing the command display in full.
LISTING AND
PRINTING
PROCEDURES
Whenever you call the edit command you are shown a list of the names of all the defined procedures present in the computer's memory.
12/84
•
•
•
•
Procedures
You can list anyone of these procedures from within edit by pressing the TABULATE
. key to move down the list or the SHIFT and TABULATE keys together to move up the list until the particular procedure name is highlighted. The procedure is automatically listed at the right hand side of the screen. If the procedure is too long to fit in the display area, you will be shown the first part and you can then scroll up and down through the procedure using the up and down cursor keys. When you have finished you can leave the edit command by pressing ESC.
If you want a printed listing of your procedures you can use the IIist command. Type:
LLis t and all the procedures currently in the computer's memory will be listed on a printer.
WARNING: Do not use this command unless a printer is attached since this will cause the program to "hang".
SAVING AND
LOADING
PROCEDURES
If you want to keep the procedures that you have defined, you can use the save command. ThiS stores all defined procedures in a single named file on Microdnve cartridge. If you want to save the new display procedures that you have Just defined in a file called "myprocs", you should type in save "myprocs"
At any later time you can bring these procedures back into the computer's memory by typing
Load "myprocs"
The load command deletes any existing procedures in memory before loading the new ones from the Microdrive cartridge. If you want to add the new procedures to those already in memory, you can use the merge command. For example: merge "myprocs"
This works like load, except that the existing procedures are not deleted. If a new procedure has the same name as an existing one, the new one will replace the old version.
Renaming commonly used commands with single-charader names is one way of making life easier for yourself. An alternative would be to write a longer procedure to replace several commands by single key presses. Try using the edit command to define the follOWing procedure. It allows you to open and examine any of your data files, providing, of course, that the file you wish to use is not already loaded.
If you have already defined a procedure, typing: edit will not automatically give you the option to create a new procedure. From within edit you must press F3 and then the N key to start a new procedure.
Don't worry if you make a few mistakes whife typing in the example how to correct them in the next chapter.
- you will learn I
EXAMINING FILE
RECORDS
12/84
17
Procedures
18 proc vufi Le cLs input "which fi Le? ";fi le$
Look fiLe$ dispLay let key$="z" whi le key$<>" q" sprint
Let key$=lower(getkey()) if key$="f l ':first:endif if key$="l":Last:endif if key$="nll:next:endif if key$="b":back:endif endwhi le close endproc
Remember that you leave edit by pressing ESC tWice.
You can use the procedure by typing: vufiLe
It will first clear the display area and then prompt you to type in a file name such as
'gaze!': If 'gazet" IS already loaded, however, you will receive an error message. To recover, type new and load and run the procedure again. When you have entered the name of one of your data files the procedure will open that file ,n read-only mode and display
ItS first record. It will then wait for you to press a key and will respond to the keys f,
I, n, b or q. The first four of these Will cause the appropriate display action (first. last.
next or back) and pressing the q (quit) key will close the file and end the procedure.
Since this is the first program of any great length that we have written, a few comments might prove helpful. First note how the example is indented to clarify the structure of the procedure. There IS no need for you to type it like this, the Indents are added automatically as you write, list or print the procedure.
The main part of the procedure (waiting for a key to be pressed and performing the appropriate action) IS enclosed between while and endwhile commands. This repetitive loop Will only be left when the condition follOWing while is false, in this case, when you press the q key.
The if command, used several times within thiS loop, also requires that each if has a matching endif to mark the end of the sequence of instructions to be executed if the condition is true. If and endif are separate commands and can be used on different hnes.
We could, for example, have written the nrst of the if statements in this procedure as: if key$="f" firs t endif
You may include several lines of statements between if and endif; they will all be executed, provided the condition follOWing if is true. In the vufile procedure these statements are sufficiently short that each can be written on a single line, using the colon to separate
,the individual statements.
As you can see, a sprint command is used Within the main loop of this procedure to make sure that each new record is shown on the screen. Remember that. although the display commands (first, last etc.) always move to the correct record, the data in the display area is not automatically changed until the end of the procedure. If we had not included the sprint command, no information wculd have been shown in the display area until you pressed the q key to leave the procedure. In that case all you wculd see wculd be the result of the last of any sequence of keypresses that you have made.
C
'. /
12/84
CHAPTER
9
EDITING
This chapter descnbes the program editor We shall include a few simple examples, but the best way to learn is by uSing them yourself Start by typing new to clear the computer's memory.
When you have read this chapter you could try wntlng a few simple programs of your own, or you could try modifying the procedures you typed In while working on the last chapter. If you want to use longer examples you could use the editor to type in all or part of the programs In the following chapters.
THE PROGRAM
EDITOR
You enter the mam level of the program editor With the edit
As an example we can create a procedure and add a couple of statements to It From the main level of edit, press F3 and N to create a new procedure. Type In test when prompted for the name of the procedure.
Press ESC twice to leave the editor Without adding any statements. Then use the edit command again. If you have no other procedures loaded, the screen will show: test proc test endproc
If the procedures you created in the last chapter are still loaded, then test IS highlighted on the left as the current procedure among these other procedures. Press F4 to Insert lines of text. The line containing proc will be highlighted.
Now type: print "this is a test"IENTERI print "there are two statements" IENTERIIENTERI
Pressing ENTER twice In succession takes you out of insert When you have finished the screen will look like: test proc test print "th;
5 ; 5 a test" print "there are two statements" endproc
The line containing the second pnnt statement is highlighted.
Remember that until you press ENTER you can use the line editor to correct any text that you type. However, once you have pressed ENTER the line IS inserted into the procedure. To get It out again to edit it you must press F5. Pressing ENTER Will then replace the old line with the new line.
You are not allowed to edit the endproc statement at the end of the procedure. You are also not allowed to edit the word proc but you may edit the rest of the contents of thiS line. You can, therefore, rename a procedure by using the line editor to delete the old name and replace it with a new one. The list of procedures at the left of the screen
IS rearranged automatically to keep the procedures in alphabetical order
There are four separate editing commands which you Will have noticed in the command section when creating a new procedure. You can select one by pressing F3 and then typing the first letter of its name.
You type in the name of the procedure you want to create. If you type in the name of an existing procedure, you Will not be allowed to create a second procedure but will be offered the option of editing the existing procedure.
When you press ENTER at the end of the name the new procedure becomes the current one, listed at the right of the screen. You are presented with an empty procedure that is, one containing only the proc and endproc statements.
This command deletes the current procedure from your program. You must first select the procedure you want to delete by using the SHIFT and TABULATE keys, as described earlier, to make It the current procedure. You then select the command by pressing F3 and then the D key.
You must press ENTER to confirm that you really do want to delete the procedure. If you change your mind at this stage you can press any other key to go back to edit without deleting the procedure.
Editing Commands
New Procedure (N)
Delete Procedure (D)
12/84 19
Editing
Be careful when you use this command since there is no way to restore a deleted procedure, except by typing it in again.
Cut (C)
ThiS command removes one or more lines of text from the current procedure. The text that is removed can be Inserted in another POSition, or even in another procedure, by means of the paste command.
Before you select the command you should use the up and down cursor keys to make the current line either the first or the last line of the section you want to remove. You can then select the command by preSSIng F3 and then the C key.
If you then press ENTER the current line will be removed from the procedure. Alternatively you can use the up or the down cursor key to move the cursor to the other end of a section of text that you want to remove. The region of text that will be removed is marked by highlighting. When you have marked the text you want to remove you should press
ENTER. Archive will immediately remove the marked text.
Paste (P)
This command Inserts the text removed by the last use of the cut command into the current procedure, below the current line. The text can be inserted in another POSition, or even In another procedure.
Before you select the command you should, If necessary, use the SHIFT and TABULATE keys to select the procedure in which you want to insert the text You should also use the up and down cursor keys to highlight the line immediately above the position where you want to insert the text.
Archive Immediately Inserts the text, underneath the current line. When you have used paste to insert the text, the paste buffer is empty. You can not, therefore, insert the same text in more than one position.
20
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
12/84
CHAPTER 10
PROGRAMMING
IN ARCHIVE
This chapter will describe the development of an actual working example and each new technique will be described as it IS needed.
Suppose you are involved In running a club or society which charges a subscription and produces a newsletter. You Will need to send a copy of each issue to every pald·up member. You Will also need to send a reminder to each member when his or her subscription falls due.
This example allows you to construct a mailing list and then print a set of address labels on request. The address label Includes a reminder when a subscription is due. The example assumes that you send out six Issues of the newsletter per year and that a person's subscription falls due when he or she has received six issues. It could easily be adapted to any situation where you regularly send out some form of circular letter to a number of people on a mailing list
In this example we shall make as much use as possible of the existing facilities and introduce some new ones. If you need help with a feature or command you have not yet encountered, or one that seems to do things you don't understand, you may now find It quicker to look for help in the reference section or use the help function by pressing
F1. We use the insert and alter commands for all additions and changes to the file records. We shall, however need to write special routines to print out the address labels.
We shall have to cater for the follOWing set of requirements:
Add a new record to the file.
Delete a record.
Modify a record.
Record subscription payments.
Produce the address labels.
Leave the program.
We shall write a procedure to handle each of these tasks and link them together by another procedure which will allow you to select any of these options.
In this application it IS qUite clear what fields each record must contarn. The name and address are essential plus one field to record the number of issues the person has received. We can create the necessary file Immediately, as shown below create "ma i LII titleS fname$ surname$ street$ town$ county$ postcode$ issues
endcreate
We have used three string fields for the person's name; to hold the title (Dr, Mr, Mrs etc), the first name and the surname respectively. We could probably have managed With
Just a single field.
There are four string fields for the address, nominally reserved for the street address, the town, county and postcode. You do not always have to use them in this way, but can treat them as four general fields to hold the address. Four fields should normally be qUite sufficient
There is only one numeric field, to hold the Information about how many Issues remain to be sent.
Now that we have the file, we can use it to test the various procedures as we write them.
It IS a good idea to test each procedure as far as possible as you go along. You can then spot each mistake as It occurs and correct It immediately. If you leave all the testing to the end It will be much more complicated as several things may be gOing wrong at the same time, Keep things as simple as possible while you are stili testing your procedures. Try to make sure that each procedure works correctly before you move on to the next one. That way you will find that your final program Will usually work as soon as you have written the last procedure.
AMAILING LIST
21
12/84
Programming
Insertion
We do not need to write a procedure to add a record. We can use insert. Remember that you must use sprint to force the display of the contents of the record trom within a procedure. You can use insert immediately to add a few records to the file so that you can test the other procedures on a real file.
Deletions
At some time you will want to remove the records of people who have not renewed their subscriptions. We shall write a procedure, wipe, which allows you to scan through the file, examining the records of all people who have not renewed, and to deCide which should be deleted.
We shall use the field variable issues to hold the number of Issues that a person IS entitled to receive. All records for which the value of issues is zero are therefore candidates for deletion.
proc wi pe rem ***** delete non-paying subscribers ***** cLs dispLay se lect issues =0 aLL sprint print at 18,0; "DELETE (yin)?
";
Let ok$ =Lower(getkey()) print ok$ if ok$ =llyll detete print "DELETED"; tab 15 else print tab 15 endit endaLL reset endproc
Since a deleted record cannot be recovered, the full contents of the record are displayed and you are asked to confirm that you really want to delete it We use the getkeyO function which walts for a key to be pressed and then returns the ASCII code of that key. Note that lowerO converts the code to the lower case character so that you can type the letter
In either upper or lower case.
Once you are satisfied you have correctly entered this procedure, you may try it out on your file, (provided, of course, that you have entered some test records). First, leave edit by pressing ESC (twice if necessary) and save your procedure in a file called "Maillist':
~~.
save "Mai II i st"
The procedure called wipe
IS now stored and can be called whenever "Mailllst': IS loaded.
After entering each of the follOWing procedures, repeat these steps, each time storing the new procedure In "Maillist':
Payments
You will normally want to record a batch of subscription payments from a list of names and addresses. You will therefore need to get the record of a particular person. The qUickest way is to write a separate procedure, getrec, to locate a particular record and then Incorporate it In a pay procedure.
The getrec procedure asks for a text string (n$) and then locates the first record in the file which contains that text. If you reply by just pressing ENTER, n$ is set to the empty string and no search is made. This will, however, Indicate that you have finished recording payments.
C
22 12/84
Programming
From the edit level, press F3 and N to start entering getrec.
proc getrec rem c Ls
*****
locate a particular record
*****
let ok$ ="n ll input "who? "; n$ if n$ <>"" find n$ whi le ok$ <>'Iyll and found() print title$ ;
It " ; fname$(1);
II " ; surname$ print street$ print "0K (yin)?
";
Let ok$ =Lower(getkey()) cts if ok$ <>" y tl continue endif endwhi le if not found() print n$ ; " not found" endif end if endproc
The search uses the find command, so that the text IS tound In any string field. You can therefore Identify a record by name or by address. Of course, the first record which matches may not be the one you want, so we have to be able to continue the search.
This is the purpose of the while endwhile loop. This prints out the name and first line of the address, to identify the record, and asks you If that IS the right record. If you do not respond by pressing the Y key, it continues the search. The loop ends either when you answer by pressing the Y key or when the text is not found in any of the remaining records. Note that the function foundO returns a true (non-zero) value if the search IS successful.
Since ok$ could initially be ''y'' (from a previous successful search) we must give II some other value at the beginning of the procedure, before entering the loop. This makes sure that the loop will be used at least once.
We can now write the pay procedure: proc pay rem c L s
*****
record subscription payment let n$ ="x" whi le n$ <>"11
*****
getrec if ok$ =" y" let issues =issues +6 update endif endwhile endproc
The loop in this procedure continues until n$ IS an empty string. This allows you to record several payments without having to select the pay option for each one. When you have finished, just press ENTER in response to the 'v,ho?" prompt, If the value of ok$ is y after the call to getrec then the payment IS recorded by marking it as valid for a further six Issues,
Again we have to set the initial value of n$ to some appropriate value (anything except the empty string) to make sure that the procedure IS not affected by a previous operation.
The procedure to allow you to change the contents of a record is now very easy. Again you must be able to select a particular record to change, so the general structure can be identical to pay.
Changes
12/84 23
Pro<Jrarnmirg proc change rem ***** alter record ***** let n$ =" X " c Ls whi le n$ <>'"' getrec if ok$ =" y" alter cLs endif endwhi Ie endproc
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron,co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
PARAMETERS
We shall now take a short break from the development of the program to describe the use of parameters with procedures. You can use a parameter to pass a value to a procedure, rather than using the value of a variable. We shall show you a few examples of how they can be used. You do not need to save these procedures in "maillist" and you may delete them before moving on to the section of the program which deals with labels.
Try the following simple example. Using the line editor, you add the parameter to the line containing the procedure name.
proc test; a pri nt 5*a endproc
This defines a procedure called test which requires one parameter, 'f!': Notice that the parameter is separated from the name of the procedure by a semicolon. Whenever you use the procedure you must always supply a value for the parameter For example, you could type: test; 3 which will print the value 15 - the number (3) has been passed to the procedure as the value of the variable a.
You may specify any number of parameters for a procedure, provided you separate them by commas. For example: proc trial; a,b,c print a * b * c endproc which you can call by: trial; 3,4,5
The values you supply do not have to be literal values, but could be variables, as shown below:
Let x = 2
Let y
Let z
=
7
5 trial; x,y,z
Note that the names of the variables do not have to be the same as the names used within the procedure. We can distinguish between the tormal parameters (e.g. a,b,c) in the definition of the procedure, and the actual parameters which are the actual values that are passed to the procedure.
You can also pass the results of expressions: trial; x*2,z/y, (z-y)*x
You are not restricted to uSing numeric variables but can also pass strings (or string expressions) as parameters, provided you specify string variables in the definition of the procedure. For example: l
24 12/84
Programming proc try; a$ print a$ endproc
Let t$ = "message ll try; t$
The only requirement IS that the number and types of parameters supplied must match the list at tormal parameters in the definition of the procedure.
The reason for the brief Interlude about parameters IS that they give a neat way at wnting the procedure to print an address label. For the purposes of testing we shall lIrst write the procedure to show the addresses on the display and later convert it to send the output to the pnnte' We shall assume that the labels are eight lines of pnnt-out in length.
If this IS not right for your printer and label combination you will have to change the number at lines of space in the procedure so that It matches your reqUirement Remember to start saving your procedures In "Mailllst" again.
First we shall write a procedure that displays a single line, the contents of which are passed via a parameter.
proc doLine; x$ print x$ endproc
We can now use this procedure to display eight lines at text tor the address label.
proc doLabeL rem
*****
print LabeLs
*****
if issues if issues =1 doline; "REMINDER Subscription Now Due" eLse doLine; end if doLine; doLine; titLe$ +11 "+fname$ (1)+".
"+surname$ doLine; street$ doL ine; town$ doLine; county$ doLine; postcode$ doLine; "" let issues =issues 1 update endif endproc
The procedure includes a reminder in the address label if the person is about to receive his or her last issue. Each time a label is printed, that person's issue count is reduced by one. If this number has reached zero then the label is not printed.
You can begin to see how useful parameters can be - without them this procedure would be much longe, Look how easy it is to combine the title, Initial and surname for the tirst line of the address.
Perhaps you are wondering why we went to the trouble of detining doline when we could have Just used print statements throughout dolabel. The reason is that the routine in ItS present form shows the addresses on the display screen. We can convert it to send its output to the printer merely by changing one line in doline, instead of having to change every print statement in dolabel. All we need to do is change doline to read: proc doLine; x$
Lprint x$ endproc
Address Labels
12/84
25
Programming
26
Finally we can write the procedure to print all the address labels' proe despatch cLs aLL doLabeL endaLt endproc
Leaving the Program
The final option IS to leave the program when you have finished. This procedure can be very simple - all It has to do IS to make sure that the file is closed properly before returning control to the keyboard. We have also added a short sign·off message to make it clear that the program has ended.
proe bye cLose print "bye" stop endproc
ERRORS
It is qUite likely that sooner or later you will make an error while uSing this program
You may, for example, aCCidentally press the ESC key or you may type in soine text when a number is expected. ThiS type of mistake IS detected by Archive and normally results in the display of an error message and a return from your program to the keyboard.
You can use the error command to mark a procedure to be treated specially If any error is detected. Any error occumng In the marked procedure, or any procedure that It calls, results in an immediate, premature, return.
The normal method of handling errors is switched all for the marked procedure and it is left to you to decide how to deal with it You can find out the number of the last error that occurred by using the errnum( ) function. You can use It to read the error number more than once as the value is only cleared to zero by the next use of the error command. If no errors have occurred since the start of the program, or Since the last time error was executed, then errnum( ) Will return a value of zero.
This method, although not easy to understand at first, gives you a very powerful and flexible control of how to deal With errors. The follOWing example shows a typical way of uSing error. It gives you an error·resistant method of inputting a number.
proc dotest input x endproc proc test
Let n =1 whiLe n error dot est
Let n =errnumO if n print "You made error number
II in endif endwhiLe endproc
.
,
" , try again'l
The first procedure Simply waits for your Input to the variable x. The second procedure handles any error during the execution of the Input procedure. If any error occurs within dotest It will be terminated prematurely and the error number Will be set This number is then read by errnum( ) and, if it is non-zero, the error message is printed (thiS error message could, of course, be anything you like). Since these statements are enclosed in a while endwhile loop, any error Will cause them to be executed again. The error number is cleared by error, ready for the next try. You can not leave test until you have typed in a valid number
This example reports the number of the error that was detected. On most occasions you will not be concerned about which error occurred. The main use of errnum( ) is to differentiate between there being no error and there being a detected error of any type. A list of error numbers and pOSSible explanations is included in the Reference chapter
We can now write a procedure which will allow you to select anyone of the SIX options with a single keypress. It IS suffiCiently simple that no explanation IS necessary.
12 B-1
I
'--/
Programming proc choose rem cLs
*****
choose an opt i on
*****
print print" Add Despatch Pay Change Wipe Quit"; print "? ";
Let choice$ =Lo_er(getkey()) print choice$ if choice$
:;;;lI a ": insert: endif if choice$ ="d " : despatch: endif if choice$ :;;;"p": pay: endif if choice$ :;;;"c rr
: change: endif if choice$
:;;;II W": wipe: endif if choice$ :;;;llq": bye: endif endproc
All that remains to be done to complete our program IS to wnte a start~up procedure which opens the file and calls choose. We must include choose In a loop so that you are offered the options again, each time you complete your previous selection.
You will see that the while endwhile loop In the following procedure will never end. Such a loop will only come to an end when the expression following white has a zero value.
in the above procedure the expression always has the value 1, so the loop will continue indefinitely. The only way ot leaving this loop is to choose the QUit option. The stop command in bye immediately returns control to the keyboard.
proc start
*****
rem start procedure
*****
c L 5 open "newma it. dbf"
_hi te 1 error choose tet n =errnum() if n print "Mistake Press any key to continue"
Let m$ =getkey() endif end_hi Le endproc
Within this loop is a sequence of statements which handles any errors, uSing a similar method to that described in the prevIous section. If you make a mistake the program will not continue until you press a key. This allows you to look at what you have Just done so that you can find out how you made the error
THE RUN
COMMAND
The main procedure in the mailing list program is called "start': This IS so that you can use the run command when uSing the program We have already used this command when we used the "loader" program to load the 'gazer data file
Save this final procedure in "maillisr. When you want to run the program you will need to load the procedures into the computer's memory and then execute the main procedure, which Will call all the others. One way is to use the load command and then type In the name of the main procedure, for example: toad "mai II i st" start
The run command will load a named program and then automatically execute the procedure called "start" (if it exists). You can run the program exactly as in the prevIous example just by typing: run "mai II i st"
The remaining two sections of this chapter include some general purpose procedures which you may find useful.
Most variables that appear in procedures are global.
This means that they are recognised throughout the program. They may be used or changed in any procedure, and not Just the procedure In which they are first assigned a value.
LOCAL VARIABLES
27
12':84
Programming
28
The variables used as formal parameters in a procedure are local variables and they are not recognised outside the procedure In which they appear.
The following example may help to make the distinction clear Before going on, type new to clear the computer's memory. Flfst we create a procedure which uses two local variables a and b$, as well as aSSigning values to two normal (global) variables u and v$.
proc demoi a,b$ print a,b$
Let u=3
Let v$="text ll print u;v$ endproc
Then we use demo: demo 5 i "words"
All four values are printed showing that all four variables are recognised Inside demo.
Typing print u;v$ shows that both of these variables are also recognised outside the procedure. However, typing print a,b$ results In an error because a and b$ are not recognised outside demo. All formal parameters are local variables, but you can also declare other variables to be local, as in the following example: proc dumbo print "inside dumbo" print Pi q; r endproc proc dummy
LocaL q,r
Let p tet q
Let r
2
= 3
= 4 print "inside dummy" print Pi qi r dumbo endproc
If you attempt to use dummy by typing: dummy you will find that the values of p, q and r are all recognised (and therefore printed) in dummy, but dumbo does not know the values of q and ( which are local to dummy.
The values of local variables are not defined anywhere except in the procedure in which they are declared not even in procedures called from the declaring procedure. The variable p is global and is recognised everyWhere
You may be wondering why local variables are necessary. To illustrate their usefulness, suppose you write a program containing several procedures that you, or someone else, originally write for use in other programs. It is quite possible that two or more of these procedures might use variables with the same name for qUite different purposes. If these variables were global then one procedure could alter a value so that It would be wrong for another In such a situation you would have to check all the procedures that you use and, if necessary, change the names of the variables. If, however, the variables were local it would not matter if they had the same name. Provided they were In different procedures, changing one would have no effect on the other
Furthermore, It does not matter if a procedure calls another which uses the same name for a variable - provided at least one of them is local. For example, the procedure choose in the section on errors, earlier In this chapter, declared the variable choice$ to be local.
This means that there is no need to check whether any of the many procedures called by choose also use choice$ - the called procedures cannot change the value of choice$ in choose.
12184 f
Progamming
Displaying a prompt and waiting for a key to be pressed is one of the most commonly needed actions, so it IS worth writing a general-purpose procedure. The procedure must be able to display a wide range of messages. A simple way of allowing the procedure to print any message is to pass the message to the procedure in the form of a parameter proc prompt; m$ print m$ + ": II;
Let x$ =Lawer(getkey()) print x$ endproc
The message to be displayed IS passed to the procedure as a parameter In the local variable m$. The function getkey( ) waits for a key to be pressed and returns the ASCII code for the key. In this procedure the ASCII code is converted to lower case by the function lower(), so that the result IS independent of upper or lower case. Finally the resulting value is assigned to the variable x$. This is a global variable, so that the key that was actually pressed IS available to any other procedure In the program.
A useful procedure IS pause. It uses prompt to print a message and then Simply waits until a key is pressed. Since you are not usually interested In knowing which key was actually pressed, it uses a local variable, y$, to preserve the original contents of x$.
proc pause rem ***** wait for any key *****
Laca L y$ let y$ =x$ print prompt; "press any key to cant
Let x$ =y$ endproc i nue"
PROMPTS
PAUSE
DATA ENTRY
Text
Accepting text as typed Input is qUite simple. Any collection of characters is a valid text string (even If It does not make sense) and will not cause an system error. You will not normally need to take any special precautions when accepting text input. It will usually be sufficient to use a line such as the follOWing, which asks you to type In your name: input "PLease type your name: ";name$
Note that a space is included as the last character of the prompt text; this small pOint makes a lot of difference to the appearance of your program when you use it.
You can input several items with one Input statement. All you have to do is to Include all the prompts and variable names, separated by semicolons.
input "Your first name? ";fname$;"Your surname? ";sname$;
This last input statement also ends with a semicolon - this stops the cursor moving to the following line after you have typed your Input.
When you use the input command to enter text to a string variable the computer will accept anything that you type, without complaint. If, however you try the same thing with input to a numeric variable you Will get an error message if you type anything except a valid number Assuming that you do not want to leave your program every time your finger 9ips while you are typing in a number, you must make sure that your program can cope with such errors.
The most useful way is to make use of the error command, which was described earlier
The following procedure, for example, will accept any valid number within a speCified range. It even provides the display of any prompt message you want to appear.
Numbers
12/84 29
Programming proc getnum; m$,min,max rem ***** get number in range local wrong
***** let _rong=1 whi le wrong print m$; "?
II; error readnum let wrong=errnumO if not wrong if num<min or num>max let wrong=1 print "Allowed range ;s ";min;" to ";max endif endif if wrong print "Try again" end if endwhi le endproc
Since error must be followed by the name of a procedure. we define readnum to input a value for the vanable num.
proc readnum input num endprac
Suppose you want a procedure thaf checks that a number is within the range 1 to 10
You can do this uSing getnum in the following way: prac check getnum; "Numeric value?",1,10 endproc
30 12/S-l
This chapter extends the explanation of how to use the Archive programming language by describing how to work with two or more open files. When you have more than one file open at the same time you must be able to Identify which file you want to use for any particular operation. You must give each file a unique logical file name when you open or create It and then refer to It by that name in all commands that refer to the file.
Archive automatically supplies the logical file name, "main", when you open a single file.
It is called a logical file name to distingUish it from the phYSical file name the name you give to the file when you save it
Since a program refers to a file by its logical file name, you can write a program that will work with several different files.
Logical file names are essential for multiple file operations Since you can only open a second file by using both ItS phySical file name and its logical file name. Note that the logical file name is not saved with the file when it is closed and must be specified each time the file IS opened.
Two or more data files could contain fields with the same name. When thiS happens you can idenlify the file to which the field belongs by adding the logical file name to the field name. For example, If the field country$ appears In two files whose logical file names are "main" and "b" you could refer to each of them respectively as "main.country$" and "b.country$':
CHAPTER 11
USING
MULTIPLE
FILES
LOGICAL
FILE
NAMES
The first example demonstrates how to add, delete or rename fields within an existing file.
Suppose that you want to make some changes to the 'gaze!" file, to create a new file containing only European countries. The 'tontlnent$" field becomes irrelevant and we need not Include It We shall also rename the "pop" field as "population':
The most convenient way of changing the file is to create a second file containing the fields you want and then to copy the required records from the old file to the new one.
Let us call the new file 'europe': The following procedure will do the rest of the work.
proc start rem
*****
c reat e eu rope f; t e
*****
create "europe" logicaL lie" country$ capital$ languages$ currency$ popuLation gdp area endcreate
Look "gazet ll Logical "g" seLect continent$="EUROPE II all "g" print at O,O;g.country$;tab 30
Let e.country$=g.country$ let e.capital$=g.capital$ let e.language$=g.language$
Let e.currency$=g.currency$ let e.population=g.pop
let e.gdp=g.gdp
let e.area=g.area
append " e " endall cLose lie" cLose "g" print print "DONE" endproc
CHANGING THE
RECORDS OF A
FILE
12/84
31
Using MLilipie F~es
THE CURRENT FILE
You can see, from this example, that you can use the same name for a field in both files - they can be distinguished by including the logical file name. If you do not include the logical file name then it will be assumed that the current file IS to be used. The last file to be opened automatically becomes the current file. In thiS example the current file will be 'gaze!" (with logical file name 'g') so we could make use of thiS by simply writing the g before the field name in the previous program.
If you do not Include the logigal file name in any case where it is optional, Archive will assume that the command refers to the current file. It IS usually safer to include the logical file name expliCitly, to avoid any possibility of confusion.
You can, at any time, speCify the current file by means of the use command. If you
Included the command: in the above example, then "europ~' would be the current file until you changed it again, either by opening another file or by means of the use command.
STOCK CONTROL
Now for a more complex example. In a stock control system you will need to
Find information on a particular stock Item.
Obtain a report on the current stock levels of all items.
Record sales and modify the stock records accordingly.
Order new supplies, to maintain adequate stock levels.
Record deliveries of stock.
You will obviously need a file to hold the details of all items held in stock and it is convenient to have a second file to hold details of all your suppliers. You will need to be able to access either file from the other - tor example you may want to know all the possible suppliers of a particular item, or to find out what items are supplied by a particular company.
In order to keep the application as simple as possible we shall not use the menu-driven approach of the examples in the previous two chapters. We shall write it as a series of separate commands which can be used - like the standard commands - by typing their names.
Since the procedures will be strongly dependent on the file structure we use, we must first give some thought to their appearance.
The Stock File
The stock file must contain full details of the stock situation for each item. The following list explains all the fields we shall use.
32
Field Name Use Example stockno$ description$ qty se llpr reorder Lev buyqty
The internal stock code
Item description
Number in stock
Selling price
Reorder when stock level falls below this value.
How many to order
A101
Widget, La rge
500
1.
25
200
400
We can create the file by: create "stock" LogicaL "sto" stockno$ description$ qty reorder Lev sellpr buyqty endcreate
The Supplier File
This file holds the names, addresses and telephone numbers of the companies that supply the goods you sell. It will be useful also to include the name of a contact person
In the company. In order to be able to access this information efficiently we shall include a code for each company. We shall use the following fields:
12/84
USing Muhple Fies
Field Name coname$ streetS town$ countyS post codeS contact$ telS codeS
Use
The company's name
First line of address
Second line of address
Third line of address
Last line of address
Name of a contact
Telephone number
Your code for the company
Example
Wonder Widgets plc
27 Be lmont House
LIVERPOOL
Merseyside
L31 2H K
Andrew Cummi ns
051-532 7133 a
We can create the tile by create "suppLier ll logicaL "sup" coname$ street$ town$ county$ post codeS contact$ telS codeS endcreate
This file forms the link between the previous two files. It uses the following fields:
The Orders File
Field Name Use Example stocknoS codeS scodeS price delivery
Your stock code
Your code for the supplier
The supplier's code for the item
The supplier's selling price
The supplier's delivery time, In days
A101 a
123-456
0.87
28
Each record in this file links one record in the stock file with one record In the supplier file. The above example shows that Wonder Widgets (supplier code 'a') can supply you with large widgets (stock code '1\101').
In addition, we include details of the pnce, delivery time and the supplier's own stock code. These items are useful when you order more stock.
Using this file allows you to cater for the cases where one supplier supplies more than one stock item (equal values for code$, but different values for stockno$) and where one stock item is obtainable from several suppliers (equal stockno$ but different code$).
Create the file with: create "orders" LogicaL "ord ll stockno$ codeS scode$ price delivery endcreate
Having created these files, we now need some procedures to handle the information they will contain. You will find that the most frequently-needed facility is to find information about a particular stock item in response to customer enquiries. You will need to find the information as qUickly as possible, but may need to find a particular record from either the part number or the description. We shall therefore use the find command so that you can give any valid text to start the search.
Enquiries
12/84 33
Using Mulbple Files
34
The procedure must be able to ask for you to confirm that the record is the one you require. We shall delegate this task to a separate procedure, so we can use it in different situations If necessary proc confirm print: print "Confirm (y/n)lI;
Let yes=Lower(getkey() )=lI y " cLs endproc
It leaves the variable yes containing 1 It you press the Y key - otherwise the value is zero. Note the use of the sign for assignment and also in a logical condition.
proc inquire rem ***** inqui re stock item ***** print input IlStock item?
"; name$ use "sto" find name$
Let yes=O whi Le foundO and not yes dispLay sprint confirm if not yes continue endif endwhi Le i f not found() pri nt print name$; " does not exi st" endif endproc
This procedure merely locates the correct record. A more usable procedure for interrogating the stock file IS query: proc query inquire cLear endproc
This uses another procedure, clear, which walts until you press a key, clears the screen and then prints a list of the commands you can use. We shall leave this procedure until we have written the procedures it must list. Remember to leave edit from time to time to save these procedures as you enter them.
Stock Report
We can also write a simple procedure to produce a general stock report proc report rem ***** stock report ***** c L s print tab 2; "ITEM"; tab 11; "CODE"; print tab 20; "QUANTITY"; tab 31; "PRICE"; print tab 40; "STOCK VALUE"; print
Let totaL=O use Il aLL s to" print description$( to 10);tab 11;sto.stockno$; tab 20;qty; print tab 31;1l£";seLLpr; tab 40;"£";seLLpr*qty
Let totat=total+seLLpr*qty endaLL print print "TotaL stock vaLue =£11; totaL clear endproc
12/84
USing Multiple Files
All we need to do to record a sale IS to subtract the number at items sold from the relevant stock record. It IS advisable to Include some form of confirmation that we are dealing with the right stock Item and that the stock IS sufficient to meet the order.
proe quantity rem ***** pri nt items in stock ***** inquire print
; nput "How many?
1/; num print e l s print num;1l * ";sto.stockno$;" (";sto.description$;")l1 endproc proc sa Le rem ***** process sa Le ***** quantity if num<=sto.qty
print "Order value:- E"; num*sto.seL Lpr confirm if yes let sto.qty=sto.qty-num update sprint: rem *** show the modified record *** endif else print "Not enough stock" endif clear endproc
Recording Sales
The following procedure allows you to record the delivery of stock. Again it requests confirmation of the details you type in before accepting them and updating the relevant stock record.
proc deLivery rem ***** incase stock on de Livery ***** quantity confirm pri nt if yes pri nt "Accepted"
Let sto.qty=sto.qty+num update sprint eLse print "DeLivery not recorded" endif cLear endproc
Recording Incoming
Stock
So far our procedures have only referred to the stock file. When we want to order more stock we shall have to refer to the supplier and orders files for the name and address of the company, the price, and so on.
Assuming that we have identified the Item in the stock file (with inquire) we select. from the orders file, those records that have the correct stock code. These records contain the codes for all the companies that can supply the item. Since the records also contain the price and delivery time far each supplier, we can decide whether we want the cheapest Item or the shortest delivery time.
We use locate as a fast way of finding the requrred supplier record. This means that the supplier file must be ordered (with respect to the supplier code, code$) before we use doorder.
Ordering New Stock
12184 35
36
Using Multiple Fies proc doorder rem *****order new stock ***** inquire use "ord" seLect sto.stockno$=ord.stockno$ print print "fast or cheap (f/c)";
;f Lower(getkeyO)=/lf Jl fast eLse : cheap endi f
Let ycode$=scode$ reset use II SUp ll
Locate comp$ doform print print IIExpected delivery ;s lI;del;" daysll cLear endproc
The procedure cheap finds the supplier with the lowest price, and fast works in the same way to find the supplier with the shortest delivery time.
proc cheap rem ***** f; nd cheapest *****
USe "or dl!
Let pri=pr;ce
Let comp$=code$
Let deL=deLivery aLL
;f price<pr; let pr;=price let comp$=code$ let del=deLivery endif endaLL endproc proc fast rem ***** fastest de Livery ***** use "or d ll let deL=deLivery
Let comp$=code$
Let pri==price aLL if delivery<deL
Let del=delivery
Let comp$=code$
Let pri=pr;ce end;f endaLl endproc
The procedure doform produces the actual order form. You should modify it to your own requirements. We shall use a simple version which shows the order details on the screen.
proc doform
.
rem ***** produce order form ***** c L s print print sup.coname$ print sup.street$ print sup.county$ print print sup. post codeS print "PLease suppLy "; sto.buyqty;
12/84
• c
•
print" * part number "; print ycode$ print "("; sto.description$; II) "; print "at E"; pri; " each." print print "Total value: £11; sto.buyqty*pri endproc
The tinal command that we need is one to close all the files when we have finished using them.
proc bye conti rm if yes cLs print: print "bye" cLose "s to" cLose "sup" close "ord" cLs endif endproc
We can now write a short procedure to run the application. It must open all three files with the correct logical tile names, clear the display and show you the additional commands that you have. Note that, In normal use, the stock tile is the only one whose records will need to be changed. The other two files are opened as read only files. It also orders the supplier file so that we can locale a company by its reference code.
proc start cLs print at 5,5; "STOCK CONTROL DEMONSTRATION" print open "stock" logicaL "sto" look "supplier" logicaL "sup" look lIorders" LogicaL /lord" use "sup" order codeS; a cLear endproc
Finally we can write clear, which simply clears the screen and shows a list of the extra commands available: proc cLear rem ***** clear screen and get command *****' loca L x$ print print "Press any key to continue "; let x$=getkey() cIs pri nt print "Query Report DeLiver:y Doorder Sale Bye": print print "Type in your choice" endproc
USing MlJtIJe Fies
12/84 37
38
CHAPTER 12
QL ARCHIVE
REFERENCE
VARIABLES
Variable names may be up to thirteen characters In length, and must not start with a digit (0 to 9). They may contain any combination of upper or lower case alphabetic characters, or digits. Other characters are not allowed, except for $ and. which have special meanings.
If a vanable name ends with a $ it is a string van able. Strings may be up to 255 characters
In length. If the name does not end with a $ the variable IS numeric. A variable name may reter to the contents of a record In a file and is then known as a field vanable. Field variables are normally assumed to refer to the current file but may be made to refer to another open file by Including a logical file name, separated by a . from the variable's name. Such a field variable IS written as:
logical_fi/e_name . field_name
For example main.continent$. If a vanable name Includes a dot then It must refer to a field In an open file. If there IS no dot an attempt IS made to match the name to an eXisting variable in the following sequence:
1 a field of the current file
2 a local variable (a parameter in the current procedure, if any)
3 a global variable
An error message IS given if no match is found.
SYNTAX
The termsynlax refers to the exact structure of a command or function. The syntax of a command specifies the parameters that the command needs, in what order they must appear and the symbols (if any) used to separate them.
This section describes the notation used to express the syntax of Archive's programming language.
EXPRESSIONS
An expression is a combination of literal values, variables, functions and operators which results in a single value. A numeric expression results In a numenc value and a string expression results in a text value. Examples are:
3
* y
* sin (x) + len (a$) [numeric]
"abc" + a$ + rept (" ", 5) [string]
An expression may, as in the above examples, be composed of several sub-expressions.
In such a case you may not mix sub-expressions of different types. They must all be stnng expressions or all numenc.
Syntax Conventions
The syntax definitions are similar to those used to define the syntax of SuperBASIC, i.e.:
Symbol italics
[ ]
**
I
[ ]
Meaning denotes a syntactic entity encloses an optional item encloses Items that may be repeated or comment
Syntactic Entities
slit s.exp
n.8xp
exp ptm
var
Ifn fnm pnm literal string string expression numeric expression expression, either stnng or numeric print item variable name, either stnng or numenc logical file name physical file name (up to 8 characters) procedure name
A literal stnng IS text enclosed In quotes, for example text: or 'text':
A string expression is a literal string, or a combination of literal strings, string variables and string functions that results in a text value for example:
"fred" +a$+chr(72)
12/84
Reference
A numeric expression is either a number, or a combination of numbers, numeric variables and operators (+, -, *, I, etc) that results in a numeric value for example:
(3+x) 1sin(y)
A print item is one of four possibilities: at, lab, ink, paper. A full description of a print item in our syntax notation is: prinLitem:~ I at n exp, n exp
I tab n exp
I ink n exp
I paper n exp
Logical file names and procedure names have the same restrictions as variable names.
PhYSical file names must also not exceed eight characters.
As an example of a syntax definition, consider the syntax of the order command. In our notation it appears as: order spec> var; order order spec a I d
*[ , order spec J
*
Order therefore needs to be followed by at least one order specification which Itself consists of a variable separated by a colon from a letter which must be either a or d.
In addition you can also include up to three further order specifications provided each pair IS separated by commas. Clearly the syntax notation provides a much more compact description.
Note that the syntax notation does not tell you the meaning or purpose of the symbols so you will have to read the rest of the description for each command. The syntax only gives you a formal description of the number and kind of items that go to make up a valid command. In addition the syntax notation does not tell you the maximum number of repetitions allowed for the repeated items. Order will accept up to four pairs of a variable and a letter
ARCHIVE DATA
FILES
A Field
A field Is the space reserved to hold either a string or a number.
In Archive, each field is identified by a field variable name. Whether a particular field can hold a string or a number is dependent on the name given to the field at the time it was created - string fields have a name ending with a $.
An Archive string field may hold up to 255 characters. A numeric field has a name that does not end with a $ sign.
All numbers are stored in the same amount of space, regardless of their value. The possible range for a number is the same as the valid numeric range for the arithmetic operators.
A record is a collection of fields, whose contents are related in some way. The fields of a record might. for example, be used to hold the name, the address and the telephone number of a particular person. In Archive the records are of variable length so that each record only takes up as much room as is necessary to hold the information contained
In ItS fields. There may be up to 255 fields in an Archive record.
A data file IS made up from a number of related records. To continue the above example, a data file could consist of a collection of name, address and telephone number records for many different people. The number of records in an Archive data file is limited to roughly 15 000. In practice, you are limited to the capacity of one Microdrive cartridge, which will hold about 1000 records of 100 characters. A file is the basic unit that you can save on, or load from, a Microdrive cartridge. Each file has a name to identify it.
In Archive you give a physical name to the file when it is created, but you can change the logical name at any time.
A Record
A File
When you want to read from or write to a data file you must first open it. Generally speaking, opening a data file transfers a copy of the file from the Mlcrodrlve cartridge into memory although, in the case of a long file, It is possible that only part of the file
Will be present in memory at anyone time.
You can open a data file in
read only
mode with look which, as its name suggests, means that you can not change Its contents. You also have the option of opening a data file in update mode with open so that you are allowed both to read and to change its contents.
Opening and
Closing Files
12/84 33
Reference
40
Every time you open a data file, Archive reserves space for the field variables needed by a record within the file. The field vanables always contain the values of the current record.
When you close a data file with close or qUit any changes that you have made are copied into the file stored on the Microdrive cartridge. The copy held in memory is discarded. Closing a file is the only way of ensuring that the copy on the Microdrive cartridge contains your latest version. Since an open file uses part of the computer's memory, you should not leave files open if you are not using them.
When you leave Archive with the quit command, all open files are closed automatically.
Do not turn off the computer, or remove a cartridge from a Microdrive, while the cartridge contains open files.
Logical File Names
Each open data file has an associated logical file name, given to it when the file is opened.
If you do not specify a logical file name when you open the file, it is automatically given the logical file name "main':
The logical file name is used to identify a particular file when you are using several files at once.
PROCEDURES
A procedure is a named section of program, starting with a procedure declaration of the form: ptlC pnm[; var
* [,
var]
*]
and ending with: endproc
It may be referred to by name from any other program or procedure, including itself.
It acts as though its code had been inserted at the pOint from which it IS called.
In Archive the proc and endproc commands cannot be entered directly at the keyboard, but are added automatically when you use the program editor to create a procedure.
THE PROGRAM
EDITOR
The program editor is entered using the edit command.
If there are no procedures present in memory, you will be immediately offered the option of creating a new procedure. Otherwise you are given a list of all the procedures In memory on the left hand side of the display area. The first procedure is highlighted and is listed in full on the right hand side of the display. The first line of the procedure is highlighted to mark the current procedure and the current line.
Once in edit you have five options:
Select a procedure
Press TABULATE to move down the list of procedures, press SHIFT and TABULATE to move up the list. The listing on the screen always shows the current procedure.
Select a line
Use the up and down cursor keys to select a line within the current procedure. The current line is highlighted.
Press F3 for the menu of editing commands.
There are four commands, which are selected by pressing the key corresponding to the first letter
Delete Press ENTER to delete the procedure highlighted on the left of the display.
Press any other key to leave the command without deleting the procedure.
New
Cut
Type in the name of the new procedure and press ENTER. If a procedure of that name already exists you will be offered the opportunity to edit it.
Removes text from the current procedure and transfers it to the paste buffer
Before calling this command use the up or down cursor keys to make the first
(or last) line of the region to be removed the current line. Then use the up and down cursor keys to mark the region of text to be removed. Press ENTER to remove the text into the paste buffer
Paste Copy the contents of the paste buffer into the current procedure below the current line. Paste will clear the paste buffer
12/84
Reference
Insert text
. Press F4 to insert one or more lines of text below the current line in the current procedure.
Type the text and press ENTER. Pressing ENTER without any preceeding text will leave the insert option.
Edit text
Press F5 to edit the current line of the current procedure. The line of text is copied into the input line and can be edited with the line editor Press ENTER to replace the old line with the new line.
THE SCREEN
EDITOR
The screen editor is entered with the sedit command. It allows you to design a new screen layout or modify an existing one. Once you have designed a layout you can save it on a Microdrive cartridge with the ssave command and load It with the sload command.
A screen layout is composed of two parts, the fixed background text and the variable values that are displayed in it The screen command shows the background text and the sprint command adds the current values of the variables it contains.
Sedit has two options: type text into the screen background press F3 to use a screen editing command.
There are four screen editing commands available after pring F3:
C clear the screen
V mark a region to show a variable
I - set the ink colour
P - set the paper colour.
A screen layout is made active by: sload screen
When a particular screen is active it will show the current values of its variables after sprint, or when control returns to the keyboard after executing a program (or a command).
A screen layout is made inactive by clearing the screen with cis. If there is no active screen, sprint has no effect You may only have one screen layout in the computer's memory at anyone time.
The display command creates and uses its own screen layout It will therefore replace any other screen layout with its own design.
The following commands are available.
THE COMMANDS
ALL
Scans through the logically present records of the file in the fastest possible time.
Syntax all [ lin
I : ... : endall
This scan will not, in general, be in any particular sequence. The optional logical file name will force it to refer to a specified open file. If the logical file name is not given then it will scan the current file.
The all loop is primarily designed for examining the file records rather than for changing them. Do not use update within an all loop, unless you are sure that the length of the record will remain unchanged. You may, for example, change the value of a number, or convert a text field to upper case. If in doubt, use a while loop - using the value of eof( ) to detect the end of the file. For example first while not eof() update next endwhile
ALTER
Alters the current screen layout to display the current values of the varrables.
Syntax: alter
12/84 41
Reference
42
You can change the contents of anyone or more fields of the current file whose values are shown in the screen layout Note that it is not necessary for all the field variables to be shown. You can not change a field that is not shown. If none of the field variables appear in the screen, Archive forces a display of the file.
first select the field to change by pressing TABULATE or ENTER until the cursor IS at the correct field (variables that are not fields of the file are skipped). You can then type a new value or use the line editor to modify the existing value. Press TABULATE or ENTER to move to the next field. (Pressing SHIFT and TABULATE together moves back to the previous field.)
When you have made all the changes you want, press F5 to replace the old record with the new one. The record IS replaced automatically if you press ENTER. If the file is ordered the new version of the record is inserted in sequence.
APPEND
Adds a record to the specified file, or to the current file if the logical file name is not given.
Syntax: append [ lin J
The fields of the record take the current values of the field variables.
If the file is ordered, the insertion is in sequence.
BACK
Moves backwards one record in the specified file, or in the current file if the logical file name is not given.
Syntax back
I lin J
BACKUP
Makes a copy of the specified file. You should make copies of all your files, to profect against accidental damage or erasure.
Syntax: backup oldlnm as newlnm
CLOSE
Closes the specified file, or the current file If no logical file name is specified.
Syntax close [ lin]
CLS
Clears the display area and switches off any display screen. See screen, sload, sprint.
Syntax: cis
CaNTIN UE
Continues the previous search or find, from the record follOWing the current record In the current file.
Syntax: continue
CREATE
Creates a named open file whose records contain the fields given by the list of variables specified in the command. You have the option of specifYing a logical file name if you do not the file is created with the logical file name "main".
Syntax: create Inm
I logical: lin] : var
*[ : var)
* : endcreate
DELETE
Deletes the current record from the specified file, or from the current file if no logical file name is given.
Syntax: delete
I lin J
Warning: Use this command with care since you can not recover the deleted record.
DIR
Displays a list of files on a Microdrive cartridge.
Syntax dir [ drive)
You may specify the Microdrive to be either mdv1 or mdv2.
If you do not include the
Microdrive name Archive will automatically list the files on the cartridge in Microdrlve 2.
Before showing the list of files, Archive displays fhe volume name of the cartridge (the name you gave when you formatted it).
'''''0 •
Shows the logical file name of the current file and a list of the field names and the values of the field variables for the current record. If the file is sorted, it also shows the sort fields and their sort priority.
Syntax: display
The command replaces any existing user-defined screen layout with this list, which becomes the active screen layout.
DISPLAY
Syntax: dump [ ; var ]
* I ' var)
*
Prints the speCified fields of the selected records of the current file in tabular form ser1 output. If you do not give a list of field variable names, all the fields are printed.
You can divert the output to a Microdrive file with spoolon.
DUMP
Calls the procedure editor to create a new procedure or to edit an existing procedure.
Syntax: edit
EDIT
See all.
ENDALL
See create.
ENDCREATE
Syntax: error pnm[ ; exp
* [ , exp
1*
J
Marks a procedure for the purposes of error-handling. Any error which occurs during the execution of this procedure, or any other procedure which it calls, causes a premature return from the marked procedure. The procedure can determine the nature of the error by using the errnum( ) function to read the error number. This error number is cleared each time that error is executed.
ERROR
Saves the named fields of the selected records of the current Archive file on a Microdrive cartridge In a form suitable for Import to QL Abacus or QL Easel.
Syntax: export fnm [ ; var]
* [ .
var]
*
[quill ]
If you do not specify a list of field variable names, all the fields are exported. If you include the optional parameter quill, (separated by at least one space from the last variable name) the file is exported in a form suitable for import by QL Quill.
The export file is named fnm and, unless you specify your own file name extension.
Archive uses the extension _EXP.
See the Information seclion for a full discussion of Import and export.
EXPORT
Rewinds the file to the beginning and searches for the first record containing a match to the specified string in any string field. The match is independent of upper or lower case text.
Syntax: find s.exp
You can continue the search with the continue command, and determine whether the search was successful by examining the value returned by the found( ) function.
FIND
Finds the first record of the specified file. or the current file If no logical file name is specified.
Syntax: first [ Ifn
I
FIRST
Formats the cartridge in Microdrive 2 (the right hand drive). It gives the cartridge the name you speCified. This name is reported when you subsequently use dir to show a directory of the files on that cartridge.
Syntax: format "you specified"
FORMAT
12/84 43
44
IF
Allows a specified condition to control sUbsequent processing.
Syntax: if nexp : [: else : .. ] : endif
Without else.
If the expression IS non-zero, the following statements are executed. If the expression is zero execution transfers to the statement following endi!.
With else.
If the numeric expression is non-zero, the statements between if and else are executed. Otherwise the statements between else and endif are executed. In either case execution continues with the statements following endif.
IMPORT
Reads a file, name!, exported from QL Abacus or OL Easel and produces an Archive data file name2.
As with open and look you have the option of specifying a logical file name for the data file.
Syntax: import name!
as name2 !logical
Ifni where: name!: = fnm name2:= fnm
See the Information section for a full description of import and export.
INK
Sets the foreground colour for all following text to the colour specified by the value of the expression.
Syntax: ink nexp
The colours are: 0 and 1 black
2 and 3 red
4 and 5 green
6 and 7 white
If the expression evaluates to more fhan 7, the value taken is the remainder after division by 8, for example ink 9 is equivalent to ink I, both setting the print colour to black.
ij
Ink is used within a print command it will only change the print colour for the duration of that command.
INPUT
Requests input from the keyboard to the variables listed in the command. Each variable in an Input list may be preceded by a initial string which will be displayed as a prompt for the input All Input items must be separated from each other by semicolons. If the list has a final semicolon, the cursor will not move to a new line after the input
Syntax: input [ var
I s./JI
I ptm * [ ; var
I slit
I
ptm ] *][ ;
I
The list of input Items may include the cursor-positioning items at tab line,column column where: Itne:=nexp, column:=n.exp
The first of these positions the cursor at the specified line and column position, and tab moves the cursor to the specified column within the current line. If the cursor is already to the right of the specified column, tab will have no effect
These two items may not be used outside an input or a print command.
You may also use ink and paper as input items. If used within an input command they will only affect the ink and paper colours to the end of the input, when the colours will return to thelf original settings.
INSERT
Adds a new record 10 a liIe.
Syntax: insert
Uses the current screen layout to display the current values of the variables. You can type a new value for anyone or more fields of the current file whose values are shown in the screen layout Note that it is not necessary for all the field variables to be shown.
You cannot type a value for a field that is not shown.
ij none of the field variables appear
In the screen, Archive forces a display of the liIe.
12/84
First select a field by pressing TABULATE or ENTER until the cursor is at the correct field (values that are not fields of the file are skipped). You can then type a new value.
Press TABULATEor ENTER to move to the next field. (Pressing SHIFT and TABULATE logefher moves back to the previous field.)
When you have typed all the values you want you should press F5 to add the new record to the file. The record will also be added to the file if you press ENTER when the cursor is in the last field. Any field that you have not given a value will be zero (if it is a numeric field) or an empty string (if it is a text field). If the file is ordered, the new record is inserted in sequence, otherwise the Insertion takes place at an unspecified position.
Erases the specified file from the Mlcrodrive cartridge.
Syntax: kill Inm
Warning: Use this command with care since you cannot recover the erased file.
Lists all the procedures currently in memory on a printer
Synlax: /tist
KILL
Finds the last record of the specified file, or the current file if you do not specify a logical file name.
Syntax: last
I lin]
LAST
Used to assign a value to a variable (as in SuperBASIC).
Syntax: let
var
=
exp
LET
LUST
Loads the specified procedure file from a Microdrive cartridge into memory.
Syntax: toad ( object ] Inm
If you Include the optional object Archive will expect the file to be In binary rather than
ASCII form, see save.
Within a procedure, forces the following list of variables to be local variables. These variables exist only within the procedure in which they are declared and are undefined in any other procedure Their values are destroyed on exit from the procedure.
Syntax: local
var
*
f ' var]
*
LOAD
LOCAL
Finds, In an ordered file, the first record whose field contents match the expression(s).
Syntax: locate
exp
* I
,exp 1
*
The record IS located much more quickly than if you used find, but the file must first have been sorted. Each expression must explicitly refer to the contents of a particular sort field. In the case of a string field the match is case-dependent.
If you have ordered the file With respect to more than one field, you can specify several expressions (one for each sort field).
The expressions are separated by commas and must refer to the fields used to order the file. They must be in the same sequence as in the preceding order command. For example: order animat$ ; a ,
weight;
a
locate "Elephant" , 2000
will find the first record in which the field animal$ contains the text "Elephant" and a weight that equals (or exceeds) 2000.
If there is not an exact match locate will still find a record. This record will be the first one whose field contents "exceed" - in the sense of the ordering (i.e. "d" comes after
"e' if the file IS sorted in descending order) - the specified values.
LOCATE
Opens the named file for read access only. If the logical file name is not specified, It
IS given the default value "main':
Syntax: look Inm
I logical lin J
LOOK
12184 45
46
LPRINT
Displays the values of the following list of items on a printer attached to SER1, in the same way as for llist.
Syntax: Iprint [ exp
I ptm
* [ ; exp
I ptmJ.
J
L]
MERGE
Adds the procedures of the specified program file to the procedures already in the computer's memory. If the file contains a procedure with the same name as one already in memory, the new procedure replaces the old one.
Syntax: merge [ object
I
Inm
If you include the optional object Archive will export the file to be a binary rather than
ASCII format. See Save.
MODE
Changes the form of the display.
Syntax: mode var, var
The first variable may have a value of 0 or 1. A value of 0 joins the control, display and work areas into a single region. A value of 1 separates them back into three distinct areas.
The second variable may have a value of 4, 6 or 8 and switches the display between showing 40, 64 or 80 characters per line.
The initial setting, when you load Archive for use with a monitor, is equivalent to: mode 1,8
NEW
Deletes all the data from the computer's memory, ready for a fresh start. Any open files are closed. (The command does not delete files stored on a Mlerodrive cartridge.)
Syntax: new
NEXT
Moves to the next record in the specified file, or In the current file if you do not specify a logical file name.
Syntax: next [ lin
I
OPEN
Opens the specified file for both reading and writing. The file is given a logical file name
"main" if you do not specify one.
Syntax: open Inm [logical lin )
ORDER
Orders the records of the file according to the contents of the specified fields.
Syntax: order order_spec
*[ , order_spec
I * where: order_spec: ~ var; a I d
The first field specified in the list is the primary sort field. Records which have equal contents of their primary sort field are further sorted according to the contents of the next field in the list (if it is specified) and so on. For each specified field an ordering direction must be given.
This must be either a or d to specify ascending or descending order respectivefy.
Order only takes account of the fICst 8 characters of a text field and you may not specify more than four fields to order the file.
PAPER
Sets the background colour for all following text to the colour specified by the value of the expression.
Syntax: paper n.exp
The colours are: o and 1 black
2 and 3 red
4 and 5 green
6 and 7 white
12/84
Reference
If the expression evaluates to more than 7, the value taken is the remainder after division by 8, i.e. paper 11 is equivalent to paper 3, both setting the colour to red.
If paper is used within a print command, it will only change the background colour for the duration of that command.
Makes the record whose record number is given by the expression the current record.
Syntax: position nexp
POSITION
Displays the values of the following list of items - which must be separated by semicolons
- on the screen. If the list has a final semicolon, the cursor will not move to a new line after the display See also Iprint.
Syntax print [ exp
I
ptm ] *[; exp [ ptm
1 *] [ ; ]
Closes all files and returns to SuperBASIC.
Syntax: quit
QUIT
When used within a procedure, it marks the rest of the line as containing a comment.
Any following text on that line is ignored when the procedure is executed.
Syntax: rem
REM
This command restores all the records in the current file which were removed by an earlier use of select. It destroys any ordering of the file.
Syntax: reset
RESET
Used Within a procedure to cause an immediate termination of the procedure to the calling procedure.
by returning
Syntax: return
RETURN
Loads the specified procedure file into memory and starts execution of the procedure called start.
Syntax: run [ object] fnm
If you include the optional object Archive will expect the file to be in binary rather than
ASCII form, see save.
Saves all procedures currently in memory as a single named file on a Microdrive cartridge.
Syntax: save
I object] fnm
If you include the optional object, Archive will save the file in binary, rather than ASCII, torrnat. This means that Archive does not have to convert the program into ASCII characters before saving it and is therefore much faster You can load, run or merge such a program by adding the optional object to the appropriate command. These operations will also work more rapidly since no conversion is necessary. Such files have an extension of _pro, rather than the normal prg.
You may also save such an object program in a form that is protected against examination or modification. Include, instead of object, the optional protect. A program saved in this way can only be loaded, run or merged - using the optional object with the appropriate command.
A protected program cannot be listed, edited or saved. If you merge a protected program with any other program then the combination will be similarly protected. The only way to clear the protected status is with the new command.
Saving a protected version does not affect the copy of the program in the computer's memory. You can stHl list, edit or save the program in the normal way.
Displays the formatted screen layout previously sloaded. It does nothing If there is no screen layout present. It does not display any of the variables in the screen.
Syntax: screen
RUN
SAVE
SCREEN
12/84 47
48
SEARCH
Searches the current file from the beginning until a record is found in which the specified expression is true. This record becomes the current record.
Syntax: search n.exp
SEDIT
Calls the screen editor-to enable you to define a new screen layout. See Chapter 1
SELECT
Scans the whole file selecting only those records for which the speCified expression is true. The file then behaves as if only the selected records are present.
Syntax: select n.exp
You can restore all the discarded records with the reset command.
SINPUT
Waits for input to the variables in the following list, using the order specified in the list.
All the variables in the list must be currently displayed in an active screen layout.
Syntax: sinput var
*
I,
var ]
*
SLOAD
Loads a previously defined and saved display screen layout. It also displays this screen layout and activates the display of any variables within the screen.
Syntax: sload fnm
The displayed values are then updated automatically whenever control returns from a procedure to the keyboard interpreter
SPOOLOFF
Direct all following Iprint and lIist output to the printer This cancels the effect of spoolon.
Syntax: spooloff
SPOOLON
Directs all following Iprint, IIlst and dump output to the specified file - or to the screen
- Instead of to the printer
Syntax: spoolon
<
fnm or: spoolon screen
> [
export I dumpj
If you are directing output to a file, it IS directed via the currently installed printer driver so that it contains all the special codes that your printer needs.
If you include the optional export, Archive ensures that the file contains only printable
ASCII codes, carnage refurns and line feeds. The resulting file is suitable for importing into Quill
The optional dump allows the text to be transmitted to the file without being processed by the printer driver In this case all ASCII codes (Including control codes) are passed straight into the file.
Unless you specify a file name extension, Archive assumes an extension of _lis (_exp or _dmp if you include the optional export or dump).
The alternative form of the command - spoolon screen - directs the output to the monitor screen instead of the printer.
SPRINT
Used within a procedure to force a display of the fields of the current record.
Syntax: sprint
There must be an active screen layout (the screen layout is made active by a previous use of screen, sload or display). If there IS no active screen layout, the command will have no effect.
SSAVE
Saves, as a named file on a Microdrive cartridge, the current display area as a defined screen layout.
Syntax: ssave fnm
It saves the text of the screen and a list of the variables in the display, together With their positions.
STOP
Terminates the execution of all procedures and returns control to the keyboard.
Syntax: stop
12/84
Switches the trace mode on and off.
Syntax: trace
Type: trace to turn on the trace. In trace mode each line of the program is displayed in the work area of the screen, as it is executed. Press the space bar and keep it held down to pause. The trace will continue when you release the space bar. To turn the trace off again, type: trace
TRACE
Replaces the current record in the spedfied file (or the current file if no logical file name is given) with a record containing the current values of the field variables.
Syntax: update
I lin ]
UPDATE
Makes the specified file the current file.
Syntax: use lin
USE
Repeatedly executes the statements between while and endwhile for as long as the value of the expression is non-zero (true).
Syntax: while nexp: : endwhile
Think of a function as a kind of recipe which converts one or more initial values, known as the function's arguments, into a different value, which is said to be the value that is returned by the function.
The functions provided by Archive may take three, two, one or no arguments. The arguments for a function are placed in brackets after its name. You must not leave a space between the name and the opening bracket, but spaces are allowed between items within the brackets. If a function takes more than one argument, the arguments are separated by commas. All functions must be followed by the brackets, even if they take no arguments. The presence of the brackets is a useful reminder that you are referring to a function. They allow you to distinguish between a variable and a function, even if they have the same name.
The following functions are provided.
ABS(nexp) Returns the absolute value of the argument, i.e. ignores any minus sign.
ATN(n.exp)
CHR(nexp)
Returns the angle, in radians, whose tangent is nexp.
This function returns the ASCII character whose code is nexp. A character with an ASCII code less than 32 is only sent to the printer
If preceded by an ASCII null. For example:
Iprint chr(O)+chr(13) passes the ASClf character for a carnage return to a printer ThiS is useful if your printer needs control code sequences to produce special effects - refer to your printer manual for any special codes that it needs.
You can, for example, send an ':4" to the screen with: print chr(65).
CODE(s.exp)
COS(nexp)
COUNT([lln J)
DATE(nexp)
This returns the ASCII value of the first character found in the specified text.
Returns the cosine of the given (radian) angle.
Returns the count of the number of records in the current file
Returns today's date as a text string in one of three forms: n.exp
o
1
2 date string
'YYYY/MM/DD"
"DD/MMIYYYY"
"MM/DDIYYYY"
WHILE
FUNCTIONS
12/84 49
Reference
50
DAYS(s.exp)
You must first have set the system clock, as described in the
SuperBASIC Keyword Guide.
Returns a number of days, from the first of January 1583, to a date given as a text expression of the form ''YYYY/MM/DD': The conversion assumes the Gregorian (modern) calendar IS being used. The formula is therefore only valid for dates after 1582.
DEC( va/ue,dp,width) value: ~(n.exp) dp.~ (n.exp) width.
~ (n.exp)
Converts the given numeric value to the equivalent text string, in deCimal format with dp deCimal places. The text is Justified right in a field of width characters. For example: dec(1.23e1,3,10) returns the text" 12.300" (with 4 leading spaces).
DEG(n.exp)
EOF([ lin])
Takes an angle, measured in radians, and converts it to the same angle in degrees.
Returns a value Indicating whether you have attempted to read past the end of the current file, or the specified file if a file identifier is given.
The value returned is 1 if you have attempted to read past the end of the file, otherwise it IS zero.
ERRNUMO
EXP(n.exp)
Returns the number of the last error which occurred (an error number of zero indicates no errors). The error number is the same as that displayed together with the error message when Archive reports a detected error
Returns the value of e (approximately 2.718) raised to the power of
(n.exp).
The returned value will be In error if n.exp
is greater than +88 since the result will then exceed the numeric range of Archive.
FIELDN(n.expl.
Ilnl)
Returns the name of the specified field in the current record of the specified file (or the current file if no logical file name is given). Note that fieldn(O) returns the name of the first field.
FIELDT(n.exp [, lin ])
Returns the type of the specified field in the current record of the specified file (or the current file if no logical file name is given). Note that fieldl(O) returns the type of the first field.
It returns the value 0 If the field is numeric, otherwise it returns 1.
FIELDV(n.exp[, lin j)
Returns the value of the specified field In the current record of the specified file (or the current file if no logical file name is given). Note that fieldv(O) returns the value of the first field.
.
FOUNDO Returns one if a record is found by use of search or find, otherwise returns zero.
GEN(value,width) value: =n.exp
width.=n.exp
GETKEYO
INKEYO
Converts the given numeric value to the equivalent text string, in general format. The text is Justified right in a field of width characters. For example: gen(1.23e1,10) returns the text" 12.3" (with 6 leading spaces).
Walts for a key to be pressed and returns a Single text character which corresponds to the key that was pressed.
Returns the single text character corresponding to any key that was being pressed at the time the function is called. It does not wait for a keypress, but will return a null string ( "" ) if no key is pressed.
12/84
INSTR(main,sub) main:
= s.exp
sub:= s.exp
INT(nexp)
This finds the t"st occurrence of sub within main and returns the position of the first character of sub in main. It will return a value of zero if no match is found. The m"tch is case-dependent.
i nst r ("January", "Jan") instr(IIJanuary","an") ins t r
(/I
Jan ua r y" ,
II
AN" )
!returns 1)
(returns
[returns
2}
OJ
Returns the integer vatue of the number, by truncating at the decimal point. The truncation always operates towards zero. Thus; i nt (3.7) int(-4.8)
[returns 3)
[returns-4]
LEN(s.exp)
LN(nexp)
LOWER(s.exp)
Returns the number of characters in the specified text.
Returns the natural, or base e, logarithm of n.exp. An error results if n.exp is negative or zero, since logarithms are not defined in this range.
Converts the specified text to lower case.
MEMORY( )
MONTH(nexp)
Returns the number of unused bytes of memory remaining.
Returns, as text, the name of a month.
For example monlh(3) returns the text "March';
If an argument larger than 12 is used, it is replaced by the remainder after division by 12 so that. for example, month(13) and month(1) will both give the result 'January':
NUM(value, Width) value> nexp width> nexp
Converts the given numeric value to the equivalent tex1 string, in integer format. The text is justified right in a field of width characters. For example: num(1.23e1,10) returns the text" 12" (with 8 leading spaces).
NUMFLD([ lin J) Returns the number of fields in the records of the specified file (or the current file if you do not give a logical file name).
PIO
RAD(nexp)
Returns the value of the mathematical constant 7t.
Takes an angle, measured in degrees, and converts it to the same angle in radians.
RECNUM([ Ifn J) Returns the number (counting from zero at the t"st record) of the current record of the speCitied file (or the current file If you do not file name).
give a logical
REPT(s.exp,nexp)
This function returns a string consisting of a number of copies of the first character of the given text. The resulting text may be up to 255 characters in length. For example, print rept("*",S) print rept(ll a bc",3)
[will print five asterisks)
[prints "aaa")
SGN(nexp) Returns +1, -1 or 0, depending on whether the argument is posilive, negative or zero.
SIN(nexp)
SQR(nexp)
Returns the value of the sine of the specified (radian) angle.
Returns the square root of the argument. which must not be negative.
STR(n,type,dp) n: = nexp type: = n.exp
dp:=nexp
Converts a number, n, to the equivalent text string.
12184
Helerence
51
52
TAN(n.exp)
TIME( )
UPPER(s.exp)
VAL(s.exp)
VALUE(sexp)
The second parameter, type, Indicates the torm of the converted string as follows; a decimal (floating point)
1 exponential, or scientific, notation
2 integer
3 general format
The third parameter dp, indicates the number of figures after the decimal point in the converted string. It should always be specified, although its value is ignored for integer and general formats.
For example: let a$=str<12.3456,O,2) let a$ str(12.3456,1,4)
[gives a$ the value '12.35")
Iglvesa$thevalue'I.2346e1"j
Returns the tangent of the specified (radian) angle.
Returns, as text, the time of day in the format "HH:MM:SS': You must first have set the system clock, as described in the SuperBtlSIC Keyword
Guide.
Converts the specified sl(lng to upper case.
Converts the text to its equivalent numeric value. It will only convert text composed of valid nume(,c characters and the conversion will stop at the first character that can not be interpreted as a digit For example, val("1.1ABC") will return the numeric value 1.1, and val(''''BC'') will return
0.0
Returns the value of the variable whose name is given by s.exp for example: let a$="ten" let length=15 print vatue(a$+' 'gth '
I ) will print the value 15.
Note that value(fieldn(y)) is exactly equivalent to fieldv(y).
ERRORS
When ARCHIVE detects an error in a command typed at the keyboard or in a procedure, it displays an error number and a short error message. Examples of errors that would be detecfed are: attempting to divide by zero if not matched with an endif supplying a procedure with the wrong number of parameters.
If the error comes from keyboard input, the text of the statement remains visible In the work area. You can press F5 to recall the text so that you can use the line editor to correct the error You can then press ENTER to execute the corrected statement
If the error comes from a program statement, ARCHIVE shows the name of the procedure and the line in which the error occurred. You can then use the program editor to correct the error
When you use the error command In your programs, ARCHIVE will not report any error that it detects In a procedure marked with error. You are free to deal with any such error in any way that you want (including ignoring it). You can find which error has occurred by examining the value returned by errnum(). This number IS the same as the one
ARCH IVE gives when it prints an error message.
The following list shows ARCHIVE's error numbers, together with the corresponding messages Where possible, the list includes a short exam pie of a statement that would give the error The error messages are not designed to pinpoint the precise error, but are intended to g·,ve you an Idea of what type of error to look for
Those error messages for which there is no short example are marked With an asterisk.
They are dealt With in the notes which follow the list
12/84
Reference
No.
o
93
94
100
101
103
104
105
76
77
78
80
90
91
3
4
1
2
5
6
7
8
9
18
50
51
52
53
70
71
73
74
75
10
11
12
13
14
15
16
17
Message no error command not recognized end of statement expected variable name expected unrecognized print item wrong data type numeric expression expected string expression expected variable not found variable undefined missing separator name too long duplicate name string literal expected mi ss i ng endproc bad proc statement premature end of statement program structure fault too many numbers missing closing quote mi ssing exponent after liE" number too bi g unknown symbo l evaluator syntax error mismatched parenthesis type mi smatch wrong number of arguments string too long dlvide by zero bad function arguments string subscript error out of memory no room to open a fi le incomplete fi le transfer out of range file not open cannot open file write to read only fi le wrong file type bad fi le name error reading fi le
Example apend let x=3 let y=4 let 31=x print create
• (1) let x="fred" let x$=4 let x=qq (qq undefined) prj nt qq print at 5 let thisverylongname=4 create:n$:n$:endcreate
(2)
• (3)
• (3) createl/test":endcreate
• (4)
• (5) let x$="f red let x=1.2E
let x=1.2E100
let x=% let x=3+ let x=(3+5) /7> let x$= lI fred"+3 let x$=str(1,2) let x$=rept ("*",256) let a=O: let x=5/a let x$=sqr(-4) let x$="fred" (to 97)
(6)
• (7)
• (8) print at 100,100;37 append (without tirst opening a file) loa k"x xx" (non-existent) look
II names": insert s load"names ll (data file) save"3test"
• (9)
1) The most likely cause of error 5 - 'wrong data type" - is that you have inputted text when a number is expected, e.g. in response to an input statement such as:
; nput
X
2) Error 13 - "string literal expected" - can occur, for example, during the import of a file that you have constructed yourself (without using any of the export commands in the OL programs). If means that Archive has found a numbe( or a numeric or fext expression, where it was expecting to find a literal text value.
In mosf situations where Archive finds numeric data when expecting text, or vice versa, It will give error 7 or error 8.
3) Errors 14 - "missing endproc" - and 15 - "bad proc statement" - should never occur in normal use. They Indicate that Archive has detected a missing endproc or an error In the structure of a proc statement In a procedure. They are only I'lkely to occur if you construct a program file with an editor other than the one included in Archive.
4) Error 17 - "program structure fault" usually indicates that an all, if or while is not paired with a corresponding endall, endif or endwhile in a procedure. You
Notes
12/84 53
54 can also generate this error by including an endproc inside another program structure, or by using return directly from the keyboard.
5) Error 18 '100 many numbers" - indicates that you are trying to input more numbers than
will
fit Into the memory reserved for input. The error may occur either in a line of input from the keyboard, or while loading a program that includes a procedure with many numbers
in
one of its lines. The exact limit depends on circumstances - a typical limit would be 15 to 20 numbers, so you are unlikely to get th is error.
6) Error 80 'but of memory" - should only be given if you use a very large program
The size of an ordinary data file is not limited by the amount of memory in the computer since only part of a large file is in memory at anyone time. If Archive gives you this error you will have to reduce the size of your program before continuing. You can, if necessary, break your program into several sections, in different files, and use merge to load each section as it is needed. This technique will, however, normally need a considerable amount of programming skill.
7) Error 90 "no room to open a file" - occurs when the area of memory Archive reserves to store internal information about the files currently In memory becomes full. This may happen even if there is still memory available (i.e. if the value returned by memoryO is still not close to zero.)
8) Error 91 - "incomplete file transfer" - means that the loading or saving of a file has failed for some reason. This may mean that the data has been corrupted, or that the cartridge or the Microdrive has been damaged.
9) Error 105 '\mor reading file" - means that some of the data in a file is in the wrong format. the wrong order, or has been corrupted. This is only likely to occur
If you construct your own import file - or your own program file without using the Archive program editor (advanced uses).
12/84
©1984 PSION LIMITED by Dick de Grandis-Harrison (Psion United)
5iinclair
QL
QL Easel
QL Easel is fully interactive, which means that you see the results of everything you do immediately. From the moment you start you can just type in a series of numbers and see them displayed as a graph, as you type them In. You never need to worry about building up tables of values; Easel takes care of that kind of thing for you, and keeps them where they should be - out of Sight.
You can add text to the graph just as simply as you enter data and, once ',t is there, you can edit it or
move
it around (easily, of coursel.) until you are satisfied with the result.
Easel is organised in a series of levels and exhibits a pyramidal structure. The top level, which IS immediately available when you start, allows you to do the most commonly needed operations, for example, entering data or text. The full power of Easel becomes apparent as you become more familiar with it and dig more deeply into the pyramid.
Despite this powe( Easel still remains simple to use at all levels. You do not need to remember lots of numbers and commands, since you are guided through each process by a carefully designed sequence of prompts which explain what you can do at each stage. In particula( Easel has a design by example facility which allows you to select or des'lgn anything from a single line or bar to a whole graph, simply by choosing from a set of pictures. With this facility you need never be in any doubt as to what the final appearance of your graph will be.
If, af any time, you are not sure what fa do, remember thaf you can ask for Help by pressing F1 . Also remember that you can cancel any partially completed operation by pressing ESC.
CHAPTER
1
ABOUT
QL EASEL
12/84
2
GETTING
STARTED
LOADING QL EASEL
Load QL Easel as described in the Introduction to the QL Programs. When loaded Easel will display the following message:
LOADING QL EASEL
Copyright version x.xx
© 1984 PSION SYSTEMS business graphics where x.xx is the version number, e.g. 1.04.
Easel will, from time to time, read more information from the Easel cartridge. You must not take the cartridge out of Microdrive 1 until you have finished using Easel and returned to SuperBASIC,
APPEARANCE
When you have loaded Easel the display should look like that shown in Figure 2.1. The display is divided into three main areas, known as the status area, the display area and the control area.
HELP press F1
PROMPTS press F2
NUMBERS Use
TABULATE Key to move wire type number
X-WIRES move t wi th
<-- ......
keys (
TEXT fORMULAE type" Enter then text directly
COMMANDS press f3
ESCAPE press ESC
Ti t Ie lO-
A
!
1
S
5 -
2
0 -
Jan feb Mar Apr May Jun Jul Aug Sep Ocl Nov Dec
Ax i 5 1
'0 formal 1 Rep BAR 1
Current Name figures
Figure 2.1 The main display
12K Memory
The Status Area
The format tells you how the values you type in will be shown, There are eight different display formats (numbered 0 to 7) to choose from, pre-defined to give an assortment of bar, line and pie chart displays. Initially, the format is set to give you a bar graph display
(format 0).
You are also told the name of the set of data (or figures) for your graph. If you have more than one graph there will be a named set of figures for each graph. The current set of figures is the set that is changed when you type in numbers.
In addition you are told the style which will be used. Easel can show a set of figures in one of three different representations as-a bar graph, a line graph or a pie chart.
Easel initially selects a bar graph representation and uses bar number 0 (there are 16 different bar designs ready for you to use).
12/84
The amount of memory available at any time is displayed in the status area together with
error messages
when necessary.
BDDDDB
Getting Started
Figure 2.2 The status area Figure 2,3 The display area
All graphs produced by Easel are shown in the display area.
Initially, there is an empty bar graph in the display area marked with a grid of horizontal and vertical lines. The horizontal lines correspond to the values shown on the vertical axis (Axis 2) and the vertical lines divide the graph into cells. Each cell marks the position where one value of a set of figures will be plotted.
Each cell has a cell label, along the horizontal axis (Axis 1). Easel automatically supplies the text ':Jan': "Feb" and so on, up to "Dec" for cell labels but you can change the text to anything you want.
Think of each set at figures as a row of cells, each containing one of the values to be plotted.
The Display Area
B DB
Figure 2.4 The control area Figure 2.5 The crosswires
The control area shows the normal options: Help (F1), to turn the prompts on and oft
(F2) , to select a command (F3) and to cancel an incomplete selection (ESC). In addition, there are four options that are specific to Easel. These are: move the crosswires, type in a number, fype in text, type In a formula,
Press the light cursor key and hold it down briefly. You will see the vet1/cal crosswire moving across the screen, from left to light. The left and right arrow keys move it across the screen.
The up and down Cursor keys move the horizontal crosswire.
The Control Area
THE CROSSWIRES
12/84 3
Getting Started
You can indicate any point in the display area by moving the interseclion of the crosswires to that point
In addition, the vertical crosswire marks the position in the graph where a number that you type in will be plotted.
If the crosswires are not visible press any cursor key; press either the left or the right cursor key to display the vertical crosswire, and either the up or down cursor key to show the horizontal crosswlre. Note that you can only do this from the main display, and not from the command menu.
If you press a cursor key and release it immediately the crosswire will move a short distance in the appropriate direction, but if you hold the key down the crosswire will move more rapidly across the display area.
NUMBERS
Type In a number (and then press ENTER). It will be displayed immediately on the graph, at the current position of the vertical crosswire. The crosswire will move one cell to the right, ready for the next number
Each time you type in a number that exceeds the range of values shown along the vertical axis, Easel will redraw the graph with a scale that allows the new value to be shown.
If you press TABULATE, you will find that each press of the key makes the vertical crosswire move to the right by one cell. Hold down SHIFT and press TABULATE, and the vertical crosswlre moves left by one cell. The position of the vertical crosswire marks the current cetl - the cell that will show the next number you type in.
If you put an incorrect value into your graph you can correct it by moving the vertical crosswire to the cell where the mistake appears and typing in the correct value.
If you spot a mistake before you press ENTER you can correct it by using the line editor.
Alternatively you can cancel the number by pressing ESC and then typing in the correct value.
Whether you move the crosswire with TABULATE or with the cursor keys, the next value you type in will always be shown in the cell containing the vertical crosswire.
TEXT
You can add text to your graph by typing a double or single quotation mark (' or ') as the first character of your input.
The crosswires will appear (if they were not al ready visible) and any following text that you type In will be written in the display area starting at the intersection of the crosswires and in the Input line. Press ENTER when you have finished.
If the text IS not In the exact position you want, move It using the cursor keys. The crosswires will move across the screen, carrying the text with them. When the text is in the position you want, press ENTER and the crosswires will disappear
FORMULAE
A formula can be used to create a new set of figures, or to change an existing set.
Easel interprets any keyboard input that does not start with a numeric digit or quotation marks as a formula. For example, we can change the current set of figures (WhiCh, as you can see from the status area, has the name '~igures').
figures == figures + 2 ENTER
The new graph is similar to the old one, except that each value has been increased by 2. If you want to return to the original graph you can type In another formula: figures; figures 2 ENTER
A formula always starts with the name of a set of figures. This name could be the name of an eXisting set or It could be a new name. In either case the contents of that data set are defined by the expression to the right of the equals sign in the formula. It is important to realise that the formula will affect all the values in the set, rather than just one value.
THE COMMANDS
The commands allow you to use some of the more sophisticated aspects of Easel. Press
F3 to select a command. The contents of the conlrol area will change to show a list of the available commands - the command menu.
4 1?/Rt1
Getting Started
HELP press Fl
PROMPTS press F2
COMMANDS Fi tes
Change Highl ight
Newdata
Olddata
Defaults Ki II
Edit load
Quit
Rename
Save
View
Zap
Title
10 s
I
A
X
2
5
-
0
Jan Feb Mar Apr May Jun Jul Aug Sep
AXIS 1
Oct Nov Dec
COMMANDS press f3
ESCAPE press ESC
command >
Format 1 Rep BAR 1
Current Name figures
Figure 2.6
The command menu.
12K Memory
When the command menu IS displayed you can select a command by typing its first letter
For example, the Quit command leaves Easel and returns to SuperBASIG Select ',t by pressing F3 and then Q. Easel gives you the option to press ESC to stay in Easel (in case you selected the command by mistake). If you decide you really do want to leave
Easel, you press ENTER.
You cannot type in a number to a cell or type in a formula when the command menu is visible. Also, you cannot move the crosswires, except when given this option as part of a command.
At the end of a command, Easel remains in the command menu and you must press
ESC to go back to the main display.
You can delete a value from the graph Use the TABULATE key (or the SHIFT and
TABULATE keys) to position the vertical crosswire on the number you want to rub out and then press F4. If your graph is showing more than one set of figures, pressing F4 deletes all values shown in that cell. It has no effect on sets of figures that are not shown.
If you delete the values from a cell that has no label, then that cell will not be included in the graph when it is next redrawn.
Easel will only delete a cell that has no label and no value. If you want to delete a cell you should delete its contents and also delete any label that it has. The cell will not be
Included next time the graph IS redrawn with the View command.
You can insert a new value to the right of the one marked by the vertical crosswire. Press
F5 and a gap IS opened up, ready for you to type in a new number The new cell will not have a label, but you can add one.
Inserting and deleting values from pie charts is slightly different and is explained in Chapter
9.
DELETING AVALUE
INSERTING AVALUE
12/84 5
6
CHAPTER
DESIGNING
3
A BAR
This chapter show.; how you can modify the appearance of your graph by using a different design of bar.
All the options to modify the various features of the graph work in the same way Learning how to change your graph to use a new bar design explains the methDds you will use tD change any Dther aspect Df the graph.
We assume that YDU have typed in a few numbers and have a bar graph shDwn Dn the screen.
SELECTING ABAR
You use the Change cDmmand tD select a different bar, F3 and then the C key. YDU are Dffered many DptlDns - tD change an Axis, Text, and so Dn. Select the Bar Dption by pressing the B key.
There are two routes tD using a new style Df bar~select'IDn by number or by example.
Selection by Number
When YDU have selected the Bar DptiDn, the input line shows the text:
COMMANO>Change to BAR 7 and Easel waits for YDU tD type In a number. There are to 15
16 different bars, numbered 0 and you can select any Dne Df them by typing its number. fDllowed by ENTER.
This is a very quick methDd Df changing the bar you use, prDvided you know the number
Df the Dne you want.
Selection by Example
If YDU do not knDw the number Df the bar, or you want to use YDur Dwn design, press
ENTER, instead of typing a number. Try this method by typing in
ITII
C B
I
EN I ER
I
(YDU dD nDt have tD press F3 il you are still in the cDmmand menu.) The display changes tD show examples of all the available bar styles, tDgether with their assDciated numbers.
The selected bar is surrounded by a box. YDU use the left and right cursor keys to move this bDx from bar tD bar until it is pDsitioned on the one you want. When you press ENTER the bar you have chDsen will be used.
HELP press f1
PROMPTS press
F2
SELECTION
Move the box cursor with the"'-f keysandpress ENTER. For a new design select the last (?).
COMMANDS press f3
ESCAPE press ESC
I
-
.......-
••••.
~
••.
-
LC.
Easel Bars
10~10~IGiIGIIBI
Your Bars
11
~ormat
1 Rep
BAR 1
Current Name figures
Figure 3.1 Selecting a bar
12K Memory
I .
12/84
When you use the option to select by example you will notice that there is one bar present in the second row, which shows a question mark in place of its number You select this bar if you want to make your own design.
Position the selection box on this bar and then press ENTER. The design by example continues by presenting you with a blank bar design and a list of options.
BAR DESIGN
HELP press f1
PROMPTS press f2
DESIGN Use 11 keys to select design option and press ENTER.'Use ~ ~ keys to select colour then press ENTER.
COMMANDS press f3
ESCAPE press ESC
Fill colour
Border colour
Border thickness
Satrsfled command) Change to Bar?
Gl format 1 Rep BAR 1
Current Name figures
Figure 3.2 Designing a bar
•
2K Memory
The first option highlighted is bar colour and allows you to choose the bar colour from
Ihe palette shown across the top of the display. You can accept the option by pressing
ENTER or select another option by using the up and down cursor keys.
If you accept the bar fill option a box is drawn around the first colour in the palette and the specimen bar is filled with that colour You can
move
from colour to colour by pressing the left or right cursor keys. Make your selection by pressing ENTER when the bar is filled With the colour you want. Easel draws the bar against a background of the current graph paper
The next option in the list, to select a border colour for the bar is then highlighted automatically. Again you can either select this option by pressing ENTER, or
move
on to one of the other options. If you select this option you can choose the border colour for the bar in the same way as you chose the main fill colour (If the width of the border is currently set to zero you will not, of course, see the colour in your bar design.) You should press ENTER when you are satisfied with the result.
The third option is to select the width of the border. In this case you are asked to type in a number to represent the width of the border as a percentage of half the width of the bar.
Bar Colou r
Border Colour
Border Width
You are finally given the option of deciding whether you are satisfied with the design as shown. If you are you should press ENTER, when the new design will be added to the list of bar designs and It will automatically be used for display of the current set of figures. If you are not satisfied with the design you can go back to one of the other options, using the up and down cursor keys, and try a new combination. At any time before you accept the design you can terminate the command by pressing ESC and you will leave the command without creating a new bar design.
12/84 7
8
CHAPTER
4
USING TEXT
Each time you edit some text, or add new text, it is shown in the colour and directionhorizontal or vertical-that you last set with the Text option of the Change command.
Easel recognises three basic types of text:
Ordinary Text (Including the Title).
Axis Names .
Cell Labels
ORDINARY TEXT
Ordinary text - i.e. all text except for the axis names and cell labels - behaves as though it were pasted on the screen. It is always printed over the top of the graph or chart and remains on the screen until you delete it, regardless of any other changes you make.
The Edit command has options to edit the 3 types of text listed above, and a fourth option relating to the Key. The Key option is only relevant when you have more than one set of figures In your graph. It is described in the next chapter
Press the T key to select the Text option. You then use the cursor keys to move the intersection of the crosswires close to the text which you want to change. It is not necessary to position the crosswires exactly; press any key and the crosswires will attach themselves to the nearest piece of text. A copy of the text also appears in the input line.
You can delete the text by pressing F4, or modify the text using the line editor choose to delete the text this will also end the command.
If you
When you are completely satISfied wrth the wording of the text you should press ENTER.
Easel then gives you the opportunity to reposition the text. Press ENTER when you are satisfied with the position.
Easel treats a graph title in the same way as any other text. The only difference is that
Easel supplies the text 'TItle: centred above the graph, when you load it from its Microdrive cartridge.
AXIS NAMES
Axis names only appear on bar and line graphs and are not shown when you select a pie chart representation.
Select the Axis option of the Edit command to edit either of the twc axis names. Press
V or H to select the vertical or horizontal axis. You can then edit, delete or move the text, as described for the Text option. Easel redraws the text in the current ink and paper colours.
CELL LABELS
The cells of the graph are provided with labels which are initially set to show the months from January to December These labels are shown along the horizontal axis of a bar or line graph. In a pie chart they are used to label the segments of the chart.
You use the Labels option of the Edit command to change the cell labels. When you do so the crosswires will attach themselves to the nearest label which will then be displayed in full. Cell labels can be up to ten characters long but normally only the first few characters are shown. The text is also copied into the input line. You can then delete the label by pressing F4, or edit it with the line editor Press ENTER to finish editing.
Although the labels initially have their own text colour, when you edit any label, all the labels are shown In the current text colour You cannot move a cell label.
TEXT COLOUR AND
DIRECTION
You use the Text option of the Change command to alter the colour of the text and ',tS background. You can also select whether the text is vertical or horizontal.
Easel uses the new text colour and direction for all new text that you add to the graph
and for any old text that you edit.
A convenient way of changing the colour of text IS first to change the text colour and then to use the Edit command - described in the follOWing section - on the existing text, without actually changing its wording or position.
Select the Text option of the Change command. Easel offers you a list of text design options in a similar way to designing a bar by example. You can step through the options with the up and down cursor keys, and select the highlighted option by pressing ENTER.
12/84
The first option is to select the ink colour You use the left and right cursor keys to select the colour and press ENTER when the text is shown in the colour you want The following option is highlighted automatically, ready for selection by pressing ENTER.
This second option is to select a background paper colour. You select the colour with the left and right cursor keys, press ENTER to confirm your selection and move to the next option.
The third option is to select a transparent background for the text If you select this option
Easel ignores your selection of paper colour and allows the background graph to be seen around the text. Each time you select this option the background switches between the chosen background colour and a transparent background.
The fourth option is to select the direction In which the text is printed. Each time you select thiS oplion Easel sWitches the text between horizontal and vertical.
Ink Colour
Paper Colour
Text Direction
Finally you are given the option of deciding If you are satisfied with the appearance of the text. At this stage you can press ENTER to keep your selection of text style and return to the command menu. Alternatively, you can use the up or down cursor keys to go back and make further changes.
12/84 9
10
CHAPTER 5
SEVERAL
SETS OF
FIGURES
So far we have only described how fo create and display a single set of figures. On many occasions you may want to display two or more sets of data on the same graph, for example to compare the saes figures for two successive years. This chapter describes the techniques you can use to produce, modify and display graphs containing several sets of figures.
THE CURRENT
FIGURES
No matter how many sets of figures you have in your graph, you can only modify one set at a time. The set that you can add to or change is known as the current figures, and its name is shown in the status area. Initially you have one set of figures called '1igures':
If a set of figures is current it will be displayed on the screen.
THE RENAME
COMMAND
Suppose that you have typed in a set of numbers to '1igures" and want to change the name to "sales': You do this with the Rename command. Press F3 and then the R key.
Easel asks you to type the old name of the set of figures and mark the end of the name by pressing ENTER. You then type in the new name. To change the name of '1igures" to the new name "sales': you should type:
~
R figures
I
ENTER
I
sales
I
"E~N~T"'E~R~I
The set of figures that you have renamed becomes the current figures.
THE NEWDATA
COMMAND
There are two methods that you can use to produce new subsequent sets of figures.
These are by uSing the Newdata command, or by using a formula. The two methods are described in this and the following section.
Suppose you have created a set of figures called ''sales': as described above, containing monthly sales figures, and that you now want to include a display of the monthly costs.
You can do this by pressing F3 and then the N key, to select the Newdata command.
You then type in a name for the new set of figures, ending by pressing ENTER.
To create a new set of figures called costs' you therefore type:
~N costsiENTER!
Easel immediately gives you a new, blank graph (assuming you are in a bar or a line format) with the vertical crosswire set on the first column. The status area shows that the current figures are the new set, with name "costs': All you have to do is type ',n the new numbers which are immediately displayed on the graph as normal.
If you want to create a third set of figures, you can use the Newdata command again, exactly as has been described, giving the new set of figures a different name. You can create as many sets as you like, the only limit is the amount of available memory.
USING A FORMULA
On occasions you may wish to produce a new set of figures relafed in some way to one or more existing sets.
Suppose you have already entered sets of figures for "sales" and 'costs" and want to generate a graph showing the resulting profits. All you have to do is type in a formula which describes the new set of figures, for example: profits:: sales - costs
This creates a new set of figures with the name "profits': each value being the difference between the corresponding values of the "sales" and 'costs" figures. "Profits" will become the current figures and the graph will be displayed immediately.
You can also use a formula without having to refer to existing sets of figures. You could, for example, write a formula such as wave
=
10' sin(cell/2)
12/84
Using Text
This formula creates and displays a new set of figures with the name ''wave', whose vaues are calculated using the sin
0
function. in this formula we have also used 'tell': This gives the cell number counting from 1 at the left hand side of the graph. To see how this works, type in the formula: a
= ce LL and look at the graph that is drawn. When you use tell' in a formula, the number of values in the set of figures is made equal to the number of columns currently being shown on the graph.
There is another reserved word in Easel - 'tellmax': It has a value equal to the number of cells currently shown on the screen. You can use 'tellmax" to adjust the scale of the hOrizontal axis in a formula. For example, the formula: curve = s;n(2*p;O*(cell -1)/(ceLLmax -1)) draws one complete cycle of a sine curve, regardless of how many cells are shown on the screen.
When you use the Newdata command the set of figures that you create becomes the current set. Remember that this is the set that can be added to or changed by typing in numbers. If you want to make some changes to an existing set of figures that is not the current set. you can do so by using the Olddata command. When you select this command you are asked to type in the name of an existing set of figures, and that set becomes the current figures.
Suppose that you have the three sets of Jigures called "sales': 'tosts" and "profits': and that "profits" is the current set of figures. If you want to change or ad~ to the 'tosts" figures you should select it with the Olddata command. The costs tigures will then be shown on the graph and you can modify the data by typing in replacement numbers.
Note that any change you make in the 'tosts" figures will not automatically change the
"profits" graph. (This is a job for Abacus.)
You can see the effect of displaying all of your figures on a single graph with the View command.
Try selecting this command. As you see, Easel suggests that all the sets of figures should be shown on the graph and you can accept this suggestion by pressing ENTER. Easel then suggests the display format to be used and again you can accept the suggestion by pressing ENTER. The graph is drawn immediately, containing all the data that you have defined - together with a key box which shows the name of each set of figures and the way that it is represented (the key IS not shown if you only have one set of figures on the graph).
If you have defined a large number of sets of figures the graph will be very crowded and make very little sense. In general it is a good idea to display only a small number of sets of figures on anyone graph to make the best visual impact This does not mean that you should only define a small number of sets of figures, since the View command allows you to select which sets of figures you want to see.
You do this by not accepting the "all figures" suggestion that Easel gives in the View command. Instead of Just pressing ENTER at this point, you can type in a list of the names of those sets of figures which you want to be displayed, separating the items in the list by commas. When you have typed in all the names of the sets of figures that you want to be displayed, press ENTER.
You can also select a different format for the display instead of accepling the suggestion made by Easel. Instead of Just pressing ENTER to accept the suggested format you can type in a number between 0 and 7 Easel is provided with eight pre-defined formats, providing various styles of bar charts, lines or pie diagrams. You can type in a question mark to see a menu of all possible formats. Try using the View command to display three or four sets of figures in a number of the different formats available.
One of the options ,n the Edit command is to move the key. The key is replaced by
Its outline, and you are then offered the option of either deleting the key - by pressing
F4 - or moving the key by means of the cursor keys. If you choose the move option the cursor keys move a box equal In size to the key around the display area When you press ENTER the graph will be redrawn with the key in its new position.
THE OLDDATA
COMMAND
VIEWING THE DATA
THE KEY
12/84 11
12
You may at some time want to restore the display of a key which you had deleted earlier
You can do this by using the Edit command and selecting the Key option. The outline of the key will appear You can move the key to a new location. Pressing ENTER will redraw the graph, including a display of the key.
The only change that you can make to the contents of the key box is to change the colour of the text that it includes. Th·,s text is always drawn in the colour last set by using the Change command. The symbols shown in the key box will, of course, afways match the symbols which you use to display the graphs.
•
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES www.mauritron.co.uk
TEL: 01844·351694
FAX: 01844 . 352554
12/84
CHAPTER
6
GRAPH
FORMATS
CHANGING FORMAT
Easel ',S provided with 8 display formats (numbered 0 to 7) and you can use one of these numbers to specify which format should be used each time you use the VifN<l command. In addition to using different styles of background and bar colour these formats give you a range of display styles.
You can also use the Format option of the Change command to selecf one of the 8 formats. Easel puts the text:
COMMAND Change to format?
In the input I'lne and you can select a particular format by typing in a number between o and 7 (followed by ENTER). If you press ENTER, then Easel shows you the appearance of all 8 formats and again asks you for the format number
You can redes'lgn the enf"e appearance of any or all of the eight different formats provided by EASEL
You will normally have some idea of how you want your graph to appear In this case you would select the format that is closest to the one you want and then modify it until it matches your requirements.
Use the options of the Edit command to change the text of the cell labels and the axis names. You use the Change command to modify the text and bar styles.
If you want a line graph you can use format 3, or you can use the Line option of the
Change command. Pie charts are described in Chapter 8.
REDESIGNING
FORMAT
The Graph paper option of the Change command allows you to select the paper colour and the colour of the grid markings. You can select a graph paper from an eXisting set of 7 styles, or you can design a nfN<l one. The method of design is exactly as described for the Bar option of Change.
Graph Paper
The Axis option of the Change command allows you to select the axis style for your graph. You can select an axis from an existing set of 10 styles, or you can design a new one. The method of design is exactly as described for the Bar and Graph paper options of Change.
The Axis design option allows you to select a colour for the aXIs line, whether or not the aXIs line is drawn, the colour of the numbers labelling the vertical axis and the axis limits.
EASEL normally chooses the limits for the range of values shown on the vertical axis.
It chooses a range that allows you to see all the values in your graphs. If you select the option to change the aXIs limits you are offered one of three possibilities.
Press the A key to select automatic limits. In this option Easel selects a suitable range, depending on the values ,n your graphs. The range might not include the zero point
If, for example, all the values are large and positive.
Press the Z key to select automatic limits which always include zero. This IS the type of axis limits that Easel uses if you do not make your own choice.
Press the M key if you want to make your own choice of limits. Easel asks you to type in the lower limit and then the upper limit (mark the end of each value by pressing
ENTER). Note that Easel will override your selection if it does not cover the full range of values in your graphs.
In all cases the two limits are adjusted so that the intervals in the scale are sensible ones.
Note that the specimen axis, shown at the right of the screen, does not necessarily show the exact range that will be used in the resulting graph. It is a representative axis and is only intended to Illustrate the general type of aXIs that you have chosen.
Axis
A
13 12/84
CHAPTER
7
LINE
GRAPHS
As you may have seen when you experimented with the different display tormats, the sets of figures can also be represented by line graphs or by pie charts. This allows you to display a given set of the figures in many different ways so that you can choose the method most appropriate for your needs.
Format 3 uses lines to display the sets of figures. Each value may be marked by a symbol and the values are Joined by lines of various thicknesses and colours. You can also use
'~llIed" lines where the space between the line and the zero level is completely filled
With colour
You may find filled lines useful for showing 'triflcal values': such as a break even level, as a background fo your graph.
Since bars and lines are both displayed on the same type of grid, you can mix bars and lines in any combination. Titles, axis labels, general text and fhe key box all behave
In exactly the same way for both bars and lines.
SELECTING ALINE
STYLE
If you select the Lrne option of the Change command you can change the representation of a set of figures to use a line graph. First make the graph you want fo change to be the current figures (e.g. With Olddata). Then select the Lrne option of the Change command.
There are 16 pre-defined line styles and Easel first asks you to type in the number of the line you want. Type in the number and press ENTER, or just press ENTER to see the selection available. Select a line by pressing the left or right cursor key. When the box encloses the line you want, press ENTER. Easel Immediately draws the set of figures with the line style fhat you have selected.
Select fhe line shown with a Ouestion mark instead of a number if you want to design your own style of line.
Easel gives you a list of options for your line and you use them exactly as was described for the Bar option, in Chapter 3. Press ENTER to select the highlighted opfion, or use the up and down cursor keys to step to the option you want.
Line Colour
selects the line colour Select the colour with the left and right cursor keys and press
ENTER fo move to the next option.
Symbols
allows you to choose whether to mark each point on the line with a symbol. Each time you select this option the symbols are switched between on and off.
Symbol Colour
selecfs the symbol colour in the same way as you select the line colour You can step over fhis option if you have chosen not to use symbols.
Filled Lines
switches befween a normal line and a line which is filled with the line colour to the horrzontal axis. Each time you select this option Easel switches between the two types of line.
Line Thickness
allows you to choose the thickness of the line. Type in a number between
a
(thinnest) and 100 (thickest) and press ENTER. You can sfep over this option if you have selected a line filled to the axis.
14
Easel offers you a final option to check that you are satisfied with the result Press ENTER to see the graph with your style of line, or use the up or down cursor keys to go back to modify your selections.
Figure 7.1 was created in format 2 (stacked bars) with one set of figures changed from a bar to a line representation.
NUMERIC ENTRY
FOR LINES
If you select a format which uses a line graph for your current figures, you can enter your data in exactly fhe same way as described for bar charts - simply type them in.
The only real difference between line and bar representations appears when you are typing numbers into a set of figures represented by a line. In order to allow you fo type new numbers - or change existing ones - without redrawing the whole graph for each number, Easel does nof use the true line colour
12/84
HELP press Fl
PROMPTS press F1
NUHBERS Use
TABULATE Key to move wi re type number
X-WIRES move t wi
th
<------I keys j
TEXT type
II then text fORMULAE
Enter directly
COMMANDS press f3
ESCAPE press ESC
Softco Production Figures
20
$ m 15
I
I o n
I
I 10
5
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1984
Format 3 Rep LINE 16
Current Name figures 11K Memory
Figure 7.1 Stacked bars and lines
While you are typing in the numbers, the graph is drawn using a thin white line - or a filled line - depending on the line style you have chosen. The colour of fhe line changes as if passes over any bars, lines or text. Easel warns you in the status area that the line colour is not being shown correctly.
When you have finished typing in numbers, use the View command to see your graph with the correct colour and thickness of line.
Graph Formats
12/84 15
Note that you can only show one set of figures at a time in pie chart format, and that any negative values are ignored. Easel will warn you if data has been omitted.
Since you can only have one set of figures in a pie chart, the View command offers you the option of viewing the current set of figures· instead of the usual "all Figures':
You can type in a replacement name. If you type in a list of names (separated by commas)
Easel will display the first set of figures in the list, ignoring the rest.
ENTERING
NUMBERS
To illustrate entry into a pie chart, use the Change command to change to format 7, which is a pie chart format. Then use the Newdata command to create a new, empty set of figures called, for example, 'costs': Easel draws a filled circle, labelled with the first cell label which, unless you have changed it, is 'Jan':
Type a number and press ENTER. Easel redraws the circle, but this time the number you typed in is shown under the label. The diagram IS a pie chart with only one value.
Type in a few more numbers, exactly as if you were typing numbers into a bar chart.
During data entry into a pre chart the next cell to receive data will be indicated by having its label highlighted. If this is not possible it will be indicated by a special highlighted display box at the bottom left of the display area. In Figure 8.1 this is the label "PORTUGAL::
HELP press f1
PROMPTS press F2
NUMBERS Use
TABULATE Key to move wi re type number
X-WIRES move i wi th <-~ keys I
TEXT fORMULAE type" Enter then text directly
COMMANDS press f3
ESCAPE press ESC
BRITAIN
220
FRANCE
300
GERMANY
225
ITALY
180
COSTS
16 format 8 Rep PIE
Current Name costs 12K Memory
Figure 8.1 A pie chart
Since the chart must be redrawn each time you add or change a value, you may find it more convenient to enter the numbers rn one of the other formats changing to pie chart format later
CELL LABELS
You move from cell to cell with the TABULATE or SHIFT + TABULATE keys, just as in a bar chart. Remember that as always the option is not available from the command menu.
Press F5 to add another cell after the one whose label is highlighted. Easel gives each new cell the label "unnamed". Type a number into the cell as normal. You can edit the
12/84
PieCharls cell label with the Label option of the Edit command. The cell that you can edit is highlighted, and you can step from label to label with the TABULATE and SHIFT keys.
As in bar charts and line graphs you must delete both the cell label (use the label option of Edit, and press F4) and the number in the cell (step to the cell with TABULATE and press F4) before Easel deletes the whole cell. Easel deletes a blank cell when you next use the View command.
You can add, delete, and move text and titles exactly as described for lines and bars in Chapters 2 and 4. You use the horizontal and vertical crosswires in the normal way for adding, editing or moving ordinary text.
TEXT
The Text and Format options of the Change command work in exactly the same way with a pie chart as in any other format.
Graph paper, bars, lines and graph axes have no meaning for a pie chart and Easel does not allow you to use these options.
The Segment option can only be used in the pie chart format. It allows you to change the colour of a segment of the chart. First select the segment whose colour you want to change.(Press TABULATE until its label is highlighted.) Then select the Segment option of the Change command.
Easel draws the palette of possible colours in the display area. Press the left or right cursor key to select the colour you want and then press ENTER. Easel redraws the pie chart with the segment in your chosen colour
THE CHANGE
COMMAND
MAUR:' '.
'N 'fE, '1IlJICt",EF
;\CE~ www,mawllfun,V,),l!h
TEL: 01844 351 b:i4
FAX: 01844 - 352554
17 12/84
18
CHAPTER
PERMANENT
9
COPIES OF
YOUR
GRAPHS
PRINTING
If you have a dot matrix printer that is compatible with the Epson FX80 (for example the Brother HR-15 or the Canon PW1080A) you can make printed copies of your graphs immediately.
The print command makes a printed copy of the graph shown on the screen. Press the P key to seled the print command. Before printing Easel reads the printer driver from the file gprinLprt' from the cartridge in Microdrive 1
Press the S key to dump the screen into a Microdrive file; you must type in the name of the file to use followed by ENTER. This file can then be subsequently processed for example by a SuperBASIC program and sent to a printer not supported by Easel.
Note that this file is very large and normally no more than three can be stored on a
Microdrive cartridge.
Press the I key to install a different printer driver Several other printer drivers are supplied on the Easel crtridge, they are in files with the extension _Pr!o
Some of these are colour printers, for example the Integrex 132 and the Okimate 80. Type In the name of the printer driver you want and press ENTER.
The new printer driver IS not Installed permanently and Easel will revert to the Epson
FX80 the next time Easel is loaded. The default printer driver is contained In the file gprinLprt' and so you can make the Installation of a new printer permanent by simply renaming the files. First copy the original 'gprlnLprt' to another file, for example
FX80_prt' and delete the original file. Then copy the file containing the driver you require to the IiIe 'prinLprt: Note that the original Easel cartridge is write protected so you must use the copy you made.
You can use a baud rate different from the Initial 9600 baud assumed by the example, if you wanted to set 4800 baud start Easel by typing:
OL.
For
BAUD 4800
LRUN mdv1 boot instead of having the Easel cartridge in Mlcrodrive 1 when you press F1 or F2.
Alternatively you could make the change of baud rate permanent by adding an extra line to the 'boot' program. First load and renumber the program by typing:
LOAD mdv1 boot
RENUM 10,10
Then add, for example, the line:
5 BAUD 4800
Delete the old copy of the program and save the new version on the Easel cartridge, type:
SAVE mdv1 boot
Again thiS change must be made to a copy of the Easel cartridge.
PHOTOGRAPHY
The simplest, and fastest. way of obtaining a permanent copy of one of your graphs is to take a photograph of the screen. You must. however, take a little care If you want to obtain good results.
One of the most common causes of a poor photograph of a television screen IS using too short an exposure time. The picture is made up of 625 separate lines, displayed one after another It lakes a 25th of a second to display all the lines in the picture and if you use an exposure time of about this length, or shorter, the picture will be unevenly lit. It IS best to use an exposure time of around a quarter of a second - this means that you must support the camera on a tripod. An average colour film (for prints or transparenc'les) with a speed of, say, 100 ASA will need an aperture of around F5.6.
Use a long focal length lens (about 100mm) if you have one, as this will reduce the distortion caused by the curved surface of a TV screen.
12/84
Try to take the photograph in a darkened room, to avoid reflections of the surroundings on the surface of the screen. It is surprising how strongly such reflections show up on the photograph, even If you do not notice any when you look through the camera viewfinder
Press F2 to remove the control area and give you a larger graph. You can also press
SHIFT and, while holding it down, press F2 to erase the text in the status area.
Before taking the picture make sure that all text, cell labels, axis names and the key appear exactly as you want them.
FOR SERVICE MANUALS
CONTACT:
MAURITRON TECHNICAL SERVICES
www.mauritron.co.uk
TEL: 01844 - 351694
FAX: 01844 - 352554
12/84
19
20
CHAPTER 10
QL EASEL
REFERENCE
THE FUNCTION
KEYS
In addition to the standard use of F1, F2 and F3, function keys 4 and S are used as follows:
! F4!
delete text labels numbers the key user-defined objects
Note: user-detined objects are bars, lines, graph paper and axes.
I
FS\ insert a cell
THE COMMANDS
The commands give access to the deeper levels of Easel and allow you to use many of the more advanced facilities. The following commands are provided.
CHANGE
The Change command allows you to modify the appearance of any feature of the graph.
You are offered the following options:
Axis
Bar to select the axis markings. You can alter the colour of the axes and of the numbers labelling the y-axis. You may also select whether or not the axis I'lnes are to be drawn. Easel will not allow you to select thiS option in format 7 (a pie chart).
The option to change the axis lim',ts allows you to choose between automatic or manual limits. Press the A key for automatic limits or the
Z key for automatic limits which always include zero.
Alternatively, press the M key to select manual limits. In this case you must type values for both limits. Easel may modify your choices of limits to ensure that the whole of your graph is shown, with simple numeric values on the scale.
to select or define the style of bar used to represent the current set of figures. You may choose one of 16 previously-defined bars by its number, or by example. The deSign by example option allows you to select a bar or to design a new one. Easel will not allow you to select this option in format 7 (a pie chart).
Format to redefine the appearance of the entire graph. You may choose one of 8 defined formats by its number, or by example.
Graph_paper to select one of 7 different graph papers, or to replace one with your own design. You can select both the background colour and the colour of the grid markings. Easel will not allow you to select this option in format 7 (a pie chart).
line
Segment to select one of 16 defined line styles, or design your own line. You can choose the line colour and thickness, and the colour of the symbol used for each point on the line, or select a filled line, where the space between the line and the zero level on the graph is colour-filled. Easel will not allow you to select this option in format 7 (a pie chart).
to select the colour of a particular pie chart segment Easel will only allow you to select this option in format 7 (a pie chart).
Text to select the colour used for both the text and its background. You can select a transparent background so that the underlying graph will show through. You can also select whether the text is to be drawn horizontally or vertically.
Any existing text will retain ItS anginal colour and direction, but new text will appear in the selected style, until you change it again. (The text In a key box is always drawn in the current text colour.)
12/84
The Defaults command allows you to select a number of features, such as whether you use a 40, 64 or 80 character display You can select an item by pressing the key corresponding to its first letter in the list of options shown.
The Edit command allows you to modify or move text, labels and the key.
You are asked to choose befween the following four options:
Text the crosswires lock on to the nearest piece of text and you can use the line editor to change the wording. Press ENTER and you are offered the option of moving the text to a new position. Press ENTER when you are satisfied with the position.
Labels
Key the crosswires lock on to the nearest cell label and you can then edit the text of the label as in the Text option. Press ENTER when you have finished. Cell labels can not be moved.
you are immediately offered the option of moving the key box with the cursor keys. Press ENTER when the outline of the key box is in the position you want The key box is then redrawn in its new position.
Axis you are asked to press either the V or the H key to select the vertical or the horizontal axis name. The crosswires lock on the chosen name and you can edit the text and then reposition it
After editing, all text is shown in the colour and direction set by the last use of the Text option of the Change command. The only exceptions are the axis names, which are fixed in drrection.
This command allows you to modify Easel files, previously saved on a Microdrive cartridge, or to transfer data files to another of the Psion OL programs.
You are offered the follOWing options:
Backup used to make a backup copy of an Easel file. You are asked for the name of the file to be copied and the name you want to give to the new copy Making copies of your files is strongly recommended, to protect yourself against accidental loss of, or damage to, the cartridge, and against making a mistake which causes your application to be corrupted or deleted.
Delete deletes a named file from a Microdrive cartridge.
Export
Import
Format
Warning - this command is not reversible and should be used with great care.
exports a named file. The file contains all the sets of figures currently in the computer's memory. It is saved in a form SUitable for being read by OL Abacus or OL Archive Import and export are described in the
Appendix.
If you do not speCify a file name extension for an exported file, Easel will supply an extension of _expo imports a named file and allows Easel to read data files exported from
OL Abacus or OL Archive and display them In graphical form.
tf you do not specify a file name extension for an imported file, Easel
Will assume an extension of _expo formats the cartridge in Microdrive 2. or another named Microdrive.
Accept Easel's suggestion to format mdv2 or type in another Microdrive specifier e.g.
mdv3.
Easel asks you to confrrm your selection of this option.
Warning - all information on the cartridge is erased when you format it
This command allows you to use a special symbol to represent a particular number in a set of figures, or all negative values in a bar chart. The value to be highlighted is the one at the current position of the intersection of the crosswires, or the one whose label is highlighted in a pie chart
DEFAULTS
EDIT
FILES
HIGHLIGHT
12/84 21
Reference
Easel first asks you to press either the V key to highlight a particular value, or to press
N to highlight all negative values. You are not allowed to select this second option for a pie chart.
If you choose to highlight a value Easel asks you to select the value. Press TABULATE
(or SHIFT and TABULATE) to select the cell you want to highlight and then press ENTER.
In the case of a bar graph you are shown the selection of defined bars, and can choose one - or design a new one. In a pie diagram the selected segment is detached from the remainder of the pie.
If you select the option to highlight negative values, Easel immediately asks you to select or design a bar.
HELP press F1
PROMPTS press f2
NUMBERS Use
TABULATE Key to move wi re type number
X-WIRES
move i wi th <--keys j
TEXT type" fORMULAE
Enter then text directly
COMMANDS press f3
ESCAPE press ESC
Standard Text Area
COPPER
45
ZINC
73
22
METALS format 8 Rep PIE
Current Name METALS 12K Memory
Figure 10.1 A highlighted pie sector
KILL
Deletes one or more sets of figures from the graph and destroys the data. When you select this command you are asked to type in a list of the names of the figures you want to delete, separated by commas and ending with ENTER. If you just press ENTER,
Easel will delete the current figures. You can, if you like, type in the text all figures.
LOAD
Loads a previously saved graph from a Microdrive cartridge. Easel asks you to type
In the name of the file to be loaded. All the Design options are loaded with the data so that the graph of the loaded data has exactly the same appearance as it had when it was saved.
If you do not specify a file name extension, Easel assumes an extension of _gr!.
NEWDATA
Allows you to create a new set of figures, which becomes the current figures'. You are asked to type In the name of the new set (no quotation marks are needed). When you press ENTER you are returned in data entry mode, ready to type in some values.
OLDDATA
The Olddata command allows you to make an existing set of figures the current figures:
You are asked to type in the name of the old set (no quotation marks are needed). When you press ENTER you are returned to data entry mode, ready to change or add to the values.
12/84
Reference
Prints the graph that is currently displayed on the screen.
The command offers three options. Press the P key to print the graph, uSing the current graphics printer driver.
Press the S key for a screen dump to a Microdrive flle..In the Screen dump option Easel asks you to type in a name for the file. -
Press the I key if you want to install a different graphics printer driver Easel will walt for you to type in the name of one of the printer driver files (with an assumed extension of _prt) supplied on the Easel cartridge. See Chapter 9 for further information.
You use this command to leave Easel and return to SuperBASIC. You are offered the options to press ENTER to confirm your choice and return to SuperBASIC, or to press
ESC to cancel the command and return to Easel's command menu.
This command allows you to rename an existing set of figures. Easel asks you fa type
In the old name, suggesting the current set of figures, and then the new name. Press
ENTER at the end of each name.
If you do not specify a file name extension for the old file, Easel assumes an extension of _gr!. The new file IS given the same extension as the old one, unless you also type in an extension for the second name.
Saves all the sets of figures currently In the computer's memory on a Microdrive cartridge.
You are asked to type in a name under which the figures will be saved. If you do not specify a file name extension, Easel assumes an extension of _gr!.
All the properties of the graph, e.g. the bar colours and style of axes, are saved with the figures.
You use this command to redisplay your graph, showing all, or a selected few, of your sets of figures. Easel suggests that all sets of figures are to be displayed and you can eifher accept this suggestion, by pressing ENTER, or type in a list of the names of those sets that you want to be displayed. You should separafe the names in the list by commas and end the list by pressing ENTER.
In the pie chart format Easel suggests only the name of the current set of figures. If you type In a list of names in this format Easel shows a pie chart of the first name in the list and ignores the remaining names.
You are then offered a suggested format number for the display. You can accept the suggested format (which is the last one you were using) by pressing ENTER, or you can type in your own chOice of format number, followed by ENTER.
ThiS command erases all text, all sets of figures and all user-defined objects (bars, lines and so on). It also restores the original month labels for the cells. It does not, however, restore the original appearance of the graph formats, but leaves any changes that you may have made.
Think of a function as a kind 01 recipe which converts a number of initial values, known as the function's arguments, Into a different value, which IS said to be the value that is
returned by the function.
The functions provided by Easel take one or no arguments The argument for a function is placed in brackets after ItS name. You must not leave a space between the name and the opening bracket, but spaces are allowed within the brackets. All function names must be followed by the brackets, even If they take no arguments. The presence of the brackets is a useful reminder that you are refernng to a function. They allow you to distinguish between the name of a set of figures and a function, even if they have the same name.
The following functions are provided.
ABS(n) Returns the absolute value, that is the numerical value irrespective of
ItS sign, of the argument For example, abs(5) and abs( -5) both return the value 5.
ATN(n)
COS(n)
Returns the angle, in radians, whose tangent IS n.
Returns the cosine of the given (radian) angle
QUIT
RENAME
SAVE
VIEW
ZAP
FUNCTIONS
12/84 23
Reference
EXP(n)
INT(n)
LN(n)
PI()
SGN(n)
SIN(n)
SQR(n)
TAN(n)
Returns the value of e (approximately 2.718) raised to the power n. The returned value will be in error if n lies outside the range tram -87 to
+88, since the result will then exceed the numeric range of Easel
Returns the Integer value of the number, by truncating at the decimal point. The truncation always operates towards smaller numbers. Thus; i nt (3.
int
7J
(-4.8) returns 3 returns-5
Returns the natural, or base e, logarithm of n. An error results if n is negative or zero.
Returns the value of the mathematical constant 1t.
Returns
+
1, -1, negative or zero.
or 0, depending on whether the argument is positive,
Returns the value of the Sine of the specified (radian) angle.
Returns the square root of the number n, which must not be negative.
Returns the tangent of the specified (radian) angle.
24 12/84
©1984 PSION LIMITED by Dick de Grandis-Harrison (Psion Limited)
QL
Information
You can transfer information between the four OL programs with the import and export commands.
Stored information in OL Abacus, OL Archive and OL Easel is similar and can always be represented as a table. Transferring information between them is very simple. In Abacus and Easel the import and export commands are file command options. In Archive they are two separate commands.
Let us first consider import and export between Abacus, Archive and Easel. The export tile structure produced by the three programs is identical in structure and can be imported by any.
For example, suppose we have an Abacus grid containing the following information:
1
2
3
4
A cashflow sates costs profits
B
January
1000
500
500
C
February
1050
530
520
0
March
1100
560
540
Abacus grid lor export
II this data was imported into Easel, It would be interpreted as three sets of figures, called costs, sales and profits.
Easel uses the month names as the cell name labels for the graphs. The Information would be: celt labets sales graph costs graph profi ts graph
January
1000
500
500
February
1050
530
520
March
1100
560
540
Imported into Easel
Easel does not use the first piece of text, cashflow.
When you export a set of figures from Easel it automatically inserts the text, labels, in this position to maintain compatibility.
tf we were to import the same set of figures into Archive the result would be a data file containing three records, each of which would have four fields With the field names: cashflow$ (a text field), sales, costs and profits (numeric fields). The file would be:
Fields cashflow$ sates costs profits
ReeD rd 1
January
1000
500
500
Record 2
February
1050
530
520
Record 3
March
1100
560
540
Imported into Archive
QL
PROGRA~
-IMPORT AN
EXPORT
RULES
To allow data to be exchanged between the three programs if is necessary to remember a lew rules:
1. When you export the contents of a grid from Abacus the secflon of the grid being exported must have text in the first cell of each row (or each column If exporting in column order).
2. If the first cell of any row (or column) is empty then that row (or column) is not exported.
3. There must be data in the cell Immediately follOWing the text cell in each exported row (or column). The type of this data determines the type used lor the dala in the rest of the row (or column). Each row (or column) must contain either all numeric or all string data.
4. You can export flies from Abacus or Archive which contain several sets of text data.
Easel can only export a file containing one set of text data· Ihe cell labels.
5. If you import a file containing more than one set of text data Into Easel, It uses the first as cell labels and ignores the rest.
12/84
2
FILE STRUCTURE
The export file structure consists of a series of records each terminated by <CR> (ASCII code 13) and
<
LF> (ASCII code 10). The import commands will,
however,
accept either of these characters or the two together, In either order. The end of file is marked by a
CTRL Z character (ASCII code 26).
Each record consists of a series of values separated by commas. The values are either text (which must be enclosed in quotes) or numbers.
The first value in each record must be text and If its name ends with a dollar sign all the following values must be text
The export file produced by exporting the original set of example data from Abacus is as follows: lie as
hf l
OW$II,
"sa
L
es", "cost
S",
"January",1000,SOO,SOO<LF>
"February",10S0,530,520<LF>
"March",1100,560,540<LF>
"prof; t s"<LF>
An export file
An export file can be generated from SuperBASIC The follOWing program will generate an export file, called example_exp, for the standard data.
100 OPEN NEW#4,mdv2 example exp
120 PRINT #4, IlIcashfLow$/I,"sales","costsll,"profits"1
130 PRINT #4,'''January'',1000,500,500'
140 PRINT #4, "'February",1050,530,520'
150 PRINT #4, '"March",1100,560,540'
160 PRINT #4, CHR$(26)
170 CLOSE #4
SuperBASIC will automatically add a line feed character (ASCII code 10) at the end of each record.
EXPORT TO QUILL
QL QUill works with formatted text and so files exported to Quill must contain formatted text rather than the normal export file structure. Quill will accept any text containing form feeds (ASCII code 12) and line feeds (ASCII code 10) and the printable ASCII characters.
line feeds are interpreted as an end of paragraph marker and form feeds as an end ot page. Any other characters 'In the file are ignored.
Abacus and Archive can produce special files for import by Quill. Archive can export to QUill by produCing 'Formatted report: produced by Iprint. To export the report you divert the printed output to a Microdrive file using the export option ot the spoolon command (See chapter 12 of the Archive GUide.)
12/84
The master QL program cartridge is write protected and so cannot be put through the printer install process. The cartridge should first be backed up and the subsequent copy installed.
Each of the four Psion QL programs can print text on almost any make of printer that has an RS·232·C interface.
The printer can be set to use either continuous or single sheet paper If using single sheet paper the printer will stop at the end of the sheet and a message will appear on the display prompting for more paper Press ENTER to continue or ESC to abandon the document.
QL
PROGRAMS
PRINTERS
PRINTER DRIVERS
The printer is controlled by a special program called the printer driver, which can be modified to use whatever printer you wish.
A non·printable character other than a line feed and carriage retum, must be preceded by an ASCII code 0 (NULL) to indicate to the printer drrver that it must be output. For example, the Epson FX·80 command to print in bold characters is ASCII code 27 (ESC) and E. ESC is a non·printable character and must therefore be preceded by a NULL.
You can send the codes from Archive with the instruction: lpr;nt chr(O) + chr(27) + "E"
In Abacus the same task can be performed by putting: chr(O) + chr(27) + "E" into a cell at the point where bold printing is to start.
Adapting QL QUill, QL Abacus and QL Archive to suit other prrnters is called installing the soHware and is done using the SuperBASIC install program. The install program
(install_bas), installation data for various printers 0nstall_dat) and the installation data for the current printer (printer_dat) are on the QL Quill and QL Abacus program cartridges. You can use the program to install a printer for QL Archive even though the archive cartridge does not contain the installation program or the installation data.
The Abacus, Archive and Quill programs themselves use only the information in printer_dat.
INSTALL ASERIAL
PRINTER
For example to install Quill to 'Mlrk with an Epson FX·80, fitted with an RS·232·C interface, put the Quill cartridge In Microdrive 1, but do not run it. While in SuperBASIC type: lrunmdv1 install bas and the installation program will run. The program requires the 'install_dar to be on the cartridge in Microdrive 1 so It shouldn't be deleted.
You must first select the Mlerodrive in which the printer will be installed. In this case press
1, followed by ENTER, to Install Microdrive 1. Then press ENTER to select a serral printer
(connected to the computer via serral port ser1 or ser 2).
The program then reads the installation data and displays a list of the names of printers for which a customised driver driver is supplied.
You select a printer from the list with the up or down cursor keys until the required printer is highlighted and then press F5 to install it. You must confirm the installation by pressing
ENTER; any other key will cancel the installation and retum to the list of printer names.
When the installation is complete you will be retumed to SuperBASIC. When Quill is next loaded it will be set up to use the printer you selected, including bold characters, underlining, subscripts and superscripts.
You can remove a printer from the list by pressing F3, and save all the printer drivers in the list by pressing F4. Since both of these options make irreversible changes to the printer drive information they must be confirmed by pressing ENTER.
12/84
4
OTHER SERIAL
PRINTERS
Do nothing
If your printer is not included in the list displayed by the install program you have two options:
Leave the installation program by pressing ESC. All four programs are set up With a simple printing facility which should be able to print ordinary text on almost any printer
Install it
Add a new name to the list of printer names. There are three ways of doing this:
1.
Use the down cursor key to select the item called 'OTHER: Press either F1 or F2 to create a new i1em, ready for you to set it up for your printer.
2. Select an existing printer name and press F1 to create a new printer with the same values as the old one. Use this option if your printer is similar to a printer already in the list.
3. Select an existing printer and press F2. ThiS does not make a new copy, but allows the values of an existing printer to be changed. Do not use this option unless you are sure of the changes you intend to make.
In each case you are shown a list of printer parameters to alter. Press the up and down cursor keys to select an item and the left and right cursor keys to change it.
There are two types of item in the list.
- those with a variety of possible values, such as the DRIVER NAME, and END OF
LINE CODE,
- and those with a limited range of values, such as the PARITY
The values of each type are changed in different ways. The diagram below shows the values given to the DEFAULT printer At the right of the diagram are other possible values
(for those with limited range).
DRIVER NAME
PORT
BAUD RATE
PARITY
LINES/PAGE
CHARACTERS/LINE
CONTINUOUS FORMS
END OF LINE CODE
PREAMBLE CODE
POSTAMBLE CODE
BOLD ON
BOLD OFF
UNDERLINE ON
UNDERLINE OFF
SUBSCRIPT ON
SUBSCRIPT OFF
SUPERSCRIPT ON
SUPERSCRIPT OFF
TRANSLATE1
TRANSLATE2
TRANSLATE3
TRANSLATE4
TRANSLATE5
TRANSLATE6
TRANSLATE7
TRANSLATE8
TRANSLATE9
TRANSLATE10
Default
: DEFAULT
: ser1
: 9600
: NONE
: 66
: 80
: YES
: CR, LF
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
Other options ser2
75, 300, 600, 1200, 2400, 4800
SPACE, MARK, ODD, EVEN o to 255 o to 255
NO
For each of the items that has a limited number of options, the value changes each time the leff or the right cursor key is pressed.
12/84
For the other Items pressing one of these cursor keys erases the existing value; you then type in your own value and press ENTER. All these items, except for the DRIVER
NAME, will accept lists of up to ten codes separted by commas. Each code can be typed in several ways:
3.
4.
1.
A number between 0 and 255
2.
A hexadecimal number, preceded by a dollar sign, between $0 and $FF
Any single characte( preceded by a quote symbol (" or ')
A standard ASCII control code mnemonic, in upper or lower case:
NUL
BS
OLE
CAN
SOH
HT
DC1
EM
STX
IF
DC2
SUB
ETX
VT
DC3
ESC
EOT
FF
DC4
FS
ENQ
CR
NAK
GS
ACK
SO
SYN
RS
BEL
SI
ETB
US
5.
The text DEF (or deD causes the printer to use a default action making the printer backspace to prod uce the desired effect It should only be used for emphasis and underlining. These items must be set in pairs, for example, if UNDERLINE
ON is set to DEF then so must UNDERLINE OFF The printer must be able to respond to the ASCII backspace code.
Alternatively you may just press ENTER to select NONE. You are free to mix the different methods in any way you choose.
The DRIVER NAME contains the name of the manufacture( or of the model, of the printer
It is the name by which you can identify the printer driver The name must not be more than 16 characters long. To change this item press the left or right cursor key, type in the name you want and press ENTER.
The PORT is either ser1 or ser2 and selects one of the tvvo standards serial ports.
The BAUD RATE determines the speed at which characters are via a serial interface, in terms of the number 01 bits that are transmitted per second. 110 baud is approximately equivalent to 10 characters per second, 300 baud to 30 characters per second, and so on. The baud rate of the printer driver must match that of the serial interface of your printer.
The PARITY item depends on the way your printer handles the most significant bit (binary digit) in the data sent from the computer. All ASCII codes lie between 0 and 127 and can be represented by a 7·dlgit binary number. Many serial printers expect a character to be sent as a seven bit value. Other printers may expect eight bit values, accepting codes between 0 and 255. The extra codes, between 12B and 255, may be printed as graphics or as accented characters. Your printer may interpret the eighth bit of an
B·bit code as a panty bit, used to check if there has been an error during transmission at a character Your printer may use EVEN parity (the parity bit is set to 0 or 1, so that the total number 01 1s in each character code is even) or ODD parity (the total number
01 1's is odd).
If your pnnter does not check the parity you can select SPACE (the eighth bit is always 0) or MARK (the eight bit is always 1) A setting of NONE allows the full eight bits to be sent 10 the printer
LINEs/PAGE and CHARACTERS/LINE speCify the maximum number of lines of text
(including the blank lines if you are printing double - or triple - spaced text) on each page, and the maximum number of characters on anyone line. The values used in the printer drivers supplied are SUitable for use with A4 stationery.
CONTINUOUS FORMS specifies whether your printer uses continuous stationery (YES) or separate sheets (NO). If you are printing on single sheets of paper. the printer will stop at the end of each page. A message appears on the screen, asking you to insert a fresh sheet of paper. Press ENTER to start printing again, or press ESC to abort the pnnt out.
The END OF LINE CODE is the code sequence to be sent to the pnnter to indicate the end of a line. Most printers will accept a carriage return followed by a line feed.
Select a line feed as the end of line marker if you want to print a SuperBASIC program to a file
The PREAMBLE and POSTAMBLE CODES may be needed if your pnnter requires an initialisation sequence before you first use It. You may, for example, want to set the printer margin positions, or select a particular character set. You may also want to restore these settings to their anginal values when you have finished using one of the QL programs.
The preamble and postamble items allow you to specify a sequence of up to 10 characters to be sent to the printer for these two purposes.
12/84 s
6
The BOLD ON and OFF items contain the codes to turn bold (emphasised) printing on and off. If your printer cannot print emphasised characters you can use the DEF value, described earlier, provided the printer will respond to a backspace character
UNDERLINE ON and OFF turn underlining on and off, provided your printer has an automatic underlining facility.
If your printer cannot print underlined characters you can use the DEF value, described earlier, provided the printer will respond to a backspace character
Use the SUBSCRIPT ON/OFF and SUPERSCRtPT ON/OFF items for the sequence of codes needed by your printer to turn subscript and superscript printing on and off.
Each of TRANSLATEl to TRANSLATE10 accepts up to ten characters. The first character specified is translated into the following sequence of characters before being sent to the printer The first character must not be a control character (its ASCii code must be in the range 32 to 255). The translation can contain any character The result must appear as a single character when printed.
As an example, let us create a second printer driver for the Epson FX-80. Start by loading and running the installation program from SuperBASIC Select the driver named OTHER and press either Fl or F2. The initial values displayed are listed below, the column at the right showing the values needed for the FX-80:
DRIVER NAME
PORT
BAUD RATE
PARI1Y
LINEs/PAGE
CHARACTERS/LINE
CONTINUOUS FORMS
END OF LINE CODE
PREAMBLE CODE
POSTAMBLE CODE
EMPHASIZE ON
EMPHASIZE OFF
UNDERLINE ON
UNDERLINE OFF
SUBSCRIPT ON
SUBSCRIPT OFF
SUPERSCRIPT ON
SUPERSCRIPT OFF
TRANSLATEl
TRANSLATE2
TRANSLATE3
TRANSLATE4
TRANSLATES
TRANSLATE6
TRANSLATE?
TRANSLATE8
TRANSLATE9
TRANSLATE10
Default
: OTHER
: serl
: 9600
: NONE
: 66
: 80
: NO
: CR, LF
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
Other options
: ser2
: 9600
: NONE
: 66
.80
: YES
: CR, LF
: esc,@,ESC,R,NUL
: NONE
: ESC,E
: ESC,F
: ESC 1
: ESC 0
: ESC,S,l
: ESC,T
: ESC,S,O
: ESC,T
£,ESC,R,ETX, # ,ESC,R,NULL
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
: NONE
First change the driver name, press the rrght cursor key to erase the existing text, and type
FX-80
I
ENTER
I
If you make a mistake you can repeat the process.
Press the down cursor key until the CONTINUOUS FORMS entry is highlighted. There are only two options; select YES by pressing the right or left cursor key.
A suitable PREAMBLE sequence for the Epson FX-80 is ESC which initialises the printer and dears its print buffer The printer should also be set to use the American character set (to print both the hash symbol, #, and the pound sign - see later). The FX-80 code to do this is ESC R NUL
12/84
Use the cursor keys to select the PREAMBLE and press the right (or lett) cursor key to erase the current value. The following three options all produce the same result and inilialise the printer:
ESC,"@,ESC,"R,NUl
27,64,27,82,0
$18,$40,$18,$52,$0
You could use thiS Item to set other printer properties, such as the line spacing or italic characters. If your printer doesn't require any initialisation then you can leave the initial setting at NONE.
The FX·80 doesn't need a POSTAMBLE so the setting can be kept at NONE.
EMPHASIZE ON and EMPHASIZE OFF codes for the Epson FX·80 are ESC E and
ESC F respectively. You can set them by typing: esc,"E esc,"F
The remaining codes can be set by typing:
Item
UNDERLINE ON
OFF
SUBSCRIPT ON
OFF
SUPERSCRIPT ON
OFF
TRANSLATE1
You type esc , Il -,"1 esc,"_ ,
"O esc,"S,"1
esc,"T esc,"S,"O esc,"T
£,esc,R,ETX,#,ESC,R,NUL
In the above example TRANSLATE 1 enables the Epson FX·80 to print a pound sign, which is only available in the English chracter set. The QL pound sign is translated to:
Switch to the English character set prinl a hash symbol (which appears as a pound sign) switch back to the Amencan chracter set
When you have finished editing the printer codes you can install the printer by pressing
F5. Alternatively you can return to the list of printers, ready to make mode changes.
Put a QL QUill or QL Abacus cartridge in M,crodrive 1 and a QL Archive cartridge in
Mlcrodrive 2. Load and run install_bas from Microdrive 1 but then press 2, followed by ENTER, to Indicate that you want to install a printer to Microdrive 2.
Follow the installation procedure as normal. The installation data will be read from
Microdrive 1 but the printer Will be installed to the cartridge in Microdrive 2.
INSTALL FOR
QL ARCHIVE
The installation program allows the installation of a printer connected to the QL via ports other than ser1 or ser2. You would use this option if, for example, you have added an optional parallel interface. Load and run install_bas as described earlier Atter you have selected installation to Microdrive 1 or 2, press the space bar to select the parallel port option.
The list of printers appears as before but when you press F1 or F2 the list of parameters appears as shown in the following table.
PARALLEL
PRINTERS
12/84
8
DRIVER NAME
PORT
LINES/PAGE
CHARACTERS/LINE
CONTINUOUS FORMS
END OF LINE CODE
PREAMBLE CODE
POSTAMBLE CODE
EMPHASIZE ON
EMPHASIZE OFF
UNDERLINE ON
UNDERLINE OFF
SUBSCRIPT ON
SUBSCRIPT OFF
SUPERSCRIPT ON
SUPERSCRIPT OFF
TRANSLATE1
TRANSLATE2
TRANSLATE3
TRANSLATE4
TRANSLATE5
TRANSLATE6
TRANSLATE?
TRANSLATES
TRANSLATE9
TRANSLATE10
Default
• DEFAULT
• NONE
.66
.80
• YES
• CR, LF
• NONE
'. NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
• NONE
Other options o to 255 o to 255
NO
You are not given the option to select the baud rate or panty since they are only relevant for a serial Interface
via
ser1 or ser2. The PORT section is also different Change this
Item by pressing either the left or right cursor key and then typing any valid device name, of up to sixteen characters. Reter to the Devices section of OL Concepts, or the manual accompanying an add on interface.
Apart from these differences, the remainder of the installation is exactly the same as described for a senal interface.
THE CONVERT
UTILITY
Version 2.0 of the install_bas program has been modified to offer a wide range of printer options. This means that it is not compatible with install_dat files created with verSion
1.
A conversion program, converL-bas, is supplied to
convert
version 1 install_dat files so that they are readable by the version 2.0 installation program.
First copy
converL-bas
to another cartr·ldge. Put the cartridge containing the copy of converL-bas in Microdrive 1 and a cartridge containing your version 1 install_dat file in Microdrive 2. Run the program by typing.
L run mdv1 convert bas
The program reads the install_dat frle in Microdrive 2 and writes the new version to
Microdrive 1. Note that the new version will replace any install_dat file on this cartridge.
You can then, if necessary, copy the new install_dat file to another cartridge.
12/84
The program config_bas allows you to specify alternative default devices for the QL programs and to modify the sort order in the Order commands of Abacus and Archive.
As supplied, the programs expect to use Microdrive 2 for storing data, and Help information and the installed printer driver are on Mlcrodrive 1. You may wish to modify these to make use of additional Microdrives, disk drives, and so on.
You may also wish .to modify the order in which ArChive records, or rows of an Abacus grid are sorted. This might be useful, for example, if you want to sort text which includes accented characters from a foreign language.
QL PROGRAM
- CONFIG
USING CONFIG
You can run confi9--bas from any Microdrive, and modify a QL program on a cartridge in either Microdrive 1 or Microdrive 2. Suppose you want to run confi9--bas from
Microdrive 2 to modify a copy of a QL program In Microdrive 1. Run the program by typing: l run mdv2_confi 9_bas
When prompted, type the name of the program you want to modify (Quill, Abacus, Easel or Archive) and press ENTER. Then enter the value 1 when asked which drive contains the program.
The program waits for you to press the space bar after you have made sure that the program cartridge is in the correct Microdrive. When you have done so the program shows you the main menu of options which are:
Select new default devices
Modify the sort order
Leave the program
Sort Order
To select the option to modify the sort order press ENTER. When prompted press the space bac
The largest area of the screen shows a block of 256 characters which define the sort order. The position in the block, reading from left to right and top to bottom, determines the character being sorted: the contents at that position shows how the character will be tested by the Order command. The riqht hand side of the screen shows more information about the character marked by the cursor Move the cursor from character to character with the cursor keys.
The block of characters at the bottom of the screen is used for modifying the order
It also has a cursor, which you move with SHIFT and the cursor keys. This block only shows half of the full set of characters - press F1 to switch between the two halves
The best way of describing how to modify the sort order IS by means of examples. As supplied, the lower case characters will be sorted to come after all the upper case ones, that is, "a" will come after "Z". Suppose you want to make the order independent of upper Or lower case so that, for example, ''A'' and '8." are not distinguished.
To make "a" be sorted as though It were ''A'', move the cursor in the main block of characters to the letter '8." and press the ''A'' key (make sure you type an upper case character). The "a" in the upper block changes to 'f;;' and the Information on the right of the screen shows that the character '8." will now be regarded as equivalent to ''A'' for the purpose of sorting.
Repeat this process for each lower case letter, making "b" equivalent to "B", 't" to "C" , and so on.
An alternative way of changing a character is to move the cursor in the lower block of characters, uSing SHIFT and the cursor keys, until it marks the character you require and then press F2. This method is particularly useful for the characters, such as foreign accented characters, that are not marked on the keys. This method is used in the following example.
Suppose you want to reverse the normal sort order for the upper case letters, leaving the rest of the ordering unchanged. To do this you must change the part of the main block that reads ''A B C ...
X Y Z" so that it reads cursor to ''A'' and the lower cursor to character ''A'' will then sort as though it were
"z
Y X.
.
C B A". Move the main
"z"
and press F2 to enter the new character. The
"z" .
Repeat this for each upper case letter, changing "6" to 'Y",
"C"
to "X", and so on.
9 12/84
When you have completed specifying the sort orde~ press F5 to save the new order in the OL program, replacing the old one. Press ESC to return to the main menu.
Device Selection
As supplied, the OL programs use Microdrive 1 for system information (the installed printer driver, for example) anD for Help. They all use Microdrive 2 for their data.
From the main menu press the space bar to choose new default devices. Press the space bar again when prompted.
After reading the current settings from your program cartridge, the program shows you these values and waits for you to type in your new choices. Press ENTER to keep an old value, or type in your new selection and press ENTER.
Having made your selection you may save your new devices, reselect the devices or cancel this option and return to the main menu.
If you save your device selection, the OL program will use these devices until you use config_bas to change them again.
10
12/84
Except for Easel the valid range for numbers in the OL programs is:
±
2.9*10 39 to
±
1.7*10 38
All calculations are accurate to sixteen significant digits but only a maximum of fourteen characters can be displayed.
In easel the range of valid numbers is
± 1.035 to
± 1.0
x 10.
36
The following arithmetic operators are provided In Abacus, Archive and Easel:
QL PROGRAM
ARITHMETIC
Operator Function
+
>
<
<~
>=
<>
Addition on numbers or concatenation on strings
Subtraction
Multiplication
Division
Raise to a power
Equal
Greater than
Lesser than
Lesser than or equal to
Greater than or equal to
Not equal to
There is no automatic coercion between data types. Therefore, operands must be of the same type. The result is always a numbe( 1 if the comparison is true and 0 if it is false.
Functions and operators have the following precedence:
Operation Precedence
Subscripting and slicing
All functions
Unary minus
*, /
+,-
=,>,<,<=,>=, not and or
<>
4
3
2
6
5
9
8
12
11
10
12/84 11
12
FORMAT
PROCEDURE
Formatting a cartridge will result in overwriting any data that was previously stored on the cartridge. This data cannot be recovered so ensure that you only format blank cartridges or cartridges that have no usetul information on them.
First decide on a name fm the cartridge, using not more than ten characters. With the
OL switched on and displaying the flashing cursor. place the cartridge to be formatted
In Microdrive 1.
Let us assume that the cartridge name is to be tJata'. Then type
FORMAT mdv1 data
Do nof confuse the underscore symbol (_) with the minus sign (-), since they are on the same key. The underscore symbol is the upper one and so SHIFT must be held down while the key
IS pressed.
Press ENTER and the left hand M,crodrive light will glow for about thirty seconds. The
OL will output a message on the screen indicating how much space is available on that cartridge The FORMAT command is described in full in the Keywords section.
It is good practice to format a new cartridge several times. This will help the tape to run smoothly and may result in a greater capacity.
The cartridge could equally well have been formatted in Microdrive 2 by substituting mdv2_ for mdv1_.
BACKUP
PROCEDURE
A backup is made by copying all the files contained on the cartridge to be backed up onto a blank cartridge. Preferably the blank cartridge will be newly formatted and named to reflect that it is a backup.
Choose a blank cartridge or a cartridge that holds no useful information and place it in Microdrive 1.
Decide on a name for the cartridge, for example, if the name of the cartridge to be backed up is 'QLdata' then 'QLdata-bak' would be a good name for the backup cartridge. Then type:
FORMAT mdv1 data bak followed by ENTER. The left hand Microdrive light Will glow for about thirty seconds.
Place the cartridge to be backed up into Microdrive 2 and type
OIR mdv2 this will list all the files contained on this cartridge.
For each file listed type:
COpy mdv2 filename TO mdv1 li/ename substituting the relevant file names where marked. This command will copy each specified file from Mlcrodrive 2 to Microdrive 1.
The speed of this operation depends on the sizes of the files being copied: the operation could take some time.
Repeat the COpy command for each of the listed files. When complete, the backup cartridge (the one in Microdrive 2) should be marked with the data and the name of the cartridge for which it is a backup and then put In a safe place.
Normally for each cartridge that you work with and wh',ch contains data you may have one, two, or more backup cartridges depending on how important the data is. If you use this system then always backup onto the oldest backup cartridge in the set.
12/84
You may find that you would like some assistance in using and getting the most out of your four supplied QL programs. The QL Users Bureau (QLUB) has been founded to enable you to do just this and keep you In touch with developments on the QL.
Membership is only available to QL owners and entitles you to a number of benefits:
• Regular newsletters will be published giving technical information an(J tipS.
Information will be given on new software and peripherals with an opportunity to buy new products in advance of the general public.
•
Sinclair Research has made arrangements for QLUB members to obtain software assistance from PSION. If you have any queries concerning the use or application of QL Abacus, Archive, Quill or Easel, all you have to do IS write to PSION direct using a OLUB Query Form and quoting your membership number. PSION will usually reply within 48 hours.
•
When updates to the four QL programs (QL Abacus, Archive, Quill and Easel) are issued they Will be offered to QLUB members at special discount prices.
• Membership of the QLUB is FREE and for LIFE
To join the QLUB please fill in the registration form In the Information section of your
QL User GUide.
Psion can assist members solely on the QL programs supplied With your QL. QL software which you buy subsequently will, where appropriate, offer separate service and update arrangements.
QL Users
Bureau
If you feel you need help in uSing the QL itself, rather than the QL programs, please refer first to the relevant section(s) in your QL User GUide. Numerous publishers are selling books about all kinds of different aspects of the QL. You may find these not only helpful but also very interesting.
Companies independent of Sinclair Research are offering QL user courses and symposia and we are encouraging such developments. We will keep all members Informed of such activities through the newsletter.
ORDER FORM
Monitor lead (2 metre)'
RS-232-C lead (2 metre)
Joystick adaptor
POST AND PACKING Orders
Ouantity under £90
£90 to £390 over £390
Please tick box if VAT receipt required:
• I enclose a cheque/postal order payable to Sinclair Research for £
• Please charge my Access/Barclaycard/
Trustcard account number
Unit Price
7.95
1495
5.95
SUB TOTAL
295
4.95
7.95
Code
6030
6040
6060
0028
0029
6999
TOTAL
• please delete as applicable
Signature:
PLEASE PRINT
Mr/Mrs/Miss
Address:
Total
D
Please send this form and your remittance (if paYing by cheque or postal order) to:
Sinclair Research Limited
FREEPOST, Camberley, SURREY GU15 3PS
Telephone: Camberley (0276) 685311
Please allow up to 28 days for delivery
,.
Your Sinclair QL IS covered by a 12 month comprehensive guarantee valid in the UK only and effective from the date of dispatch. It is not transferable. The guarantee is invalidated if the product is opened, modified, repaired or tampered with by any party other than Sinclair Research Limited or their agents. This guarantee does not affect your statutory rights.
A guarantee card is enclosed with your QL. Please read it straight away If you have not already done so.
If you have a problem then it may not be immediately clear whether this is caused by the QL itself or one of the QL program cartridges.
Please follow the instructions below.
none of the four software cartridges will load your QL is probably faulty.
all the software packages run successfully but all display a similar fault when running your QL is probably faulty If you believe your QL to be faulty, please take your complete
QL package (including the QL programs) in ItS original polystvrene box back to the shop from which you originally purchased it, together with your proof of purchase.
If you bought the QL by mall order from Sinclair Research Limited then please send the QL package to:
Sinclair Research limited,
Stanhope Road, Camberley,
Surrey, GU15 3BR
GUARANTEE
IF
THEN
OR
IF
THEN
Please use recorded delivery or registered post and keep proof of postage. Please send with the package a letter indicating your present address (and your old address if you have moved since ordering the QL), and giving any details you can about the nature of the fault which it has developed.
If your QL is faulty it will be repaired or replaced at Sinclair's option, free of charge Within the guarantee period.
one or more of the software packages fails to load, but at least one cartridge loads and runs successfully the cartridges which you have are probably faulty, and not the QL. Whether you bought the QL from a shop Or by mail order from Sinclair Research Limited please return the faulty QL program cartridge(s) in its protective case to
Sinclair Research Limited,
Stanhope Road, Camberley,
Surrey, GU15 3BR
IF
THEN
Preuzimanje
Oglas