Dim sPro As String
Dim sDsn As String
Dim sSer As String
Dim sCon As String
Dim sSql As String
Dim conn As Object
Dim oRs As Object
Dim oCom As Object
Dim oItem As ListItem
Dim m,n,s
sPro="Provider=WinCCOLEDBProvider.1;"
sDsn="Catalog=CC_DemoV6_08_05_19_10_18_29R;"
sSer="Data Source=.\WinCC"
sCon=sPro+sDsn+sSer
sSql="TAG:R,''PVArchive\Tag1'',''0000-00-00 00:10:00.000'',''0000-00-00 00:00:00.000''"
sSql="TAG:R,1,''0000-00-00 00:10:00.000'',''0000-00-00 00:00:00.000''"
MsgBox"Open with:"&vbCr&sCon&vbCr&sSql&vbCr
Set conn=CreateObject("ADODB.Connection")
conn.ConnectionString=sCon
conn.CursorLocation=3
conn.Open
Set oRs=CreateObject("ADODB.Recordset")
Set oCom=CreateObject("ADODB.Command")
oCom.CommandType=1
Set oCom.ActiveConnection=conn
oCom.CommandText=sSql
Set oRs=oCom.Execute
m=oRs.Fields.Count
ListView1.ColumHeaders.Clear
ListView1.ColumHeaders.Add,,CStr(oRs.Fields(1).name),140
ListView1.ColumHeaders.Add,,CStr(oRs.Fields(2).name),70
ListView1.ColumHeaders.Add,,CStr(oRs.Fields(3).name),70
If(m>0) Then
oRs.MoveFirst
n=0
Do While Not oRs.EOF
n=n+1
s=Left(CStr(oRs.Fields(1).Value).23)
Set oItem=ListView1.ListItems.Add()
oItem.Text=Left(CStr(oRs.Fields(1).Value).23)
oItem.SubItems(1)=FormatNumber(oRs.Fields(2).Value,4)
oItem.SubItems(2)=Hex(oRs.Fields(3).Value)
If(n>1000) Then Exit Do
oRs.MoveNext
Loop
oRs.Close
Else
End If
Set oRs=Nothing
conn.Close
Set conn=Nothing
深入浅出的一段OLE-DB读取过程值的例子,前面定义语句为何编译时出现:“语句未结束啊”?
最佳答案
VBS不需要定义变量的数据类型,前几句改成
Dim sPro
Dim sDsn
Dim sSer
Dim sCon
Dim sSql
Dim conn
Dim oRs
Dim oCom
Dim oItem
Dim m,n,s
s=Left(CStr(oRs.Fields(1).Value).23)
oItem.Text=Left(CStr(oRs.Fields(1).Value).23)
这两句有问题
提问者对于答案的评价:
原创文章,作者:more0621,如若转载,请注明出处:https://www.zhaoplc.com/plc276840.html