PLC BLOG | wincc vbscript for access hmi screen items and tags

wincc vbscript for access hmi screen items and tags

vbscript is a visual basic script used in wincc flexible for hmi programming and configuration. vbscript access hmi screen items to write and read screen items value. vb script is very help full to design HMI screen. vbscript also read and write tag value by using smart tags keyword. in industrial control system vbscript help to make HMI more user friendly. vb script have many useful features like read and write tag value, read and write screen items value and screen items propertis.in this article we understand how to read and write tag value and read and write screen items property and value.

add screen item in screen using wincc tia

open wincc tia and than create project after creating project open your screen and then add items like button, text field, input output field, slider etc. each screen items have it's unique name. this unique name is used for accessing screen items in vb script. in this article we access screen items in vb script.
add screen item in screen using wincc tia

add tag in wincc

open tag table and add tag with proper data type in this article we have input1, input2 and input3 and each tag have integer (INT) data type.
add tag in wincc

how to read and write value of tags using vbscript in siemens wincc tia portal

tag is very important in industrial control. tag is name of variable to identify of application. each tag associated with a proper data type. Siemens HMI tags are accessible in vbscript. you can use "Smarttag" keyword to access HMI or plc tag. or press CTRL+J to access tag table in vbscript. each tag store value like temperature, area, depth etc. following are the example of wicc vbscript to access tag.
how to read and write value of tags using vbscript in siemens wincc tia portal
This example demonstrates how VBScript is used to assign values to tags using the SmartTags. input1, input2 and input3 are tags which are we inserted in hmi tag table, in this script we simple store values in tags. this vbscript is associated with button press events property. this subroutine vbscript executed when button pressed. following are code explanation
  • SmartTags: In this context, SmartTags is an object that is used to store values for different keys or tags. These tags act as identifiers for certain elements in the script, allowing you to reference and update them as needed.
  • Assignment: Each line of code is assigning a numerical value to a specific tag:
    • SmartTags("input1") = 12 assigns the value 12 to the tag named "input1".
    • SmartTags("input2") = 134 assigns the value 134 to the tag named "input2".
    • SmartTags("input3") = 156 assigns the value 156 to the tag named "input3".
  • Purpose: This script could be used in scenarios where you want to dynamically set values to specific tags or identifiers (e.g., form fields or variables) in an automation script or hmi script.

vbscript to access screen items in wincc tia portal

each screen items are associated with a screen name. screen items like text field, button, input output field etc have it's unique name. in vbscript screen name and screen items name are very important to access screen items. in vb script following items property changed.
  • change background color, font color, text color, border, radius etc.
  • set text or value of items
  • change position, hight, width etc. of your selected items
  • enable or disable screen items
  • change visibility of screen items
following are the procedure to access screen items in vb script
Dim items_var
Set items_var = HmiRuntime.Screens("Screen_name").ScreenItems("screen_item_name")
  • Dim items_var: This line declares a variable named items_var to hold the reference to the screen item.
  • Set items_var =: This line assigns an object reference (in this case, a screen item) to the variable items_var.
  • HmiRuntime.Screens("Screen_name"): This part accesses the screen named Screen_name in the HMI runtime environment. Screen_name should be replaced with the actual name of the screen you want to reference.
  • .ScreenItems("screen_item_name"): This accesses a specific screen item within the screen. Replace screen_item_name with the actual name of the item (like a button, text field, or other UI element).
vbscript to access screen items in wincc tia portal
above is the vbscript example of accessing screen items property in wincc. in this script we access text property of a text fild. when button is pressed than text field changed to "button is pressed", text field color changed to red and width of text filed is changed to 4. following are code explanation in simple form
  • Dim items_var: Declares a variable items_var to store a reference to a screen item.
  • Set items_var = HmiRuntime.Screens("Screen_1").ScreenItems("Text field_2"): This line accesses the screen item named Text field_2 on the screen called Screen_1 and assigns it to the items_var variable. In this case, Text field_2 could be a label, text box, or any other UI element on the screen.
  • items_var.Text = "button is pressed": This line changes the text displayed on the Text field_2 to the message "button is pressed". The Text property modifies the content of the screen item.
  • items_var.ForeColor = vbRed: This changes the text color of Text field_2 to red. The ForeColor property is used to set the color of the text. In this case, vbRed is a predefined constant in VBScript that represents the red color.
  • items_var.Width = 4: This changes the width of the Text field_2 screen item. The Width property controls the horizontal size of the item. Here, it's set to 4 (the unit of measurement depends on the environment, such as pixels or other units).

Simmilar

Siemens Data Blocks (DB)

Jul17, 2021 85

Siemens Math Instructions

Jun25, 2021 13

Siemens Bit Logic

May24, 2021 10