![]() |
![]() |
![]() |
![]() |
Section Contents
There are 3 stages to producing a program using OPL, the Psion programming language:
This chapter guides you through these stages with a simple example. If you wish to follow the example, note that each instruction for you to do something is numbered.
![]() |
The example programs in the first few chapters do not include full error handling. This keeps the programs short and easy to understand, but it means that when you run one of these programs and, for example, fail to type in the kind of value which the program asks for, the program may fail harmlessly stopping before it completed. As you develop your own programs, you should usually add some error handling code to them. A later chapter gives a full explanation of error handling. |
As well as the word program, youll often see the word module used. The terms program and module are used almost interchangeably to describe each OPL file - you say "OPL module" like you might say "Word Processor document".
Create a new module and give it a name:
![]() |
Click the New File button (or select Create New File from the File menu). |
|
![]() |
Move to the Program icon on the System screen, and select New file from the File menu. |
Its always best to choose a name that describes what the module does. Then, when youve written several modules, you can still recognise which is which.
When you first move into the Program editor you will see that PROC : has already been entered on the first line, and ENDP on the third.
PROC and ENDP are the keywords that are used to mark the start and end of a procedure. Larger modules are broken up into procedures, each of which has one specific function to perform. A simple OPL module, like the one you are going to create, consists of only one procedure.
A procedure consists of a number of statements instructions upon which the Psion acts. You type these statements, in order, between PROC : and ENDP. When you come to run the program, the Psion goes through the statements one by one. When the last statement in the procedure has been completed and ENDP is reached, the procedure ends.
You can type and edit in the Program editor in much the same way as in the Word application, except that text you type does not word-wrap; you should press Enter at the end of each statement. Note also that on the Series 3c, the Program editor does not offer text layout features such as styles and emphases.
![]() |
You can use upper or lower case letters when entering OPL keywords. |
Section Contents
The next few pages work with this example procedure:
PROC test: PRINT "This is my OPL program" PAUSE 80 CLS PRINT "Press a key to finish" GET ENDP
This procedure does nothing of any real use it is just an example of how some common OPL keywords (PRINT, PAUSE, CLS and GET) are used. The procedure first displays This is my OPL program on the screen. After a few seconds the screen is cleared and then Press a key to finish is displayed. Then, when you press a key, the program finishes.
Before you type the statements that constitute the procedure, you must type a name for it, after the word PROC. The flashing cursor is automatically in the correct place for you to do this (before the colon). You can choose any name you like within the following restrictions:
![]() |
Procedure names may have up to 32 characters. The alphabetic and numeric characters are allowed and also the underscore character, _. The first character of any procedure name must be either an underscore or an alphabetic character. |
![]() |
Procedure names may have up to 8 characters. The alphabetic and numeric characters are allowed only. The first character of any procedure name must be an alphabetic character. |
For simple procedures which are the only procedure in a module, you might use the same filename you gave the module.
Each new line is automatically indented, so you dont need to press the Tab key each time. These indents are not obligatory, though as youll see, they can make a procedure easier to read. However, other spacing, such as the space between PAUSE and 80, is essential for the procedure to work properly.
Type the other statements in the procedure. Press Enter at the end of each line. You are now ready to translate the module and then run it.
When you are entering the statements in a procedure you can, if you want, combine adjacent lines by separating them with a space and colon. For example, the two lines:
PAUSE 80 CLS
could be combined as this one line:
PAUSE 80 :CLS
You can, of course, use the other Psion applications at any time while you are editing an OPL module.
![]() |
To return to editing your program, either |
tap on the Program icon on the Extras bar, or
select the modules name on the System screen, or
use the Task List to return to the Program editor.
![]() |
Use Control-Word (hold down the Control key and press the Word button) to return to the Program editor to continue editing your program. |
PRINT - takes text you enter between quote marks, and displays it on the screen. The text to be displayed, in the first statement, is This is my OPL program.
PAUSE - pauses the program, for a specified number of twentieths of a second. PAUSE 80 waits for 4 seconds. (PAUSE 20 would wait for 1 second, and so on.)
CLS - clears the screen.
GET - waits for you to press a key on the keyboard.
Section Contents
The translation process makes a separate version of your program in a format which the Psion can run.
Youd usually try to translate a module as soon as you finish typing it in, to check for any typing mistakes youve made, and then to see if the program runs as you intended.
![]() |
Select the Translate option from the Tools menu or tap the Tran button on the toolbar menu. |
![]() |
Select the Translate option from the Prog menu. |
First: the procedures in the module are checked for errors
If the Psion cannot understand a procedure, because of a typing error, a message is shown, such as Syntax error. The cursor is positioned at the point where the error was detected, so that you can correct it. For example, you might have typed PRONT "This is...", or PAUSE80 without the space.
When you think youve corrected the mistake, select Translate again. If there is still a mistake, you are again taken back to where it was detected.
![]() |
If youve already used up almost all of the memory, the Psion may be unable to translate the program, and will report a No system memory message. Youll need to free some memory before trying again. |
When Translate can find no more errors, the translation will succeed, producing a separate version of your module in a format which the Psion can run.
There may still be errors in your program at this point because there are some errors which cannot be detected until you try to run the program.
When your module translates successfully, the Run program dialog is displayed, asking whether to run the translated module. Youd usually run it straight away in order to test it.
![]() |
Running a module does require some free memory, so again a No system memory message is possible. |
Press Y to run the module; the screen is cleared, and the module runs.
When the module has finished running, you return to the Program editor, with the cursor where it was before.
If an error occurs while the module is running, you will return to editing the module, and the cursor will be positioned at the point where the error occurred.
Section Contents
You can create new OPL modules in the same way as new Word documents.
![]() |
Either create it from the Program editor using the Create New file option in File menu, or from the System screen by clicking on the New File button (or select Create New File from the File menu). |
![]() |
Either create it from the Program editor using the New file option in File menu, or from the System screen by moving to the Program icon and using its New File option. |
Use the Copy file option in the System screen to copy modules (or translated modules). See the User Guide for full details. You can also use the Save as option in the Program editor itself, to make new copies of an OPL module.
You can delete an OPL module (or a translated version) as you would any other file. Go to the System screen, move the highlight on to the file and use the Delete file option.
![]() |
If you delete all of your translated modules, the RunOpl icon will remain on the System screen, with the word RunOpl beneath it. |
If you see a File is in use (File or device in use on the Series 3c) error message when deleting or copying an OPL module, the file is open it is currently being edited in the Program editor. Exit the file and then try again.
If its the translated file youre trying to delete or copy, File is in use (File or device in use on the Series 3c) means that the translated file is currently running. Stop the running program by going to the running program, then either wait for the program to complete or press Ctrl+Esc (on the Series 5; Psion+Esc on the Series 3c) to stop it, and then you can try again.
Section Contents
You can run a module at any time from within the Program editor, by selecting Run program (Run on the Series 3c) from the Tools menu (Prog menu on the Series 3c). This runs the translated version of your program; if youve made changes to the module and havent translated it again, you must translate the module again, or the changes have no effect.
Run program (Run on the Series 3c) displays a dialog, letting you select the name of any translated module which you want to run.
The names of any successfully translated programs automatically appear in the System screen.
![]() |
Translated modules appear in the System screen with the OPL icon to the left of them. They have the same name as the Program file from which they were translated with the extension .OPO added to their name, and appear in the same folder as their corresponding Program file. Just move the highlight on to the name of the translated program you want to run, and select it. |
![]() |
Translated modules appear underneath the RunOpl icon. This appears at the right-hand end of the list of icons (past the Program icon), and is usually off the right-hand edge of the screen. Just move the highlight on to the name of the translated program you want to run, and press Enter. |
When an OPL module has been successfully translated and run, you will usually run it from the System screen. While youre still editing and testing, however, its quicker to run it from inside the Program editor. This also positions the cursor for you, if errors occur.
![]() |
To stop a running program, press Ctrl+Esc. (If youve gone away from the running program it will still be running, and you must first return to it. This is done by either selecting it from the System screen or by using the Task list to switch to it. Then Ctrl+Esc will stop it.) |
![]() |
|
![]() |
The Series 5 does not have status windows: it has a toolbar instead. You should see the Friendlier Interaction chapter for details of this. |
![]() |
A temporary status window is always available while an OPL program is running. Press Psion-Menu to see it. As youll see, there are keywords for displaying a status window yourself. |
![]() |
If you translate and run a module from the Program editor, the Task list will still allow you to return to the Program editor, even if the translated program has not finished running. A Running85 message is shown you can move the cursor around the program as normal, but you cant edit it. |
![]() |
If you translate and run a module from the Program editor, the Control-Word keypress will still return to the Program editor, even if the translated program has not finished running. A Busy message is shown you can move the cursor around the program as normal, but you cant edit it. |
If a module is running, and you select a second one from the System screen, the first one is not replaced both modules run together, and will be displayed in bold on the System screen. On the Series 5, you can swap between them using the Task list, on the Series 3c use Control-Shift-Calc.
While youre typing in the procedure, all the options on the Edit menu such as Copy (Copy text on the Series 3c) and Paste (Insert text on the Series 3c) - are available and can be used as in Word. Refer to the User Guide for more information.
![]() |
The menu options available are in general similar to those found in other applications, such as Word. The Tools menu has options for translating and running the current program. It also has a Show last error option, to re-display an error which prevented successful translation, and a Preferences option to determine the fonts available and whether spaces, tabs and paragraph ends are shown in the Program editor. It also provides an Infrared option (see the User Guide for more details of using infrared). The Create standard files option creates files in RAM from ROM files: see the Calling Procedures chapter for more details of this. |
|
|
|
![]() |
The menus available are the same as in the Word application, except that the Word menu has been replaced by the Prog menu. The Prog menu has options for translating and running the current program. It also has a Show error option, to re-display an error which prevented successful translation, and an Indentation option, for setting the tab width and to turn auto-indentation on and off in the Program editor. |
The key allows you to switch between a Normal and an Outline view of your OPL module. The Outline view lists only the names of each procedure, for quick navigation around the module.
![]() |
Tap the New file button on the system screen and select Program as the Program. |
![]() |
Move to the Program icon in the System screen and select the New file option. |
![]() |
![]() |
![]() |
![]() |