一个窗体form1,一个MSChart控件,引用DAO,一个按钮command
模块中的代码:
Public values() As Single
Public numpoints As Integer
Public Sub LoadData()
Dim db As Database, qdef As QueryDef, rs As Recordset, dbname As String, i As Integer
dbname = App.Path
If Right$(dbname, 1)"\" Then
dbname = dbname & "\"
End If
dbname = dbname & "data.mdb"
Set db = OpenDatabase(dbname)
Set qdef = db.CreateQueryDef("", "SELECT year,value FROM yearlyvalues")
Set rs = qdef.OpenRecordset(dbOpenSnapshot)
rs.MoveLast
numpoints = rs.RecordCount
ReDim values(1 To numpoints, 1 To 2)
rs.MoveFirst
For i = 1 To numpoints
values(i, 1) = Format$(rs!Year, "yyyy")
values(i, 2) = rs!Value
rs.MoveNext
Next i
rs.Close
db.Close
End Sub
Public Sub MakeData()
Dim the_year As Data, the_value As Single
dbname = App.Path & "\data.mdb"
Set db = OpenDatabase(dbname)
SQL = "DELETE FROM Yearlyvalues"
db.Execute SQL
the_year = #1/1/1960#
the_value = 1000
For i = 1 To 38
SQL = "INSERT INTO Yearlyvalues VALUES(#" & Format$(the_year) & "#," & Format$(the_value) & ")"
db.Execute SQL
the_year = DateAdd("yyyy", 1 + Rnd(i) * 2, the_year)
the_value = the_value + Rnd(i) * 2
Next i
db.Close
End Sub
窗体加载代码:
Private Sub Form_Load()
LoadData
If numpoints = 0 Then
MsgBox ("hahah")
End If
chart1.chartType = VtChChartType2dXY
chart1.RowCount = numpoints
chart1.ColumnCount = 2
chart1.ChartData = values
End Sub
按钮单击代码:
Private Sub Command1_Click()
MakeData
LoadData
chart1.chartType = VtChChartType2dXY
chart1.RowCount = numpoints
chart1.ColumnCount = 2
chart1.ChartData = values
End Sub
出现错误:
实时错误,3061,
参数不足,期待是1。
|