Dim colGraph As New Collection
.........
colGraph.Add Adodc1.Recordset.Fields("流量")希望将数据库中的“时间”字段和“流量”字段循环写入到colGraph集合中,应该如何写代码?
.........
colGraph.Add Adodc1.Recordset.Fields("流量")希望将数据库中的“时间”字段和“流量”字段循环写入到colGraph集合中,应该如何写代码?
时间
流量Dim colGraph As Collection
dim a as aaa
set colGraph = new Collection
set a = new aaa
a。时间 = Adodc1.Recordset.Fields("时间")
a。流量 = Adodc1.Recordset.Fields("流量") colGraph。add a或简单的
colGraph.Add Adodc1.Recordset.Fields("时间") & "|" & Adodc1.Recordset.Fields("流量")
要用时再分开,"|" 调你喜欢的用
for i=0 to Adodc1.Recordset.recordcount-1
colGraph.Add Adodc1.Recordset.Fields("时间")
Adodc1.Recordset.movenext
nextAdodc1.Recordset.movefirst
for i=0 to Adodc1.Recordset.recordcount-1
colGraph.Add Adodc1.Recordset.Fields("流量")
Adodc1.Recordset.movenext
next
Private Sub GraphTest()
Dim i As Integer
Dim colGraph As New Collection
Do
Randomize
colGraph.Add Int(Rnd * 1000)
Call myGraph.DrawGraph(colGraph)
tmrWait.Enabled = True
Do While tmrWait.Enabled = True
DoEvents
Loop
Loop
End Sub
我改后的程序如下:Private Sub GraphTest()
Dim i As Integer
Dim colGraph As New Collection
Dim a As aaa
Set a = New aaa
Adodc1.ConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\tiph.mdb;Persist Security Info=False"
Adodc1.RecordSource = "Select * From 钛平衡计算 order by 日期"
Adodc1.CommandType = adCmdText
Adodc1.Refresh
a.日期 = Adodc1.Recordset.Fields("日期")
a.钛负荷 = Adodc1.Recordset("收支平衡量")
Do
colGraph.Add a
Call myGraph.DrawGraph(colGraph)
tmrWait.Enabled = True
Do While tmrWait.Enabled = True
DoEvents
Loop
Loop
End Sub出现“用户定义类型未定义”错误。附上DrawGraph函数源码:
Public Function DrawGraph(ByVal colGraphValues As Collection)
Dim i As Long
Dim IntX(1) As Integer
Dim IntY(1) As Integer
Dim intYScale As Integer
' 正确则继续
On Local Error Resume Next
With Graph
' 清除
.Cls
' 计算比例
intYScale = .ScaleHeight / MaxScaleValue
' Keep the collection inside the bounarys of our graph
Do While colGraphValues.Count > Int(.Width / 100 / 2) 'ADDED /2
' 删除过去记录
colGraphValues.Remove 1
Loop
' Set x-cord
.CurrentX = 0
' Draw all y- scales exept the zero
For i = 0 To 4
' Draw scales
.CurrentY = Int(.ScaleHeight / 4) * i
Graph.Print MaxScaleValue - Int(MaxScaleValue * i / 4)
Next i
' 打印 y- 坐标 0
.CurrentY = .ScaleHeight - 200
Graph.Print 0
End With
Graph.ForeColor = &HC0C0C0
' 画线
For i = 1 To colGraphValues.Count
' 新点
IntX(1) = IntX(0) + 200
IntY(1) = colGraphValues(i) * intYScale
' 画线
Graph.Line (Graph.Width - IntX(0), Graph.Height - IntY(0))-(Graph.Width - IntX(1), Graph.Height - IntY(1)), vbGreen
' 旧点
IntX(0) = IntX(1)
IntY(0) = IntY(1)
Next i
DoEvents
End Function