# Micro­power

## Volume 1, Number 2 – September 1981

using POKE instructions, because if you get the numbers wrong you may corrupt the Basic program, change the value of a variable, or affect the operation of the monitor. For example, try typing POKE 3111,1/Enter. You will find that your keyboard is now in ‘ typewriter’ mode, and you will have to use the shift key to type upper case letter. To change back, enter POKE 3111,0 (Basic will accept commands in lower case). Similarly, POKE 3111,4 will change the keyboard to ‘graphics’ mode.

I will now sneak a quick look at the PEEK command (although it isn’t in the above list), because it is complementary to POKE. PEEK(X) tells you the value stored at memory location X. Thus PRINT PEEK(2531) will print the (decimal) value stored at the screen centre. This also illustrates the difference between Basic commands and Basic functions. A command tells the machine to do something; a function asks it a question, but you have to use a command to do something with the answer. Thus entering PEEK (2531) has no obvious effect, you must precede it with a PRINT command for the answer to appear on screen.

### STRINGS

A string is simply a series of characters. In the program above the string variable, Z\$, is first defined by equating it to the expression between quotation marks, PROGRAM TITLE, so that when the program subsequently meets Z\$ it knows that it refers to this expression.

### LEN(Z\$)

This function gives the length of Z\$, i.e., the number of characters, including spaces, in the string. Thus if you enter PRINT LEN (“THIS IS A STRING”) the computer will produce the answer 16. The same result is obtained with PRINT LEN(Z\$) is Z\$ has previously been defined as “THIS IS A STRING”.

### ASC(X\$)

This returns the decimal value of the ASCII code of the first character of string X\$. Thus ASC(“FRED”) has the value 70, because the ASCII code for F is £46 and 4x16 + 6 = 70.

### MID\$(X\$,I,J)

You often need to be able to access specific groups of letters in a string, and the most versatile of the basic string handling functions for this purpose is MID\$(...). It extracts J consecutive letters from the middle of a string, starting at the Ith letter. Note that this function returns a string, not the ASCII equivalent of a string, so if you type PRINT MID\$(“MISS PIGGY”,6,3) the computer will print PIG.

### FOR . . TO . . STEP . . NEXT

Since the first thing that most new computer owners do to try out Basic is type:

```10 FOR A = 1 TO 50:PRINT “HELLO”:NEXT
```

FOR . . NEXT loops will presumably be familiar to everyone. STEP can be omitted if you want to increment in steps of one; it has only been included in the program