items like button, circle, text field, label gauge, slider guage have property like color, border, style, fontcolor, apperance, visibility, enable or disable items. in vbscript these property also changed when particular event triggerd. in this article we have basic example to change some property like visibility, background color change, enable or disable, change background, border and font color. this property are easily changed with vbscript. vbscript is very simple language to learn and understand.
in this example we see how to back ground color change when button is pressed or when value of inputoutput field reached to maximum value. in this article we change back ground color of circle and input output field text color for a particular values. to do this add component circle and input output filed to screen. add a tag input1 in tag table so we read tag value in vbscript. add input1 tag for i/o field in tag property.
below is the example of This VBScript. compile this script and add this script to i/o field input finished event property. subroutine named VBFunction_1 designed to dynamically update the properties of graphical elements on an HMI screen based on the value of a tag named input1. Below is a detailed explanation of vbscript
input1
.iofieldvalue
:
in this vbscript disable button and i/o field when i/o field value is greater than 50. so first add two button, i/o field and declare input1 tag to i/o field. logic is very simple if i/o field value is greater than 50 then button1 and i/o field disable. if component is disable then we can't change state or input. for enabling button1 and i/o field add press second button.
above is example wincc vbscript to enable or disable screen items. add this subroutine to i/o field input finished event and button pressed event property. and also in button press event set a function to set value of input1 tag to 0. following are the explanation below vbscript example.
iofield
, button1
: These represent the controls on the screen that will be enabled or disabled.iofieldvalue
: This variable holds the value retrieved from the tag input1
.iofieldvalue = SmartTags("input1")
: This retrieves the value of the tag input1
from the system (e.g., a sensor reading or user input).Set iofield = HmiRuntime.Screens("Screen_1").ScreenItems("I/O field_1")
: This sets a reference to the I/O field on the screen.Set button1 = HmiRuntime.Screens("Screen_1").ScreenItems("Button_1")
: This sets a reference to Button_1 on the screen.iofieldvalue < 50
, both the I/O field and Button_1 are enabled. when enable button is pressed than input1 tag value set to zero than both items are enable. when enable button is pressed.iofieldvalue > 50
, both the I/O field and Button_1 are disabled.VBFunction_2
subroutine, having applied the logic to enable or disable the controls.in this example we change a text of text filed when i/o field value is changed. add i/o field and set input1 tag to i/o field. add a test field, than create a vbscript. add this vbscript to i/o field input finished event property.
above is the example of wincc vbscript to change text of items. when i/o field value changed than same value with predefined text set to text field.
textfield
: This variable will reference the text field control on the HMI screen.iofieldvalue
: This variable will store the value retrieved from the tag input1
.iofieldvalue = SmartTags("input1")
: This line fetches the value of the input1
tag using the SmartTags
function. This value can come from a sensor or another input source in the system.Set textfield = HmiRuntime.Screens("Screen_1").ScreenItems("Text field_1")
: This line sets a reference to the text field control on the screen (specifically on Screen_1
).textfield.Text = "Current Value of I/O Field is : " & iofieldvalue
: This line updates the text displayed in the text field by appending the value of input1
to the string "Current Value of I/O Field is : ". The result is a dynamic message displaying the current value of the input field.in this vbscript we understand how to change radius of an wincc hmi items using vbscript. so add a circle, and two button on button used for increment and second button is used for decrement. now create a two vb script first script increment radius of circle by 10 and second vbscript decrement circle radius by 10. after compile both script add these two script in button pressed event property.
now we have two script increment script and decrement script. when increment button is pressed then circle radius increment by 10 and if the decrement button is pressed than circle radius decrement by 10. you can also change height, width, border width border color etc.