Klik op het logo voor hulp op afstand
  
 
 
 
 
 
 
 




Language structures


Like other languages, JoPPS-Script includes the ability of conditional execution by means of the IF-THEN-ELSE statement: 

Example:

/* start word */
word := START("word.application");

/* word up and running? */
IF IsIDispatch(word) THEN
{
 /* Yes it is */
 word.Visible := TRUE;
 doc := word.Documents.Add();
 selection := word.ActiveDocument.ActiveWindow.Selection;
 selection.TypeText("Hello from JoPPS-Script");
}
ELSE
{
 /* Oops, it is not */
 Beep();
 Fatal("Sorry, I was unable to start WORD");
};
 
The general syntax for the IF-THEN-ELSE statement looks like this:
 
IF <expr> THEN
 statement block 1
[ ELSE
 statement block 2   (optional)
]
 
Statement block 1 is executed when the IF-expression evaluates TRUE, otherwise (when the IF-expression evaluates FALSE) optional statement block 2 is executed.
 

Iteration : WHILE - DO - BREAK - CONTINUE

Iterations can be programmed using a WHILE - DO statement.

Example:

/* count till 10 */
i := 0;

WHILE (i:=i+1) <= 10 DO OutputMsg("i is "+IntToStr(i));
       
The syntax for the WHILE-DO statement looks like this:
 
...
WHILE <expr> DO
 statement block 1
...
 
Statement block 1 is executed as long as <expr> evaluates TRUE, otherwise execution continuous at the first statement following the statement block.
 
When a statement block consists of more then one statement the entire block must be enclosed between braces ({...}).
 
BREAK
 
BREAK causes the flow of control to exit the current WHILE statement. This will cause script execution to continue at the first statement following statement block 1.
 
We could rewrite our previous example using BREAK :
 
/* count till 10 */
i := 1;
WHILE TRUE DO
{
 OutputMsg("i is "+IntToStr(i));
 IF i = 10 THEN BREAK;
 i := i + 1;
};
 
        
CONTINUE
 
CONTINUE allows the flow of control to proceed to the next iteration of the WHILE statement.

Example rewritten with CONTINUE:

/* count till 10 */
i := 1;

WHILE TRUE DO
{
 OutputMsg("i is "+IntToStr(i));
 i := i + 1;
 IF i <= 10 THEN CONTINUE;
 BREAK;
};
 
Infinitive loops can lockup your computer - be carefull.
Note : JoPPS-Script has no other iteration statements such as a FOR loop or a REPEAT-UNTIL.
 

Jumping: Labels and GOTO 

The GOTO statement can be used to continue the script execution at a specific location somewhere else in the same script: make a jump. The location we can jump to are marked with labels.  A goto statement is followed by a label identifier defining the location where to jump to..

Example:

errmsg := "";       /* no error */
word := START("word.application");

IF !IsIDispatch(word) THEN
{
 errmsg := "Sorry, I was unable to start WORD";
 GOTO error;       /* make jump to errorhandler */
};
word.Visible := TRUE;
doc := word.Documents.Add();
selection := word.ActiveDocument.ActiveWindow.Selection;
selection.TypeText("Hello from JoPPS-Script");
 
@error:            
IF errmsg <> "" THEN /* error? */
{
 Beep();
 Fatal(errmsg); /* script execution stops here */
};
OutputMsg("Program terminated");
 
 
The syntax for the GOTO statement looks like this:
                  
..
...
GOTO <labelname 2>
...
..
@<labelname 1>:
...
..
@<labelname 2>:
..
...
GOTO <labelname 1>
...
..
 
Label identifiers follow the same naming rules as variable identifiers. A label definition consists of a label identifier between a "@" and a ":" character. The "@" character tells the interpreter it has to deal with a label definition
instead of a regular statement.
 
Stopping script execution : Halt - Fatal
 
You can terminate a script being executed by calling Halt, execution will stop immediately without raising an error.

word := START("word.application");
IF !IsIDispatch(word) THEN
{

MsgErr("WORD did not start !");
Halt;

};

On the other hand you can abort a script and raise an error by calling Fatal. Execution will stop immediately as with Halt but an error is triggered. You can pass an error message to inform the end-user about the kind of error occurred. 
 
word := START("word.application");
IF !IsIDispatch(word) THEN Fatal("WORD did not start !");

 


 




 |  History  |
 
 

 
 
 
TECHWIN SOFTWARE
De Regenboog 11
B-2800 Mechelen
T +32(0)15 44 64 64
T +31(0)30 899 32 15 Nederland