No announcement yet.

How To use VBScript to customize the data displayed in an HSTouch element

This is a sticky topic.
  • Filter
  • Time
  • Show
Clear All
new posts

  • How To use VBScript to customize the data displayed in an HSTouch element

    This HowTo requires HSTouch designer and client version or later.

    There may be times when you want to customize the display of data in an HSTouch element. For example, you have the temperature from a thermostat in fahrenheit and want to display it as celsius. In the text property of an elelment you can use VBscript to do calculations. The format of the text would be:


    The formula we need to use to convert F to C is:

    Tc = (5/9)*(Tf-32)

    In this case, we will retrieve the temperature of the thermostat using one text element, then reference this element in a second element and then convert it. We need to do this since there is no way to add an association to a thermostat in a script statement. The element that holds the fahrenheit temp can be hidden. You can put this element on a screen that will never be displayed. The attached XML project file shows a sample screen.

    Here is the procedure:

    1: On one screen add a text element and associate it with the thermostats current temperature.

    2: On the screen where you want to display the temperature as celsius add a text element and enter the following for the text property. Note that you need 2 pieces of information: the name of the screen where the source temp is located as well as the name of the element that holds the temp. This is the element referenced from step 1. In the sample, the source element is named "ctemp" and the screen it is on is named "main".


    The $ELEMENT replacement variable simply grabs the text that is displayed on the screen named "main" in the element "ctemp", which is the temp in fahrenheit. We use the VBScript function "round" to round the value that is calculated. If we did use this, the temp would have many decimal places like 22.444444444444. The round function rounds the result to 1 decimal place so a temp of 78 is converted to 22.8.
    Attached Files
    website | buy now | support | youtube