# `EDIT` — `EXTERNAL`

## Contents

- `EDIT` — Displays a string for editing
- `ELSE/ELSEIF/ENDIF` — See `IF`
- `ENDA` — See `APP`
- `ENDV` — See `VECTOR`
- `ENDWH` — See `WHILE`
- `EOF` — Checks for end-of-file
- `ERASE` — Erases a record in the current data file
- `ERR` — Number of last error
- `ERR$` — Looks up an error message by number
- `ERRX$` — Gets an extended error message
- `ESCAPE OFF` — Disables Ctrl+Esc
- `EVAL` — Evaluates a mathematical expression
- `EXIST` — Checks if a file exists
- `EXP` — Exponential
- `EXTERNAL` — Declares procedure prototypes and external variables

## `EDIT` — Displays a string for editing

Usage: `EDIT a$`

Displays a string variable which you can edit directly on the screen. All the usual editing keys are available the arrow keys move along the line, Esc clears the line, and so on.

When you have finished editing, press Enter to confirm the changes. If you press Enter before you have made any changes, then the string will be unaltered.

If you use `EDIT` in conjunction with a `PRINT` statement, use a comma at the end of the `PRINT` statement, so that the string to be edited appears on the same line as the displayed string:

        ...
        PRINT "Edit address: ",
        EDIT A.address$
        UPDATE
        ....

#### TRAP EDIT

If the Esc key is pressed while no text is on the input line, the ‘Escape key pressed’ error (-144) will be returned by `ERR` provided that the `EDIT` has been trapped. You can use this feature to enable the user to press the Esc key to escape from inputting a string.

See also `INPUT`, `dEDIT`.

## `ELSE/ELSEIF/ENDIF` — See `IF`

See `IF`.

## `ENDA` — See `APP`

See `APP`.

## `ENDV` — See `VECTOR`

See VECTOR

## `ENDWH` — See `WHILE`

See `WHILE`.

## `EOF` — Checks for end-of-file

Usage: `e%=EOF`

Finds out whether you’re at the end of a file yet.

Returns -1 (true) if the end of the file has been reached, or 0 (false) if it hasn’t.

When reading records from a file, you should test whether there are still records left to read, otherwise you may get an error.

Example:

        PROC eoftest:
              OPEN "myfile",A,a$,b%
              DO
                    PRINT A.a$
                    PRINT A.b%
                    NEXT
                    PAUSE -40
              UNTIL EOF
              PRINT "The last record"
              GET
              RETURN
        ENDP

## `ERASE` — Erases a record in the current data file

Usage: `ERASE`

Erases the current record in the current file.

The next record is then current. If the erased record was the last record in a file, then following this command the current record will be null and EOF will return true.

## `ERR` — Number of last error

Usage: `e%=ERR`

Returns the number of the last error which occurred, or 0 if there has been no error.

Example:

              ...
              PRINT "Enter age in years"
        age::
              TRAP INPUT age%
              IF ERR=-1
                    PRINT "Number please:"
                    GOTO age
              ENDIF
              ...

You can set the value returned by `ERR` to 0 (or any other value) by using `TRAP RAISE 0`. This is useful for clearing `ERR`.

See also `ERR$`,`ERRX$`. See Runtime errors — Handling errors reported while running programs for full details, and OPL error values for the list of error numbers and messages.

## `ERR$` — Looks up an error message by number

Usage: `e$=ERR$(x%)`

Returns the error message for the specified error code `x%`.

`ERR$(ERR)` gives the message for the last error which occurred. Example:

        TRAP OPEN "\FILE",A,field1$
        IF ERR
              PRINT ERR$(ERR)
              RETURN
        ENDIF

See also `ERR`, `ERRX$`. See Runtime errors — Handling errors reported while running programs for full details, and OPL error values for the list of error numbers and messages.

## `ERRX$` — Gets an extended error message

Usage: `x$=ERRX$`

Returns the current extended error message (when an error has been trapped), e.g.

        ‘Error in MODULE\PROCEDURE,EXTERN1,EXTERN2,...’

which would have been presented as an alert if the error had not been trapped. This allows the list of missing externals, missing procedure names, etc. to be found when an error has been trapped by a handler.

See Runtime errors — Handling errors reported while running programs for full details, and OPL error values for the list of error numbers and messages.

## `ESCAPE OFF` — Disables Ctrl+Esc

Usage:

        ESCAPE OFF
        ...
        ESCAPE ON

`ESCAPE OFF` stops Ctrl+Esc being used to break out of the program when it is running. `ESCAPE ON` enables this feature again.

`ESCAPE OFF` takes effect only in the procedure in which it occurs, and in any sub-procedures that are called. Ctrl+Esc is always enabled when a program begins running.

If your program enters a loop which has no logical exit, and `ESCAPE OFF` has been used, you will have to go to the Task list, move to the program name, and select `Close file`.

## `EVAL` — Evaluates a mathematical expression

Usage: `d=EVAL(s$)`

Evaluates the mathematical string expression `s$` and returns the floating-point result. `s$` may include any mathematical function or operator. Note that floating-point arithmetic is always performed.

`EVAL` runs in the "context" of the current procedure, so globals and externals can be used in `s$`, procedures in loaded modules can be called and the current values of gX and gY, can be used etc. `LOCAL` variables cannot be used in `s$` (because the translator cannot deference them).

For example:

        DO
              AT 10,5 :PRINT "Calc:",
              TRAP INPUT n$
              IF n$="" :CONTINUE :ENDIF
              IF ERR=-114 :BREAK :ENDIF
              CLS :AT 10,4
              PRINT n$;"=";EVAL(n$)
        UNTIL 0

See also `VAL`.

## `EXIST` — Checks if a file exists

Usage: `e%=EXIST(filename$)`

Checks to see that a file exists. Returns `KTrue%` if the file exists and `KFalse%` if it doesn’t.

Use this function when creating a file to check that a file of the same name does not already exist, or when opening a file to check that it has already been created:

        IF NOT EXIST("CLIENTS")
              CREATE "CLIENTS",A,names$
        ELSE
              OPEN "CLIENTS",A,names$
        ENDIF
        ...

## `EXP` — Exponential

Usage: `e=EXP(x)`

Returns ex — that is, the value of the arithmetic constant e (2.71828...) raised to the power of `x`.

## `EXTERNAL` — Declares procedure prototypes and external variables

Usage: `EXTERNAL variable
`or `EXTERNAL prototype`

Required if `DECLARE EXTERNAL` is specified in the module.

The first usage declares a variable as external. For example, `EXTERNAL screenHeight%`

The second usage declares the prototype of a procedure (`prototype` includes the final `:` and the argument list). The procedure may then be referred to before it is defined. This allows parameter type-checking to be performed at translate-time rather than at runtime and also provides the necessary information for the translator to coerce numeric argument types. This is reasonable because OPL does not support argument overloading. The same coercion occurs as when calling the built-in keywords.

Following the example of C and C++, you would normally provide a header file declaring prototypes of all the procedures and `INCLUDE` this header file at the beginning of the module which defines the declared procedures to ensure consistency. The header file would also be `INCLUDE`d in any other modules which call these procedures. Then you should use `DECLARE EXTERNAL` at the beginning of modules which include the header file so that the translator can ensure that these procedures are called with correct parameter types or types which can be coerced.

The following is an example of usage of `DECLARE EXTERNAL` and `EXTERNAL`:

        DECLARE EXTERNAL
        EXTERNAL myProc%:(i%,l&)
        REM or INCLUDE "myproc.oph" that defines all your procedures

        PROC test:
              LOCAL i%,j%,s$(10)

              REM j% is coerced to a long integer
              REM as specified by the prototype.
              myProc%:(i%,j%)

              REM translator ‘Type mismatch’ error:
              REM string can’t be coerced to numeric type
              myProc%:(i%,s$)

              REM wrong argument count gives translator error
              myProc%:(i%)
        ENDP

        PROC myProc%:(i%,l&)
              REM Translator checks consistency with prototype above
              ...
        ENDP

See `DECLARE EXTERNAL`.