BBC BASIC 2.31 for the Tatung Einstein, showing DRIFT, the text adventure the course builds, in the middle of a game
← Back to Courses
module
5

Changing Your Mind

Introduction

You will mistype things. Everybody does, and on a machine where a program is typed in by hand it matters more than it sounds: a forty-line program is a lot of typing to repeat because of one wrong letter.

BBC BASIC is well equipped for this. You can move about a line before you press ENTER, you can call a stored line back up and change it, and three commands take care of the numbering.

Moving About A Line

Before you press ENTER, the line is just characters on the screen and you can change them. The keys are all CTRL and a letter:

KeyWhat it does
DELETErubs out the character to the left
CTRL-Hmoves left, without rubbing anything out
CTRL-D (or TAB)moves right
CTRL-Kjumps to the start of the line
CTRL-J (or the down arrow)jumps to the end of the line
CTRL-Fdeletes the character under the cursor
SHIFT-DELETEopens a space at the cursor, to type into
CTRL-Uclears from the cursor to the end of the line
CTRL-Xclears from the cursor back to the start of the line

In MAME: DELETE is Backspace, and CTRL is Ctrl (Control on a Mac, not Command).

Typing replaces what is under the cursor. Move back over a mistake and type the right letter on top of it. If you need an extra letter, SHIFT-DELETE opens a space for it first.

The arrow keys do not move the cursor. On the Einstein the left, right and up arrows type characters - [, ] and ^, which appear on the screen as little arrows. If you press one by accident you will see it arrive. CTRL-H is the left arrow you wanted.

Changing A Line That Is Stored

EDIT brings a stored line back to be changed:

EDIT 10

BBC BASIC prints line 10, number and all, and puts the cursor at the start of it. Everything in the table above works on it. Press ENTER and the changed line is stored in place of the old one - it does not matter where on the line the cursor is when you do. Press ESC and the edit is abandoned: the line stays as it was.

The number is part of what you are editing. Change it, and the line is stored under the new number as well - the old one is still there. That makes EDIT the way to copy a line.

Numbering Lines For You

Typing 10, 20, 30 at the start of every line gets dull. AUTO does it:

AUTO

BBC BASIC offers 10 and waits. Type the rest of the line and press ENTER, and it offers 20. And so on. ESC stops it: you see Escape, the > comes back, and the number it was offering is not used.

AUTO 100,5 starts at 100 and goes up in fives.

Renumbering

Once you have squeezed lines into 21, 22 and 23 and run out of room, RENUMBER tidies the whole program up:

RENUMBER

renumbers from 10 in tens. RENUMBER 100,5 starts at 100 and steps by 5.

It fixes the jumps as well. You will meet GOTO later, a line that sends the program to another line by number; when RENUMBER moves that line, it rewrites the GOTO to match.

Deleting Several Lines

A number on its own deletes one line, as S4 showed. For a run of them:

DELETE 20,40

deletes lines 20 to 40, both included. There is no OLD for this: they are gone.

The Code

Type these three lines, deliberately getting line 10 wrong:

10 PRINT "THE CAT SAT"
20 PRINT "ON THE MAT"
30 PRINT "THE END"

Now make it a bat instead of a cat without retyping the line:

  1. Type EDIT 10 and press ENTER. Line 10 appears with the cursor at its start.
  2. Press CTRL-D seventeen times, to get across to the C of CAT.
  3. Type B.
  4. Press ENTER.

Starting from

A fresh boot, or NEW.

What you should see

After the edit, LIST shows line 10 changed and the other two untouched, and RUN gives:

>RUN
THE BAT SAT
ON THE MAT
THE END
>

Line 10 corrected with EDIT

Change One Thing

  • Do the same edit on line 20, but press ENTER while the cursor is still in the middle of the line. Does it matter where the cursor is?
  • EDIT 10 again, move the cursor onto the 1 of 10, type 4 and press ENTER. Now LIST. How many lines are there, and which is which?
  • Type RENUMBER 100,5 and LIST. What have the line numbers become?

Exercises

5.1 Use AUTO to type a three-line program that prints ONE, TWO and THREE. Leave AUTO when you are done, and LIST it.

5.2 Type a program numbered 1, 2 and 3. Make it 10, 20 and 30 without retyping any of it.

5.3 Add lines 40 and 50 to that program, then remove lines 20 to 40 in one command.

Worked solutions are in Appendix II.

When It Goes Wrong

SymptomCause
A little arrow appears in your lineYou pressed an arrow key, which types a character. Rub it out with DELETE, and move with the CTRL keys.
Letters you typed replaced the ones that were thereTyping overwrites. Press SHIFT-DELETE first to open a space.
Mistake after EDITThe line you stored is not what you meant - the cursor was somewhere else when you typed. EDIT it again.
You EDITed a line and now there are twoYou changed its number. The old line is still there; delete it with its number alone if you meant to move it.
AUTO keeps offering numbersPress ESC.

Summary

CTRL-H, CTRL-D, CTRL-K and CTRL-J move about a line; DELETE, CTRL-F, CTRL-U and CTRL-X remove things; typing overwrites. EDIT brings a stored line back to be changed or copied. AUTO numbers for you, RENUMBER tidies up, and DELETE removes a run of lines.

Next

S6, Keeping Your Work - saving a program to disc, and getting it back after the Einstein has been switched off.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.