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


L

LEFT$ left string

Purpose

To copy part of a string starting at the left-hand end of the source string. For example if

A$="CATASTROPHE"

then

PRINT LEFT$(A$,3)

would give CAT, namely the left 3 characters of A$.

Examples

100 INDEX$=LEFT$(WHOLEname$,4)

3000 U$=LEFT$(H4$,value)

Description

A string function which returns the left n characters from a string. If the source string is too short then the function returns with as many characters as there are in the source string. There must be no space between LEFT$ and the first bracket.

Syntax

<string-var>=LEFT$(<string>,<numeric>)

Associated keywords

RIGHT$, MID$, LEN, INSTR

Demonstration program

This prints out letters in a pattern

10 PRINT "What is your full name";

20 INPUT name$

30 FOR X=1 TO LEN(name$)

40 PRINT LEFT$(name$ X)

50 NEXT X

>RUN

What is your full name?JOHN A COLL

J

JO

JOH

JOHN

JOHN

JOHN A

JOHN A

JOHN A C

JOHN A CO

JOHN A COL

JOHN A COLL

LEN length (of a string)

Purpose

This function counts the number of characters in a string. For example

K=LEN("FRIDAY ")

would give K=7 since there are six letters in "FRIDAY" and it is followed by a space.

This function is often used with a FOR...NEXT loop to do something once for each letter in a string. For example, we might wish to encode a word by replacing each letter by its successor in the alphabet so that, for example, "FRIDAY" would becomes "GSJEBZ". See the demonstration program.

Examples

100 X=LEN(A$)

2350 length=LEN(main$)

Description

This function returns the length of the string given as the argument.

Syntax

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

Associated keywords

LEFT$, MID$, RIGHT$, INSTR

Demonstration program

300 PRINT "Type in your word";

310 INPUT A$

320 length=LEN(A$)

325 C$=""

330 FOR Y=1 TO Length

340 B$=MID$(A$,V,1)

350 C$=C$+CHR$(ASC(B$)+1)

360 NEXT V

370 PRINT "The coded version is ";C$

In the above program each letter is copied one at a time into B$. Then its ASCII value is calculated, 1 is added to the ASCII value and the new ASCII value is converted back into a character which is then added onto C$. See the keyword ASC on page 207 for more information about the ASCII code.

LET

Purpose

In BASIC we often write things like

X=6

meaning put 6 into the box labelled X in the computer. The fact that we are changing the contents of the variable X can be made clearer by writing

LET X=6

The statement "X=X+6" is impossible in mathematical terms. How can something be the same as itself plus 6? In BASIC though it is quite legal to say LET X=X+6 since the instruction simply means

"store in the variable X whatever is already there plus 6"; or

"increase the value of X by 6".

The word LET is optional, but its use makes the program more readable.

Examples

100 LET length=15

980 LET DAY$ ="Tuesday"

210 IF A=6 THEN LET A=A+10

1000 IF length<12 THEN LET length=12

Description

LET is an optional assignment statement.

Note: LET may not be used during the assignment of the psuedo-variables LOMEM, HIMEM, PAGE, PTR#, TIME

Syntax

LET <var>=<expression>

LIST

Purpose

This command makes the computer list out whatever program it has in its memory. It is often used before typing RUN to ensure that there aren't any typing errors in the program just entered.

You can list a single line

LIST 280

or a range of lines

LIST 100,450

or the whole program

LIST

LIST ,400 will list all lines up to and including line 400.

LIST 400, will list all lines beyond line 400.

If you have a very long program you may see the whole listing whiz past before you have time to read it. To stop that, and to make the computer stop at the bottom of each page you can type CTRL N (whilst holding down the key marked CTRL press the letter N). Then type LIST. This is called "paging mode" and the computer stops at the bottom of each page. The next page will be printed when the SHIFT key is pressed.

To return to "scroll mode" type CTRL O (hold CTRL down while briefly pressing O).

If you want a listing on the printer then you can turn the printer on by typing CTRL B before typing LIST.

To turn the printer off afterwards type CTRL C.

LIST is a command and cannot be used as part of a program or as part of a multiple statement line.

The layout of programs as listed can be controlled by the command LISTO (see next entry). As an option, the computer can be instructed to insert spaces for the duration of all FOR...NEXT and REPEAT...UNTIL loops.

Examples

LIST

LIST 400

LIST 400,500

LIST ,900

LIST 900,

Description

A command which lists the current program.

Syntax

LIST[<num-const>][,<num-const>]

Associated keywords

NEW, OLD, LISTO

LISTO list option

Purpose

When a program is listed on the screen or the printer, it is often convenient to show all loops within the program indented.

LISTO can be used to control the way that the LIST command displays a program on the screen. It can cause the computer to insert spaces in three situations

a after the line number

b during FOR...NEXT loops

c during REPEAT...UNTIL loops

The number following LISTO should be in the range 0 to 7.

0 implies no inserted spaces

1 implies a space after the line number

2 implies spaces during FOR...NEXT loops

4 implies spaces during REPEAT...UNTIL loops

The numbers which select each option (1,2 or 4) can be added together to select multiple options. If spaces were required during FOR...NEXT and REPEAT...UNTIL loops then LISTO 6 would be selected. LISTO 7 puts a space after the line number and double spaces for FOR...NEXT and REPEAT...UNTIL loops.

The most common options are LISTO 0 and LISTO 7.

When editing programs using the cursor editing keys it is strongly advised that you use the LISTO 0 option or else you will COPY in a lot of extra space.

Description

LISTO effects the print format produced by subsequent LIST commands. Bit 0 of the argument controls the single space after the line number; Bit 1 the double space on

FOR...NEXT loops; Bit 2 the double space on REPEAT...UNTIL loops.

Syntax

LISTO <num-const>

Associated keywords

LIST

LN natural logarithm

Purpose

A mathematical function to calculate logarithms to the base e - usually called "natural logarithms".

Examples

100 X=LN(temp)

3000 H5=LN(REDOXpotential)

Description

A function returning the natural logarithm of its argument.

Syntax

<num-var>=LN<numeric>

Associated keywords

LOG, EXP

LOAD

Purpose

To load a program into the computer from cassette tape, floppy disc or the network, whichever is the current file system.

A WELCOME cassette containing some games is provided with the computer and these games can be loaded into the computer with the keyword LOAD. If you have problems loading a program then see page 34. The keyword LOAD is followed by the 'file name'. This file name may contain up to 10 characters and must be enclosed in quotation marks, e.g.

LOAD "GAME1"

Once the program has been loaded, type RUN to start it.

When you use the word LOAD, the computer forgets any previous program that it had in memory and also the values of all variables.

If you are loading from cassette, then the computer will show the name of each section of the program as it finds it on the cassette.

LOAD does not run a program. It just loads it into memory. It clears all variables except A% to Z% and @%. It cannot be used in a program.

LOAD"" will load the next program found on a tape. This form does not work on disc or net or other file systems.

The statement CHAIN can be used in a program (or as a command) to load another program and to start that program running automatically.

Examples

LOAD "STARWARS"

LOAD "MYPROG"

Description

The command LOAD deletes the current program, clears all variables except the resident integer variables and then loads a new program from the current file system. The program to be loaded must be in internal format.

Since LOAD is a command it cannot form part of a multiple statement line.

Syntax

LOAD <string>

Associated keywords

SAVE, CHAIN

LOCAL

Purpose

This informs the computer that the named variables are "local" to the procedure or function in which they occur; their use in this procedure or function in no way affects their value outside it. See the keyword DEF on page 230 for more information.

Examples

560 LOCAL X,Y,A$,B$

Description

A statement which can only be used inside a procedure or function definition. LOCAL saves the values of the external variables named and restores these original values when the function or procedure is completed.

Syntax

LOCAL <string-var>|<num-var>{,<string-var>|<num-var>}

Demonstration program

780 DEF PROCdrawTRIANGLE(size)

790 LOCAL Xl,X2,Y1,Y2

800 X1=320-size

810 X2=320+size

820 Yl=256-size

830 Y2=256+size

840 MOVE X1,Y1

850 DRAW X2,Y1

860 DRAW 320,Y2

870 DRAW Xl,Y1

880 ENDPROC

Associated keywords

DEF, ENDPROC, FN, PROC

LOG logarithm

Purpose

A mathematical function to calculate the common logarithm of a number to base 10.

Examples

100 Y=LOG (y)

440 pressure=LOG(speed)

Description

A function giving the common logarithm to base 10 of its argument. Inverse logarithms (anti-logarithms) can be calculated by using

Y=10^X

Syntax

<num-var>=LOG<numeric>

Associated keywords

LN, EXP

LOMEM

Purpose

Different sections of the computer's memory are used for different purposes. Normally BASIC makes an intelligent decision about where to store the numbers that the user calls X and Y$ etc. In fact it stores these variables immediately after the user's program. You can change the place where it starts to store these variables by changing the value of LOMEM.

The variable LOMEM gives the address of the place in memory above which the computer stores all its variables (except for the resident integer variables @% and A% to Z%.

LOMEM is normally set to be the same as TOP which is the address of the top of the user program. See the keyword HIMEM on page 270 and the memory map on page 501 for more details.

Do not accidentally move LOMEM in the middle of a program - the interpreter will lose track of all the variables that you are using.

Examples

100 LOMEM=TOP+&100

PRINT LOMEM

PRINT~LOMEM

NB The ~ tells the computer to print the value in hexadecimal.

Description

A pseudo-variable which sets the place in memory above which the BASIC interpreter stores dynamic variables - those that are created and destroyed as required. Space is always set aside for the "resident variables" @% to Z%. Normally LOMEM is set equal to TOP which contains the address of the end of the user program.

Moving LOMEM in the middle of a program will cause loss of all variables.

Syntax

LOMEM=<numeric>

or

<num-var>=LOMEM

Associated keywords

HIMEM, TOP, PAGE

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