技术论坛

 回复:作为对论坛得回报,贴上段代码,望大家不要见笑!!!

返回主题列表
作者 主题
ucosii
游士

经验值:177
发帖数:209
精华帖:1
楼主    2006-07-23 22:17:29
主题:作为对论坛得回报,贴上段代码,望大家不要见笑!!!
由于我的系统无法实现多变量归档查询,我只能使用单变量归档查询到数据后一次性放到listview控件中,在完成这个模块期间很感谢城外之人的帮助,作为对论坛的回报,我把这段代码贴出来,希望可以对有我同样困惑的同志起到帮助。
狭路相逢勇者胜
ucosii
游士

经验值:177
发帖数:209
精华帖:1
    2006-07-23 22:20:15
精华帖  主题:回复:作为对论坛得回报,贴上段代码,望大家不要见笑!!!
如下
Dim cn , SqlCon, search_sql ,citems,row,listview,rscount,rCom(768)
Dim rs1,rs2,rs3
Dim search_sql1,search_sql2,search_sql3
Dim flag
Dim tagvalue,lbox1,lbox2
Set lbox1=ScreenItems("listbox1")
Set lbox2=ScreenItems("listbox2")
Dim pbar
Set pbar=ScreenItems("pbar")

Dim wendu,weishui,yali
wendu="\wendu"
weishui="\weishui"
yali="\yali"

Set cn=CreateObject("adodb.connection")
'Set rs=CreateObject("adodb.recordset")
Dim starData,starTime, endData,endTime
Dim dp1,dp2,dp3,dp4
Dim dpvalue1,dpvalue2,dpvalue3,dpvalue4
Set dp1=ScreenItems("dtpicker1")
dpvalue1=Left(dp1.Value,9)
Set dp2=ScreenItems("dtpicker2")
dpvalue2=Right(dp2.Value,8)
Set dp3=ScreenItems("dtpicker3")
dpvalue3=Left(dp3.Value ,9)
Set dp4=ScreenItems("dtpicker4")
dpvalue4=Right(dp4.Value,8)

Dim startdt,enddt
startdt=dpvalue1&" "&dpvalue2' qi shi shi jian jian zi fu chuan
enddt=dpvalue3&" "&dpvalue4 'jie shu shi jian zi fu chuan
'MsgBox "the startdata is : "&dpvalue1
'MsgBox "the enddata is:"&dpvalue3

SqlCon="Provider=WinCCOLEDBProvider;Catalog=CC_winccsingle-proj_06_07_23_09_19_11R;Data Source=.\WinCC"

cn.connectionstring=SqlCon
cn.Cursorlocation=3
cn.open


Set listview = ScreenItems("ListView1")
' xiang listview jia biao tou
Dim u
For u=1 To lbox2.listcount-1
If u=1 Then

With listview
.columnheaders.add,,"Date",90
End With
End If
With listview
.ColumnHeaders.add,,lbox2.list(u)&wendu,110
.ColumnHeaders.add,,lbox2.list(u)&weishui,110
.ColumnHeaders.add,,lbox2.list(u)&yali,110
End With
Next

Dim i,str,value
Dim rs(768),tag(768),query(768)

Dim count
Dim p
p=1
' kai shi jin ru xuan huan du qu shu ju ku
pbar.max=lbox2.listcount*3-3
For i=1 To lbox2.listcount-1

' du qu listbox de lie biao xiang
str=Right(lbox2.list(i),3)
If Left(str,1)="c" Then
value=Right(lbox2.list(i),1)
Else If Left(str,1)="e" Then
value=Right (lbox2.list(i),2)
Else
value=Right (lbox2.list(i),3)
End If
End If
'sheng cheng shu ju ji he
tag(p)="'Node"&value&"\Node"&value&"_temperature'"
tag(p+1)="'Node"&value&"\Node"&value&"_moisture'"

tag(p+2)="'Node"&value&"\Node"&value&"_pressure'"
query(p)="TAG:R,"&tag(p)&","&startdt&","&enddt&""
query(p+1)="TAG:R,"&tag(p+1)&","&startdt&","&enddt&""
query(p+2)="TAG:R,"&tag(p+2)&","&startdt&","&enddt&""
Set rCom(p)=CreateObject("ADODB.Command")
rCom(p).CommandType=1
Set rCom(p).ActiveConnection=cn

rCom(p).CommandText=query(p)
Set rs(p)=rCom(p).execute
'MsgBox "the recordcount is "&rs(p).recordcount
pbar.value=p
Set rCom(p+1)=CreateObject("ADODB.Command")
rCom(p+1).CommandType=1
Set rCom(p+1).ActiveConnection=cn

rCom(p+1).CommandText=query(p+1)
Set rs(p+1)=rCom(p+1).execute
pbar.Value=p+1


Set rCom(p+2)=CreateObject("ADODB.Command")
rCom(p+2).CommandType=1
Set rCom(p+2).ActiveConnection=cn
'rCom(p)="rCom"&p
rCom(p+2).CommandText=query(p+2)
Set rs(p+2)=rCom(p+2).execute
pbar.Value=p+2
count=count+1
p=p+3
Next
'MsgBox "the p is "&P
Dim ecount,t
ecount=lbox2.listcount*3' zan shi mei you shen m yong

MsgBox "Ready to fillful the the listview"
pbar.Value=0
MsgBox "the recordcount is "&rs(1).recordcount
If rs(1).recordcount=0 Then
MsgBox "no data find!!!!"
Else
pbar.Max=rs(1).recordcount
'MsgBox "the pbar.max is "&pbar.Max
End If
Dim xx 'gei progress bar yong kong zhi jing du tiao jing du
Do While Not rs(1).eof

Set citems=listview.listitems.add()
citems.Text=CStr(rs(1).fields(1).value)
pbar.Value=xx

For t=1 To 12' yi gong cai zu tai le 4 ge xia wei bianl iiang

citems.subitems(t)=CStr(rs(t).fields(2).value)


rs(t).movenext

next
xx=xx+1
Loop

'MsgBox "the xx is "&xx
xx=HMIRuntime.Tags("listview_count").Read
'MsgBox "the listview's row is "&listview.rows

Dim close
Set cn=Nothing
For close=1 To 256
Set rs(close)=Nothing
next

狭路相逢勇者胜
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。