通过VBS脚本可以实现特殊的功能,增加画面的美感和操作性。 【1】读取当前时间,可以扩展检测到系统时间后,执行某个动作,此脚本也可以写在全局脚本中。 首先建立一个按钮: 按钮脚本如下: Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y) '脚本测试1:时间执行 Dim time1,time2,time3 time1=Hour(Time) ''''''''''''取当前的小时 time2=Minute(Time) ''''''''''''取当前的分钟数 time3=Second(Time)'''''''''''''''取当前的秒钟数 Msgbox "现在时间是:"&time1&":"&time2&":"&time3 End Sub 测试效果: 【2】变量取反,点击按钮,实现按钮取反。 Sub OnLButtonDown(ByVal Item, ByVal Flags, ByVal x, ByVal y) Dim tag1 Set tag1=hmiruntime.tags("tag1") tag1.read if tag1.value=1 then tag1.write 0 else tag1.write 1 end if set tag1=nothing End Sub 测试效果: 【3】点击按钮,增加一定的数据 '点一次加按钮tag1的值加0.2 Dim mytag mytag=hmiruntime.tags("tag2_REAL").read mytag=mytag+0.2 hmiruntime.tags("tag2_REAL").write mytag '点一次加按钮tag1的值减0.2 Dim mytag mytag=hmiruntime.tags("tag2_REAL").read mytag=mytag-0.2 hmiruntime.tags("tag2_REAL").write mytag 测试效果: 【4】改变画面中控件背景颜色 测试效果: 【5】二次确认,当按下按钮时,确认是否动作? 测试效果: 【6】其他可自行测试:{确认窗口脚本} Dim Msg,Stgle,Title,Kesponse Msg="是否切换?" Style=vbYesNo+vbQuestion+vbDefaultButton2 Title="窗口切换" Response=MsgBox(Msg,Style,Title) If Response=vbYes Then HMIRuntime.Tags("TAGS1").Write 1 End If |
|