Entry type: FAQ, Entry ID: 24074628, Entry date: 02/13/2012

How can you display/hide a layer depending on a variable?

  • Entry
  • Associated product(s)

Depending on the status of a variable, a specific layer of a picture must be shown.

For this you can use the VBS script below, in which you only have to change the picture name, the layer, the variable and its value (for example, in a global VBS script or in a VBS action of an event of a button etc.).

This script functions only if the relevant screen is also open.

Dim Tag
Dim scrObj

Set scrObj = HMIRuntime.Screens("@Screen.@win12:@1001.@Desk:Picture name")
Set Tag = HMIRuntime.Tags("Variable")


If Tag.Value = 0 Then
    scrObj.Layers(Layer).Visible = False
    scrObj.Layers(layer).Visible = True
End If

Note (taken from the WinCC Online Help)
Upon access, the layers are counted in VBS starting with 1. Thus layer "0" in the WinCC Graphics Designer must be addressed with layers(1).

For example, if you want to address layer 10 in a screen,you must enter 11 for

If you have opened a screen on anther monitor, you must address it accordingly, "@Screen.@win22:@1001.@Desk:screenname", for example. More information about the addressing of different monitors is available in Entry ID: 831486.

Error details
Detailed error description
Help us to improve Online Support.
The page requested cannot be displayed. Please contact the webmaster.
Contact to webmaster