Variables and Environment-Variables using the MPR

Moderator: MVogt

Antworten
Benutzeravatar
Theo_Gottwald
Beiträge: 309
Registriert: 03. Okt 2009, 08:57
Wohnort: Herrenstr.11 * 76706 Dettenheim
Kontaktdaten:

Variables and Environment-Variables using the MPR

Beitrag von Theo_Gottwald » 31. Jan 2019, 09:29

VARIABLES are an universal concept that is also implemented in the MPR.

1. What are variables good for?
Variables - are sort placeholders, thery work in the same way as the well known environment variables known from Empirum or DOS.
Writing the name of such a variable in a script is like the name of a "box with content".
At runtime of the script, the name of the box is replaced by the content that is assigned to this box.

2. Variables with the MPR
For example, while an environment variable may be called "VM_SERIAL," variables in the Package Robot are always built as follows:

Code: Alles auswählen

$$ABC
We use twice the "$" and then three letters (or numbers). Upper and lower case are not distinguished.
The variables: $$ABC and $$abc are thus the same variable. As well $$123 or $$A11 would be valid variable names.

How do you assign such a variable to a value, for example a serial number?
Its easy:

Code: Alles auswählen

VAR\$$ABC=1234-56768-0987
You can now use the variable anywhere in the script, where else the assigned text would be used.
The MPR will then insert the serial number at that place.

For example:

Code: Alles auswählen

RST\$$ABC
If you want to control the content of a variable, you can display a message box:

Code: Alles auswählen

MBX\The Content is:$$ABC
or something more clean, with a linefeed:

Code: Alles auswählen

MBX\The Content is:$crlf$$$ABC
3. Environment Variables
Now we know how to use the MPR variables.
But how do the Environment Variables come into play?

For this we have several MPR-commands:
"EVG\[Daten]" für "EnvironmentVariableGet",
"EVS\" für "EnvironmentVariableSet",
"IEE\[Daten]" für "IfExistsEnvironmentvariable",
and "EEE\" für "EndExistsEnvironmentvariable",
"ESE\[Daten]" für "EnvironmentStringExpand",
"ESG\" für "EnvironmentStringGet",
"ESS\" für "EnvironmentStringSet".
But to simply transfer the value of an environment variable to an MPR variable, we only need the EVG\ command.

Let's assume that our environment variable is "VM_SERIAL" (thanks for the tip, Hendrik!) And we want to transfer the value to the MPR variable "$$VMS" for later use in the script. We do like this:

Code: Alles auswählen

EVG\VM_SERIAL
VAR\$$VMS=$v1$


Now we can use the $$VMS in the script everywhere instead of text - or together with text.

For example with:

Code: Alles auswählen

SBT\10|The Serial Code is: $$VMS
We can also mix text with variables. Unlike VB-Script we do not need any "" chaining characters (&, +). The reason for this is the fixed length of the MPR variables . As a result, the robot knows exactly where a variable starts and where it ends.

And how do we pass a return code back to Empirum?
Like this:

Code: Alles auswählen

SRV\[Number or Variable]
So for example:

Code: Alles auswählen

SRV\1
would trigger the errorlevel 1.

Using all these Variables, Scirpts can easily be modified at a later time. And in result we have all the possibilities in our script.

Antworten

Zurück zu „Package Robot“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast