Contents / Reference section / BASIC keywords / Previous letter / Next letter / Index


E

ELSE

Purpose

To provide an alternative course of action. ELSE can be used following an IF...THEN statement. See the pages describing the associated keywords and section 16 page 98 for more details.

Examples

560 IF length > 0 THEN PRINT "O.K." ELSE PRINT "No good"

100 IF A<>B THEN C=D ELSE PRINT "Values match"

Description

Part of the IF...THEN...ELSE structure.

Syntax

IF <testable condition> THEN <statement> ELSE <statement>

Associated keywords

IF, THEN, ON

END

Purpose

This informs the computer that it has reached the end of the program. END is optional but may be used as many times as required in a program.

Examples

9000 END

Description

Optional end-of-program which may occur anywhere and as often as is required.

The command END has a special use in that it causes BASIC to search the program in memory for a valid end program marker. BASIC then updates its internal pointers. This may be useful after unusual loading procedures. If the user changes the value of PAGE then internal pointers such as TOP will not be reset until an END statement or command is met.

Syntax

END

Associated keywords

STOP

ENDPROC end procedure

Purpose

This indicates the end of a PROCEDURE definition. See the keyword DEF on page 230 for more information.

Examples

1000 DEF PROCdash(param)

1010 REM print dashes lots of times

1020 REM in fact "param" dashes in total

1025 REM

1030 LOCAL counter

1040 FOR counter=1 TO param

1050 PRINT "-";

1060 NEXT counter

1070 ENDPROC

2010 DEF PROCtriangle(A,B,C,D,E F)

2020 REM fill a triangle with colour

2050 MOVE A,B

2060 MOVE C,D

2070 PLOT 85,E,F

2100 ENDPROC

Description

Part of the DEFPOC...ENDPROC structure

Syntax

ENDPROC

Associated keywords

DEF, FN, PROC, LOCAL

ENVELOPE

Purpose

The envelope statement is used with the SOUND statement to control the volume and pitch of a sound while it is playing. All natural sounds change in volume (loudness or amplitude); for example, the sounds from a piano start off loudly and then fade away. An aircraft flying overhead starts off softly, gets louder and then fades away.

The variation of amplitude (loudness) for the aircraft, as it flew overhead, might well look something like this:

This variation of amplitude with time is described as an "amplitude envelope".

Some sounds change in pitch. For example, a wailing police siren

This variation of pitch with time is called a "pitch envelope".

The BBC computer can use both pitch and amplitude envelopes and these are set up with the ENVELOPE statement.

Example

10 ENVELOPE l,l,4,-4,4,10,20,10,

127,0,0,-5,126,126

20 SOUND 1,1,100,200

Description

The ENVELOPE statement is followed by 14 parameters.

ENVELOPE N,T,PI1,PI2,PI3,PNl,PN2,

PN3,AA,AD,AS,AR,ALA,ALD

Parameter Range Function
N 1 to 4 Envelope Number
T bits 0-6 0 to 127 Length of each step in hundredths of a second
bit 7 0 or 1 0 = auto-repeat the pitch envelope
1 = don't auto-repeat
PI1 -128 to 127 Change of pitch per step in
section 1
PI2 -128 to 127 Change of pitch per step in
section 2
-128 to 127 Change of pitch per step in
section 3
PN1 0 to 255 Number of steps in section 1
PN2 0 to 255 Number of steps in section 2
PN3 0 to 255 Number of steps in section 3
AA -127 to 127 Change of amplitude per step during attack phase
AD -127 to 127 Change of amplitude per step during decay phase
AS -127 to 0 Change of amplitude per step during sustain phase
AR -127 to 0 Change of amplitude per step during release phase
ALA 0 to 126 Target of level at end of attack phase
ALD 0 to 126 Target of level at end of decay phase

The N parameter specifies the envelope number that is to be defined. It normally has a value in the range 1 to 4. If the BASIC statement BPUT# is not being used then envelope numbers up to and including 16 may be used.

The T parameter determines the length in centi-seconds of each step of the pitch and amplitude envelopes. The pitch envelope normally auto-repeats but this can be suppressed by setting the top bit of T - i.e. using values of T greater than 127.

The six parameters PI1,PI2,PI3,PN1,PN2 and PN3 determine the pitch envelope. The pitch envelope has 3 sections and each section is specified with two parameters; the increment which may be positive or negative, and the number of times the increment is to be applied during that section, that is the number of steps. A typical pitch envelope might look like

In the above example

T =1 centi-second

PI1=+10 PN1=12

PI2= - 5 PN2=27

PI3=+50 PN3=3

The pitch envelope is added to the pitch parameter (P) given in the SOUND statement. In the above example it must have been 40 since the pitch starts at 40. If bit 7 of the T parameter is zero then at the end of the pitch envelope; at a time given by the equation.

time=(PN1 + PN2 + PN3)*T centi-seconds

the pitch envelope will be set to zero and will repeat automatically. Note that the pitch can only take on values in the range 0 to 255 and values outside this range "fold over", that is the value used is MOD 256 of the value calculated.

The six parameters AA,AD,AS,AR,ALA and ALD determine the amplitude envelope. Although the current internal sound generator has only 16 amplitude levels the software is upward compatible with a generator having 128 levels.

The shape of the amplitude envelope is defined in terms of rates (increments) between levels, and is an extended form of the standard ADSR system of envelope control. The envelope starts at zero and then climbs at a rate set by AA (the attack rate) until it reaches the level set by ALA. It then climbs or falls at the rate set by AD (the decay rate) until it reaches the level set by ALD. However, if AD is zero the amplitude will stay at the level set by ALA for the duration (D) of the sound.

The envelope then enters the sustain phase which lasts for the remaining duration (D) of the sound. The duration, D., is set by the SOUND statement. During the sustain phase the amplitude will remain the same or fall at a rate set by "AS".

At the end of the sustain phase the note will be terminated if there is another note waiting to be played on the selected channel. If no note is waiting then the amplitude will decay at a rate set by AR until the amplitude reaches zero. If AR is zero then the note will continue indefinitely, with the pitch envelope auto-repeating if bit 7 of parameter T is zero.

A typical amplitude envelope might look like

In the above example

T= 1 centi-second

ALA= 120

ADA= 80

AA = 30 (120 in 4 centi-seconds)

AD = - 4 (- 40 in 10 centi-seconds)

AS = 0

AR = - 5 (- 80 in 16 centi-seconds)

Note that the amplitude cannot be moved outside the range 0 to 126.

Syntax

ENVELOPE <numeric>, <numeric>, <numeric>,<numeric>, <numeric>, <numeric>,<numeric>, <numeric>, <numeric>,<numeric>, <numeric>, <numeric>,<numeric>, <numeric>

Associated keywords

ADVAL, SOUND

EOF#

Purpose

This function is used to tell whether the end of the file has been reached or not. The function returns the value 0 or -1. It returns the value -1 if the end of the file has been reached. The number following EOF# is the channel number of the file.

Refer to page 190 for more information.

Example

100 X=EOF# (channel)

200 REPEAT UNTIL EOF#(y)

Description

The function used to determine whether the end of the file has been reached or not.

Syntax

<num-var>=EOF#(<num-var>)

Associated Keywords

OPENIN, OPENOUT, EXT#, PTR#, PRINT#, INPUT#, BGET#, BPUT#, CLOSE#

EOR exclusive-or

Purpose

This is a special logical operator often used to complement certain bits in a byte selectively. Refer to page 205, which explains the keyword AND, for an introduction to the concepts involved.

The process of exclusive-or tests whether the corresponding bits in two numbers are the same or different. If the corresponding bits in the two numbers are different then the resultant bit will be a 1, if they are the same it will be set to zero.

Another way of looking at this process is that it complements (changes 0 to 1 and 1 to 0) those bits in one number which are at logic 1 in the other number. Thus if

X	0000 1100 0011 0000 1110 1011
Y	1011 1111 0000 1010 0010 1000

then

X EOR Y	1011 0011 0011 1010 1100 0011

Examples

100 d%= A% EOR &FFFF00

200 R= X EOR Y

Description

An operator performing the operation of logical bitwise exclusive-or between the two operands.

Syntax

<num-var> = <numeric> EOR <numeric>

Associated keywords

NOT, AND, OR

ERL error line number

Purpose

This enables the program to find out the line number where the last error occurred. See page 147 for more information.

Example

8500 X=ERL

8100 IF ERL=100 THEN PRINT "I didn't understand"

300 IF ERL=10000 THEN CLOSE#0

Description

A function returning the line number of the line where the last error occurred.

Syntax

<num-var>=ERL

Associated keywords

ON ERROR GOTO, ON ERROR OFF, REPORT, ERR

ERR error

Purpose

If the computer finds an error that it cannot cope with, it may give up and report the error on the screen. In addition it remembers an "error number". For example if you try to calculate with numbers which are too large for the computer it will report "Too big" and remember error number 20.

Pressing the ESCAPE key behaves as an error (error number 17) and you can detect this and act on it if you wish.

It is possible to make the computer deal with most of these errors itself by writing special sections of the program to deal with the inevitable! These sections of the program need to know what the error was and where it occurred.

The function ERR enables your program to find the "error number" of the last error which occurred. This is usually used to enable the program to respond helpfully to an error caused by the user.

Examples

1000 wrong=ERR

100 IF ERR=17 THEN PRINT "YOU CAN'T ESCAPE!"

1230 IF ERR=18 THEN PRINT "You can't divide by zero!"

Description

Returns the error number of the last error which occurred.

Syntax

<num-var>=ERR

Associated keywords

ON ERROR GOTO, ON ERROR OFF, ERL, REPORT

EVAL evaluate

Purpose

This function is mainly used to enable the user to type an expression, such as a mathematical equation, into the computer while a program is running.

For example suppose that a program has to plot a graph; you need a way of getting your equation into the computer while a program is running. In most versions of BASIC. this is very difficult to do. With the BBC BASIC the equation is put into a string and then EVAL is used to tell the computer to "work out the string".

This function is not common in other versions of BASIC so a few more specific examples are given of legal instructions which can be evaluated by the statement EVAL A$

A$="M*X+C"

A$="SIN(x/120)+COS(x/30)"

Note that EVAL can only be used to evaluate functions (SIN, COS, SQR etc.) and cannot be used to execute a statement like MODE 4.

Examples

100 X=EVAL(A$)

234 value=EVAL (z$)

Description

A statement which applies the interpreter's expression evaluation program to the characters held in the argument string. An easy way to pass a function into a program from a user input.

Syntax

<num-var>=EVAL(<string>)

<str-var>=EVAL(<string>)

Associated keywords

VAL, STR$

Demonstration program

10 INPUT A$

20 FOR X=1 TO 5

30 Y=EVAL(A$)

40 PRINT Y

50 NEXT X

>RUN

?5*X

5

10

15

20

25

The second program makes the computer act as a calculator.

5 REPEAT

10 INPUT B$

20 PRINT EVAL B$

30 UNTIL FALSE

>RUN

?3+4

7

?SIN (RAD (45))

0.707106781

?

EXP exponent

Purpose

This mathematical function calculates e (2.7183...) raised to any specified power.

Examples

120 Y=EXP(X)

3000 pressure=EXP (height)

Description

A function returning e to the power of its argument.

Syntax

<num-var>=EXP(<numeric>)

Associated keywords

LN, LOG

EXT# extent

Purpose

This finds out how large a particular file is. It only works with disc and network file systems - not with cassette files. The number returned is the number of bytes allocated to the file. The file to be investigated must have been opened using the OPENIN or OPENOUT statements. See page 188 for more information on file handling.

Examples

100 X=EXT#(employee)

PRINT EXT# (N)

Description

A function which returns the length in bytes of the file opened on the channel given in its argument.

Syntax

<num-var>=EXT#(<num-var>)

Associated keywords

CLOSED, PTR#, INPUTS, PRINT#, BGET#, BPUT#, OPENIN, OPENOUT, EOF#

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001