新手问怎样把vb6的chart连到access(资料库), 谁可以帮我改一改?
已经做好chart和text可以显示access的数据请求帮助,但是chart不能连接和读取access的数据
下面是chart的介面
Dim rptrs As Recordset
Dim dbcls As New dbclass
Dim ii As Double
Dim iii As Integer
Dim e As Double
Dim r As Double
Public chht As Long
Public chwd As Long
Dim chht1 As Long
Dim chwd1 As Long
Private Sub cmdborder_Click(Index As Integer)
optdef.Value = False
With MSChart1.Plot.Backdrop
Select Case Index
Case 0
.Frame.Style = VtFrameStyleThickOuter
' Set style to show a shadow.
Case 1
.Frame.Style = VtFrameStyleNull
' .Shadow.Style = VtShadowStyleDrop
End Select
End With
End Sub
Private Sub cmdcancel_Click()
Unload Me
End Sub
Private Sub cmdch_Click(Index As Integer)
optdef.Value = False
MSChart1.ShowLegend = True
Select Case Index
Case 0
MSChart1.chartType = VtChChartType2dBar
Case 1
MSChart1.chartType = VtChChartType3dBar
Case 2
MSChart1.chartType = VtChChartType2dPie
Case 3
MSChart1.chartType = VtChChartType2dLine
Case 4
MSChart1.chartType = VtChChartType3dLine
Case 5
MSChart1.chartType = VtChChartType3dStep
End Select
End Sub
Private Sub cmdeffect_Click(Index As Integer)
optdef.Value = False
With MSChart1.Plot
Select Case Index
Case 0
' Set the style to solid.
.Wall.Brush.Style = VtBrushStyleHatched
Case 1
.Wall.Brush.Style = VtBrushStyleSolid
End Select
' Set the color to white.
.Wall.Brush.FillColor.Set 255, 255, 255
End With
End Sub
Private Sub cmdrowcol_Click(Index As Integer)
optdef.Value = False
Select Case Index
Case 0
MSChart1.Plot.DataSeriesInRow = True
Case 1
MSChart1.Plot.DataSeriesInRow = False
End Select
End Sub
Private Sub cmdsave_Click()
On Error GoTo saverr
Dim strsavefile As String
With dlgChart ' CommonDialog object
.Filter = "Pictures (*.bmp)|*.bmp"
.DefaultExt = "bmp"
.CancelError = True
.ShowSave
strsavefile = .FileName
If strsavefile = "" Then Exit Sub
End With
MSChart1.EditCopy
SavePicture Clipboard.GetData, strsavefile
Exit Sub
saverr:
MsgBox Err.Description
End Sub
Private Sub cmdshadow_Click(Index As Integer)
optdef.Value = False
With MSChart1.Plot.Backdrop
Select Case Index
Case 0
.Shadow.Style = VtShadowStyleDrop
' Set style to show a shadow.
Case 1
.Shadow.Style = VtShadowStyleNull
End Select
End With
End Sub
Private Sub Command1_Click()
e = MSChart1.Plot.View3d.Elevation
r = MSChart1.Plot.View3d.Rotation
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Timer2.Enabled = False
e = MSChart1.Plot.View3d.Elevation
r = MSChart1.Plot.View3d.Rotation
ii = 1
iii = 1
End Sub
Private Sub Command3_Click()
e = MSChart1.Plot.View3d.Elevation
r = MSChart1.Plot.View3d.Rotation
Timer1.Enabled = True
End Sub
Private Sub Form_Activate()
If chht1 > 0 Then
MSChart1.Height = chht1
MSChart1.Width = chwd1
End If
End Sub
Private Sub Form_Load()
Dim dbname1 As Connection
Set dbname1 = dbcls.dbname3
Set rptrs = New Recordset
rptrs.Open "select * from table1", dbname1, adOpenStatic, adLockOptimistic
With MSChart1
Set .DataSource = rptrs
.ShowLegend = True
End With
End Sub
' Paste these functions into the Declarations section
' of the Form or Code Module.
Public Function RedFromRGB(ByVal rgb As Long) _
As Integer
' The ampersand after &HFF coerces the number as a
' long, preventing Visual Basic from evaluating the
' number as a negative value. The logical And is
' used to return bit values.
RedFromRGB = &HFF& And rgb
End Function
Public Function GreenFromRGB(ByVal rgb As Long) _
As Integer
' The result of the And operation is divided by
' 256, to return the value of the middle bytes.
' Note the use of the Integer divisor.
GreenFromRGB = (&HFF00& And rgb) \ 256
End Function
Public Function BlueFromRGB(ByVal rgb As Long) _
As Integer
' This function works like the GreenFromRGB above,
' except you don't need the ampersand. The
' number is already a long. The result divided by
' 65536 to obtain the highest bytes.
BlueFromRGB = (&HFF0000 And rgb) \ 65536
End Function
Private Sub Form_Unload(Cancel As Integer)
Clipboard.Clear
End Sub
Private Sub Label1_Click()
Picture2.Visible = False
End Sub
Private Sub Label2_Click()
Picture2.Visible = False
End Sub
Private Sub MSChart1_SeriesActivated(Series As _
Integer, MouseFlags As Integer, Cancel As Integer)
On Error GoTo colerr
' The CommonDialog control is named dlgChart.
Dim red, green, blue As Integer
With dlgChart ' CommonDialog object
.CancelError = True
.ShowColor
red = RedFromRGB(.Color)
green = GreenFromRGB(.Color)
blue = BlueFromRGB(.Color)
End With
' NOTE: Only the 2D and 3D line charts use the
' Pen object. All other types use the Brush.
If MSChart1.chartType <> VtChChartType2dLine Or _
MSChart1.chartType <> VtChChartType3dLine Then
MSChart1.Plot.SeriesCollection(Series). _
DataPoints(-1).Brush.FillColor. _
Set red, green, blue
Else
MSChart1.Plot.SeriesCollection(Series).Pen. _
VtColor.Set red, green, blue
End If
Exit Sub
colerr:
MsgBox Err.Description
'MSChart1.Column = 1 ' Legen column
'MSChart1.ColumnLabel = "Voltage" ' Legan name (bar name)
End Sub
Private Sub optdef_Click()
MSChart1.ToDefaults
MSChart1.ShowLegend = True
End Sub
Private Sub Picture2_Click()
Picture2.Visible = False
End Sub
Private Sub Picture1_Click()
End Sub
Private Sub quit_Click()
End
End Sub
Private Sub Timer1_Timer()
MSChart1.Plot.View3d.Set r + ii, e
ii = ii + 1
End Sub
Private Sub VScroll1_Change()
Picture1.Top = 0 - VScroll1.Value * 200
If VScroll1.Value = 0 Then
' Picture1.Top = Frame1.Top
End If
End Sub
Private Sub HScroll1_Change()
Picture1.Left = 0 - HScroll1.Value * 400
If HScroll1.Value = 0 Then
Picture1.Left = 840
End If
End Sub
Private Sub Timer2_Timer()
MSChart1.Plot.View3d.Set r, e + iii
iii = iii + 1
End Sub
下面是dbclass.cls的
Dim db As ADODB.Connection
Private Sub Class_Initialize()
' IsError = False
Set db = New ADODB.Connection
On Error GoTo dbctlerror
Set strdbname = Nothing
Set strdbAutoNumber = Nothing
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\DB.mdb;"
'db.Open "PROVIDER=Microsoft.Jet.OLEDB.3.51;Data Source=" & App.Path & "\DB.mdb;"
db.CursorLocation = adUseClient
Exit Sub
dbctlerror:
MsgBox Err.Number & Err.Description & " dbclass error !"
' IsError = True
End Sub
Private Sub Class_Terminate()
db.Close
Set db = Nothing
End Sub
Public Property Get dbname3() As Connection
Set dbname3 = db
End Property
补充:VB , 基础类