周末做了一个小的练习,读取WINCC预先定义的用户,把名字填写在组合框里面。
假设组合框名字叫做Userlist,在画面打开事件写下面的vbs脚本
Sub OnOpen()
Dim fullusername,databasename,sqlconnstr,conn,sqlstr,objrs,usercount,userlist,i
fullusername=HMIRuntime.Tags("@DatasourceNameRT").Read
databasename=Mid(fullusername,1,Len(fullusername)-1)
sqlconnstr="provider=sqloledb;data source=.\wincc;initial catalog=" & databasename & ";integrated security=SSPI;"
Set conn=Createobject("adodb.connection")
conn.connectionstring=sqlconnstr
conn.cursorlocation=3
conn.open
sqlstr="select name from pw_user where grpid>0"
Set objrs=Createobject("adodb.recordset")
objrs.open sqlstr,conn,1,3
usercount=objrs.recordcount
Set userlist=ScreenItems("Userlist")
If usercount>0 Then
objrs.movefirst
userlist.NUMBERLINES=usercount
For i =1 To usercount
userlist.index=i
userlist.text=Trim(objrs.fields("name").value)
objrs.movenext
Next
End If
userlist.index=1
objrs.close
conn.close
Set conn=Nothing
Set objrs=Nothing
Set userlist=Nothing
End Sub
保存,运行画面,画面打开时,就会把已经定义的用户填入组合框里面。
标签:用户名,userlist,VBS,WINCC,objrs,fullusername,conn,usercount From: https://www.cnblogs.com/fishingsriver/p/18623312