Overview |
The REXX language in combination with ZOC basically consists of three parts:
1. Basic REXX instructions (CALL, IF, END, etc.)
2. REXX built in functions. (TIME(), SUBSTR(), STRIP(), etc.)
3. ZOC Extensions (ZocSend, ZocDownload, ZocWait, etc.)
This topic covers the essential parts of points 1. and 2.
ZOC specific extension (3.) are listed in ZOC-REXX Commands/Functions.
If you look at the My Documents→ZOC Files→REXX folder on your computer, you will find a link to ZOC REXX Reference (PDF), document, which will cover all three points above in great depth. A link to other REXX resources. can also be found there.
Last but not least, there is a ZIP archive with Zoc scripting samples
(ZocScriptingSamples.zip)
in the folder mentioned above. Most of the topics which are presented here,
are also demonstrated in the those samples.
Essential REXX Language Elements |
Command Placement | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
In REXX comments can span multiple lines when they are placed between /* and */. REXX also knows single line comments, which start with a -- sequence and which automatically end when the line ends. More than one command can be placed in one line by separating them by semicolons.
A command can be continued in the next line by placing an
extra comma at the end of the line.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numbers and Arithmetics | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numbers can be used for calculation, counting etc. REXX uses
numbers and the arithmetic in a pretty straightforward way:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Strings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REXX programs often process text in one way or another. While REXX
inherently knows no types (values are treated as numbers or strings
depending on the context), it is generally better to put all
text strings in single or double quotes:
You can assign strings to variables. Strings in quotes and string variables can simply
be concatenated by writing them after one another, although sometimes the string concatenation
operator || can be used for clarity or to resolve ambiguities.:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Tracing | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To find errors in your REXX program (or to watch the program execution) you can insert a TRACE A command into your REXX program (usually after the initial comment). With that, the REXX interpreter will display each instruction in the program as it executes it.
TRACE I will show very detailed tracing and TRACE O
turns tracing off. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Conditionals | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To express conditions in REXX programs, the following conditional operators are used:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Decisions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Decisions are made using the
IF <condition> THEN DO <commands> END ELSE DO <commands> END
sequence (see above for conditionals).
The ELSE-part can be omitted if it is not needed. The keywords
DO and END can be omitted if only one command is to be
executed conditionally.:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Loops | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Loops are expressed in the following form:
DO <count> <commands> END
Loops can be aborted from within using the LEAVE command. The ITERATE
command will skip the rest of the loop body for the current iteration and will continue
with the next loop iteration.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Jumps and Procedures (Subroutines) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Jump targets (labels) and subroutines are marked with a name and a colon. To jump to a label, use the SIGNAL command. The CALL command is used to call a subroutine (which will return to the place it was called from via RETURN).
The following example demonstrates a jump and a call to a subroutine
with argument passing:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Function Calls | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Functions are marked and called like procedures. The difference is that
the can return a value to the calling command:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
External Calls | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It is also possible to call an external script file as a subroutine and pick up a possible result. To do this, the name of the external script files needs to be placed in quotes. The called script then needs to be placed either in the ZOC program folder, in the ZOC Files folder, in the ZOC script files folder or in a folder which is listed in the PATH or REGINA_MACROS variable in the system environment (e.g. C:\1). Alternately you can specify a full folder and file name for the file. Parameters are passed as usual (separated by commas).
If you have a scriptname or path in a REXX variable the regular call Syntax will
not work though, but you can build a string which contains the complete command
and pass it through the INTERPRET command (see the sample below).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The PARSE command | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
PARSE is a powerful REXX command which can be used to split formatted strings in parts and assign the parts to variables. The syntax is PARSE VALUE <string> WITH <variable>"<delimiter>" … For example, if you have a string coordinate in the form <index>: <pos-x>/<pos-y> you can easily break it into parts via
PARSE VALUE coord WITH index": "posx"/"posy
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Issuing ZOC Commands | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ZOC commands are extensions to the REXX language which are implemented as procedures and functions (see ZOC-REXX Commands for a list).
ZOC commands that do not return a value (or if you are not interested in the
return value) are called with the procedure call syntax:
ZOC-commands that do return a value are called with the function call
syntax: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Issuing Windows or macOS Shell Commands | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Commands which are intended to be executed by the operating system (like
deleting or renaming files), must be addressed to the operating system
directly. This can either be done through REXX's ADDRESS CMD
command or through ZOC's ZocShell command.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Built-In Functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The functions below can be used in assignments or in other commands
that expect values, e.g. b= ABS(a) or
IF ABS(n)>10 THEN ….
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
FILE I/O | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Please also check the FILEIO sample in SCRIPT\RXSAMPLE\TUTORIAL directory.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters to REXX Scripts | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It is possible to pass a parameter to a REXX scripts from the ZOC command line (or ZOC user buttons), e.g. ZOC /RUN:script\test.zrx "/RUNARG:Hello, World"
The parameter can be accessed
via the ARG(1) function from within the REXX Script and if necessary be split
using the PARSE command (it is recommended to subsequently use the STRIP function
to remove leading and trailing blanks from the parameters).
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Equivalents to BASIC Commands | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
← Back to Programming ZOC (REXX/DDE)