## The seventh program.

We are now ready to put everything together. MiniBasic has facilities for input, output, mathematical and lexical calculation, flow control, and multi-dimensional arrays.

String handling may be different to what you are used to in other versions of BASIC. In MiniBasic all functions that return a string end with the character ?$?. These include CHR$(), STR$(), LEFT$(), RIGHT$(), MID$() and STRING$(). There is no limit to string length other than the computer?s memory.

Some functions take a string argument, but return a numerical variable. These include LEN(), the length of the string, and ASCII() ? the ASCII code of the first character of the string, also VAL() ? the numerical value of string of digits. Internally, the NUL character, ASCII value 0, is used to terminate strings. The empty string ?? consists of a single NUL.

Here is a program which inputs a full name, checks for validity, and stores it in an array of variables.

`10 REM String-handling program
20 REM Inputs a name, tests for validity
30 REM and breaks up into parts.
40 PRINT "Enter your full name"
50 INPUT name$
60 REM First check for non-English characters
70 LET flag = 0
80 FOR I = 1 TO LEN(name$)
90 LET ch$ = MID$(name$, I,1)
100 IF (ch$ >= "A" AND ch$ <= "z") OR ch$ = " " THEN 140
110 LET flag = 1
120 REM This forces the loop to stop
130 LET I = LEN(name$)
140 NEXT I
150 IF flag = 0 THEN 180
160 PRINT "Non-English letter,", ch$
170 GOTO 40
180 REM Jump to subroutine
190 LET return = 210
200 GOTO 1000
210 IF name$ = "" THEN 280
220 LET return = 240
230 GOTO 2000
240 LET N = N + 1
250 DIM out$(N)
260 LET out$(N) = word$
270 GOTO 180
280 REM Print out the name
285 PRINT "Name accepted"
290 FOR I = 1 TO N
300 PRINT out$(I) + " ";
310 NEXT I
320 PRINT ""
330 GOTO 3000
1000 REM strips the leading space
1010 IF LEFT$(name$, 1) <> " " THEN return
1020 LET name$ = MID$(name$, 2, -1)
1030 GOTO 1010 <BR.
2000 REM get the leading word and put it in word$
2010 LET word$ = ""
2020 LET ch$ = LEFT$(name$, 1)
2030 IF ch$ < "A" OR ch$ > "z" THEN return
2040 LET word$ = word$ + ch$
2050 LET name$ = MID$(name$, 2, -1)
2060 GOTO 2020
3000 REM END
`