collection

ustbzhy 2010-01-06 11:08:51
Dim colGraph As New Collection
.........

colGraph.Add Adodc1.Recordset.Fields("流量")

希望将数据库中的“时间”字段和“流量”字段循环写入到colGraph集合中,应该如何写代码?

...全文
51 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liguicd 2010-01-07
  • 打赏
  • 举报
回复
顶u
king06 2010-01-07
  • 打赏
  • 举报
回复
要么将两个字段连接起来写入,要么用两个循环。顺手写个样子:
for i=0 to Adodc1.Recordset.recordcount-1
colGraph.Add Adodc1.Recordset.Fields("时间")
Adodc1.Recordset.movenext
next

Adodc1.Recordset.movefirst
for i=0 to Adodc1.Recordset.recordcount-1
colGraph.Add Adodc1.Recordset.Fields("流量")
Adodc1.Recordset.movenext
next
ustbzhy 2010-01-07
  • 打赏
  • 举报
回复
原来程序可以自动画图
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
  • 打赏
  • 举报
回复
加个类呀,家里没法看,有问题明天看。
ustbzhy 2010-01-07
  • 打赏
  • 举报
回复
如何建aaa小类。
  • 打赏
  • 举报
回复
建个小类 aaa
时间
流量

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("流量")
要用时再分开,"|" 调你喜欢的用

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧