系统测试
Public d As Integer
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub MSHFlexGrid1_Click()
Dim i%, j%, A!(), m%, n%
Dim mlink As String, mpath As String, macc As String
Dim k As Integer
Dim Cnn As New ADODB.Connection
Dim Rst As New ADODB.Recordset
mlink = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= 系统测试.mdb"
macc = "select * from 股票系统测试表 where 代码 = '" & MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, 1) & " '"
'macc = "select * from 0015"
Cnn.Open mlink
Set Rst = New ADODB.Recordset
Rst.Open macc, Cnn, adOpenKeyset, adLockOptimistic
'2 获得表的字段数和记录数
Rst.MoveLast ‘此处是调试的断点
j = Rst.RecordCount - 1
i = Rst.Fields.Count - 1
'3 利用循环赋值
ReDim A(i, j)
s = 50
For n = 0 To j
If n > 0 Then
Rst.MoveNext
If Rst.EOF Then
Rst.MoveLast
End If
Else
Rst.MoveFirst
End If
For m = 0 To i
A(m, n) = Rst.Fields(m)
'Print A(m, n);
Next m
'Print
Next n
Cnn.Close
OLE1.object.application.DataSheet.cells(1, 1).Value = "日期"
OLE1.object.application.DataSheet.cells(2, 1).Value = "开盘价"
OLE1.object.application.DataSheet.cells(3, 1).Value = "最高价"
OLE1.object.application.DataSheet.cells(4, 1).Value = "最低价"
OLE1.object.application.DataSheet.cells(5, 1).Value = "收盘价"
OLE1.object.application.Chart.ChartType = 89
For k = s - 48 To s
OLE1.object.application.DataSheet.cells(1, k).Value = A(1, k - 1)
OLE1.object.application.DataSheet.cells(2, k).Value = A(6, k - 1)
OLE1.object.application.DataSheet.cells(3, k).Value = A(7, k - 1)
OLE1.object.application.DataSheet.cells(4, k).Value = A(8, k - 1)
OLE1.object.application.DataSheet.cells(5, k).Value = A(3, k - 1)
Next k
Adodc1.ConnectionString = mlink
Adodc1.CommandType = adCmdText
sql = "SELECT TOP 30 * FROM 股票系统测试表 WHERE 代码 = '008015' AND 时间 <= #" & Format(s, "yyyy-mm-dd hh:nn:ss") & "# ORDER BY 时间 DESC"
Adodc1.RecordSource = sql
Adodc1.Refresh
Set Text1.DataSource = Adodc1
Text1.DataField = "时间"
Text2.DataField = "代码"
For i = 1 To MSHFlexGrid1.Rows - 1
MSHFlexGrid1.Row = i
MSHFlexGrid1.Col = 4
If MSHFlexGrid1.Text > 0 Then
MSHFlexGrid1.CellForeColor = vbRed
MSHFlexGrid1.Col = 2
MSHFlexGrid1.CellForeColor = vbRed
MSHFlexGrid1.Col = 6
MSHFlexGrid1.CellForeColor = vbRed
MSHFlexGrid1.Col = 3
MSHFlexGrid1.CellForeColor = vbRed
Else
If MSHFlexGrid1.Text < 0 Then
MSHFlexGrid1.CellForeColor = vbGreen
MSHFlexGrid1.Col = 2
MSHFlexGrid1.CellForeColor = vbGreen
MSHFlexGrid1.Col = 7
MSHFlexGrid1.CellForeColor = vbGreen
MSHFlexGrid1.Col = 3
MSHFlexGrid1.CellForeColor = vbGreen
End If
End If
Next
End Sub
[解决办法]
对空记录集不能 MoveLast.
[解决办法]