WinCC的VBS虽可以声明Public变量,但作用域仅限于本画面,如下:
如果WinCC版本>=V6.0 SP3,则可以使用Dataset对象,该对象可以在不同的VBS脚本中进行访问,下面是个简单的例子:
1、连接
Dim objConnection,strConnectionString
strConnectionString ="Driver={SQL Server};Server=.\WINCC;uid=;pass=;database=guowincc"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.open
HMIRuntime.DataSet.Add "objConnection",objConnection
2、全局动作中引用
Dim objConnection
objConnection= HMIRuntime.DataSet("objConnection").Value
with objCommand
.ActiveConnection = objConnection
xxxxxxxx
3、关闭连接:
Dim objConnection
objConnection= HMIRuntime.DataSet("objConnection").Value
objConnection.Close
Set objConnection = Nothing