# 14. Chaprola Command Examples

All examples are transcribed from the original documentation at johnletcher.com.

## 14.1 CALL and RETURN

```
   CALL 100
   STOP
100 [Any Number of Commands]
   RETURN
```

When statement number 100 is called, the program skips everything between the CALL and the statement number. When the computer completes its task and reaches RETURN, the program returns to the line after the last CALL that was executed. Up to nine CALL statements can be nested without a RETURN.

## 14.2 FIND

```
FIND R20 FROM -25 10 USING 15
```

Places the record number of an exact match into R20. Searches the secondary record at character position -25 for a length of 10, comparing against the reference string at primary position 15. The secondary file must be sorted on the field being searched.

## 14.3 GET

```
GET R7 FROM 26 6
```

Gets a number from location 26 for a length of 6 and places it into register 7. An error occurs if the location contains anything other than blanks or a real number.

## 14.4 GOTO

```
GOTO 17
```

Sends the computer to statement number 17. Nothing between the GOTO and the statement number is read.

## 14.5 IF Examples

### IF LEGAL

```
IF LEGAL 20 7 GET R27 FROM 20 7 ;
```

Checks character position 20 for a length of 7 to see if the string is a valid number. If valid, the GET command places the number into register 27.

### IF BLANK

```
IF BLANK 100 25 GOTO 100 ;
```

If character position 100 for a length of 25 is blank, the GOTO statement executes.

### IF NOT BLANK (Menu Driver)

```
IF NOT BLANK 26 1 MOVE "7    1SCRATCH SCRATCH SCRATCH " 6023 32 ;
```

The basis for a menu-driving program. Checks position 26 for a length of 1. If not blank, sets up the computer for changing display, data, and procedure files.

### IF EQUAL (Memory Comparison)

```
IF EQUAL 25 -50 25 WRITE 32000 ;
```

Compares location 25 (primary) to location -50 (secondary) for a length of 25. If identical, writes the secondary memory area to the end of the secondary file.

### IF EQUAL (Literal Comparison)

```
IF EQUAL "F" 26 1 GOTO 1200 ;
```

Compares character position 26 for a length of 1 to the literal "F". If equal, goes to statement 1200.

### IF FOERR

```
IF FOERR RETURN ;
```

If there was a problem executing the OPEN statement, returns to the last CALL.

### IF EOF

```
IF EOF GOTO 120 ;
```

When the EOF flag is true (no such record found or end of file reached), executes GOTO 120.

## 14.6 INSERT

```
INSERT 12 5079
PRINT 0 1
```

Inserts a form feed character (ASCII 12) at position 5079, so the PRINT command causes the printer to advance to the next page.

## 14.7 LET

### Simple Assignment

```
LET R12 = 6.25
LET R12 = 0.625E+1
```

### Arithmetic

```
LET R16 = R12 * 4.0
```

### Complex Expression

The expression `(R3*(R1-R2)/R4)+R5 = R6` must be broken down:

```
LET R7 = R1 - R2
LET R8 = R3 * R7
LET R9 = R8 / R4
LET R6 = R9 + R5
```

Or, reusing registers:

```
LET R7 = R1 - R2
LET R1 = R3 * R7
LET R2 = R1 / R4
LET R6 = R2 + R5
```

## 14.8 MOVE

### Memory to Memory

```
MOVE 12 -30 8
```

Moves 8 characters from primary position 12 to secondary position -30.

```
MOVE R3 5001 20
```

Moves 20 characters from the position stored in R3 to user buffer position 5001.

### Literal String

```
MOVE "7" 6023 1
MOVE "    1" 6026 5
MOVE "TESTFILETESTFILETESTFILE" 6031 24
```

Sets IVAL to 7, record to 1, and all three filenames to "TESTFILE". Combined form:

```
MOVE "7    1TESTFILETESTFILETESTFILE" 6023 32
```

### MOVE BLANKS

```
MOVE BLANKS 48 1
MOVE BLANKS 1 48
```

## 14.9 OPEN

```
OPEN "TESTFILE" 0
OPEN "TESTFILE" 96
```

The first opens with auto-detected record length (slower). The second specifies 96-character records (faster).

## 14.10 PUT

With R3 containing 4.673224E+3:

```
PUT R3 INTO 5028 9 D 2     . Result: $4,673.22
PUT R3 INTO 1019 9 F 3     . Result: 4673.224
PUT R3 INTO -305 9 I 0     . Result: 4673
PUT R3 INTO 200 9 I 2      . Result: 4.67E+3
```

## 14.11 READ

```
READ 7
READ R6
```

## 14.12 WRITE

```
WRITE 32000
WRITE R7
WRITE 38
```

`WRITE 32000` appends to the end of the secondary file (since 32,000 is the maximum record count).

---

*Previous: [MOMS System](13-moms.md)*
