Complex text change with scripts

<< Click to Display Table of Contents >>

Navigation:  Examples > Change the text of an object >

Complex text change with scripts

Previous pageReturn to chapter overviewNext page

If you have to change text depending on several tags you need to use scripts. For example you have 2 tags for every object - State and Speed:

complexwithscriptstags

Depending on tag's values for every Text/EditField object use texts:

State

Speed

Text

0

Any

Pump is stopped

1

0...500

Pump speed is normal: PV

1

500...1000

Warning! Pump speed is high: PV

1

>1000

Dangerous!!! Pump speed is too high.

Let's create Text/EditField graphical object for our example:

textexcomplex

Let's open Object properties window by double clicking on it:

textopjectproperties

And let's create user-defined property - Number and make it's equal 1:

complexudp

Now we have to create Object type ST script with Execution type - OnDataChange:

stscriptforcomplexscript

Now close Collection window and Object properties by clicking OK to confirm our changes. And now we can write our script:

clip0002

Now we have Text with setup text by script. To copy this Text and bind text property to tags - State2, Speed2 and State3, State3 you no need to setup script for every Text you only have to duplicate Text:

textduplicate

And change Number property of the new Text in the Property sheet:

complexpropertysheet

Click OK to confirm your changes and Run simulation to check your settings:

textcomplexex