In the actual programming project of wincc, it may be necessary to complete the self-increment or self-decrement of variables. Generally, this function can be completed by PLC, but how to complete it in wincc?
ready
Build variables
V1.0
Requirement: self-increment of variable address
screen
![Insert image description here](https://img-blog.csdnimg.cn/20200227154352310.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L70FFsize,OAFF,size
script
Dim mytag
mytag=HMIRuntime.Tags("Y").read
mytag=mytag+1
HMIRuntime.Tags("Y").write mytag
V2.0
demand:
通过条件判断,如果条件满足,则开始自增,如果条件不满足,则保持不变
screen:
Click the start button, the Value value will increase by 1 per second;
click the end button, the Value value will automatically become zero;
script
Dim meter1
Dim a
meter1 = HMIRuntime.Tags("meter1").Read
a = HMIRuntime.Tags("open").read
If a=1 Then
meter1=meter1+1
End If
HMIRuntime.Tags("meter1").Write meter1
The above script can be added to the action of wincc, and set the trigger to 1s. This time can be adjusted as needed;
after the action is set, remember to click the computer properties of the project tree, and in the startup, check the global script.