First Script

Now it is necessary to make the system add some constatnt (e.g. 3) to the temperatire value every second.
Script function:
- if the temperature value is less than the maximum temperature (e.g. 100) then add a constant to the Value property of the "Temperature" variable
- if the temperature value is higher than (or equals to) the maximum temperature (e.g. 100) then reset the Value property of the "Temperature" variable to minimum temperature value (e.g. 0)
- opakovat cyklus
Therefore it is necessary to execute the following steps regarding the onTick event:
1st step - creation of variables

In the onTick event, in the area of the right portion of Events page write the first line of script:

Dim oTemperature
By this script, you have just created a variable oTemperature, that will be represented by the "Temperature" object.
The variable name in the script mustn't imply spaces, diacritic and special characters. It is a good practice to have the first letter of the variable name in lower case that perceives type of the variable, e.g.
n = number
b = boolean
s = string (text)
o = object - oTemperature in our case, etc.
a = array with values, etc.
Notice that the variable has no defined data type. Each variable in the VBScript language is so-called Variant, meaning a variable holds inside not only the value but also the data type. After being created, the variable is empty (Empty data type). Only after the value is assigned (this process will be described in a while) the variable finds out what is being assigned to it and then sets its data type accordingly.
2nd step - "Temperature" object Assignment

Now write the second line of the script:

Set oTemperature = pMe.Pm("../Data/#vars/Temperature")
A value is assigned to the oTemperature variable that is now of the Object type. Only if an object is being assigned the VBScript language requires to use the Set statement before the assigned variable.
Each event of any PROMOTIC system object has a pMe parameter (variable). This parametr is of the PmObject data type and is set by the PROMOTIC system to be a reference to the object where the corresponding event occured. Regarding the onTick event in the "Emul" object the pMe parameter points to the "Emul" object. Each object has the Pm method. This method has a single parameter that is a text (String) representing the path in the application object tree to the desired PROMOTIC object (the tect is inside quotation marks making the VBScript aware that it is a String type value). Two types of addressing can be used in the PROMOTIC system:
- absolute addresssing – starts always from the PmRoot object, syntax starts with slash.
- relative addressing - starts always from the object where the Pm method is called.
The main disadvantage of the absolute addressing is the fact that once the application tree structure is modified the absolute object references may become invalid. For example, you can copy the "Boiler1" object in order to create a new object "Boiler2" (do not do this in your application now). There would be exactly the same objects present in the "Boiler2" as in "Boiler1" (including the corresponding settings). If the absolute addressing would have been used, the script in "Boiler2" would work with values from "Boiler1". Usage of relative addressing would avoid this problem.
Note: Instead of writing the scripts manualy, you can use the script wizard that can make script writing a lot easier. The script wizard can be activated by clicking the right mouse button on the script editing area. In the displayed local menu select "Script wizard ..." and then "PROMOTIC object (Set)" in order to create an object reference. In the displayed window use the "Variable" configurator to enter the variable name that is to be linked with object reference(oTemperature). In the "Value" configurator, use the button with three full stops to select the desired object (Temperature variable in the PmData object) and check the "Relative path" checkbox. The wizard can also help you create a new variable, but we are not going to use this function now - the variable has been created in previous steps.
3rd step – check and set value of Temperature object

Write this script on the following line:

If oTemperature.Value >= 100 Then
   oTemperature.Value = 0
   oTemperature.Value = oTemperature.Value + 3
This part of the script uses the statement If If...Then...Else. This statement allows to define a group of statements to be executed if some condition is met (temperature value is greater than 100°C) and other group of statements if the condition is not met (temperature value is less than 100°C).
The approach to the object property that was theoretically explained formerly, is used here practically for the first time – the way for setting the object property when Object.PropertyName is written. There is both reading and writing the value from/to the Value property here. The "Temperature" object (of Var type) holds more properties (e.g. property Note, Bit, etc.), but the most important property is that of Value. This property returns the value of the temperature (of Single data type – thus you've set it in the "Temperature" object).
You've finished your first script in the PROMOTIC system. You should have the following text on the right part of the page in the "Temperature" object in the Events page while selected the onTick event:
Dim oTemperature
Set oTemperature = pMe.Pm("../Data/#vars/Temperature")
If oTemperature.Value >= 100 Then
   oTemperature.Value = 0
   oTemperature.Value = oTemperature.Value + 3
Now you can start the application.
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice