Sub Record_View
Dim strConnectionString
Dim objConnection
Dim objCommand
Dim strSQL
Dim Rs
Dim MSHFlexGrid
strConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SHUJUJILU;Data Source=COMPUTER3\WINCC"
strSQL = "select * from WeightValue"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString = strConnectionString
objConnection.Open
Set objCommand = CreateObject("ADODB.Command")
With objCommand
objCommand.ActiveConnection = objConnection
objCommand.CommandText = strSQL
End With
Set Rs=CreateObject("ADODB.Recordset")
Rs.Open objCommand, , 1, 3
Set MSHFlexGrid=HMIRuntime.Screens("MainPicture").ScreenItems("MSHFlexGrid")
Set MSHFlexGrid.DataSource = Rs
MSHFlexGrid.Refresh
Rs.Close
objConnection.Close
Set objCommand = Nothing
Set Rs=Nothing
Set objConnection = Nothing
Set MSHFlexGrid=Nothing
End Sub
(注:MSHFlexGrid控件是数据显示控件,放在了MainPicture画面中)
我的这段代码用变量触发或用定时器触发时MSHFlexGrid控件中都不能显示数据库中的数据,但用Mainpicture画面上的按钮然后通过单击事件调用上面的代码却能显示数据库中的数据在MSHFlexGrid控件中,我怎么也想不通啊,为什么事件触发不行而用按钮单击事件却可以呢?请高手给小弟看看,多谢了!
最佳答案
Set MSHFlexGrid=HMIRuntime.Screens("MainPicture").ScreenItems("MSHFlexGrid")可能会有问题,全局脚本可能找不到这样的控件,你试试把触发变量放到MainPicture画面中,当变量变化的时候看脚本是否执行?
提问者对于答案的评价:
这位朋友的回答让我非常感激,我按照您的方法做了,并顺利执行了代码,看来ActiveX控件在全局脚本中有时不能够被识别出来。谢谢您了,祝您身体健康,幸福快乐
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc267352.html