' A record for a student.
Private Type StudentRecord
LastName As String
FirstName As String
Age As Integer
StudentID As Integer
Score(1 To NUM_TESTS) As Integer
End Type
Private NumStudents As Integer
Private Students() As StudentRecord
' Graph the age data.
Private Sub GraphAges()
Dim student As Integer
Dim lft As Single
Dim i As Integer
Dim the_age As Integer
Dim txt As String
Dim font_hgt As Single
txt = Students(student).LastName
picAge.CurrentX = student - 0.5 - _
picAge.TextWidth(txt) / 2
picAge.CurrentY = font_hgt * 1.5
picAge.Print txt
Next student
End Sub
' Graph the test score data.
Private Sub GraphScores()
Dim test As Integer
Dim lft As Single
Dim i As Integer
Dim the_score As Integer
Dim txt As String
Dim font_hgt As Single
Dim student As Integer
' Draw the axes.
picScore.Line (1, 100)-(1, 0)
picScore.Line -(NUM_TESTS, 0)
For i = 10 To 100 Step 10
picScore.Line (1 - lft / 6, i)-Step(lft / 3, 0)
txt = Format$(i)
picScore.CurrentX = 1 + lft / 4 - picScore.TextWidth(txt)
picScore.CurrentY = i - font_hgt / 2
picScore.Print txt
Next i
font_hgt = font_hgt * 1.2
picScore.DrawStyle = vbDot
For test = 1 To NUM_TESTS
picScore.Line (test, 0)-(test, 100)
txt = Format$(test)
picScore.CurrentX = test - picScore.TextWidth(txt) / 2
picScore.CurrentY = font_hgt / 3
picScore.Print txt
Next test
picScore.DrawStyle = vbSolid
' Graph the scores.
For student = 1 To NumStudents
' Use a different color.
picScore.ForeColor = QBColor(student Mod 8)
the_score = Students(student).Score(1)
picScore.CurrentX = 1
picScore.CurrentY = the_score
For test = 2 To NUM_TESTS
the_score = Students(student).Score(test)
picScore.Line -(test, the_score)
Next test
Next student
End Sub
' Load the data from the database.
Private Sub LoadData()
Dim ws As Workspace
Dim db As Database
Dim student_rs As Recordset
Dim score_rs As Recordset
Dim query As String
' Use the default workspace.
Set ws = DBEngine.Workspaces(0)
' Open the database.
Set db = ws.OpenDatabase(App.Path & "\graphdb.mdb")
' Create a Recordset to read name,
' ID, and age information.
query = _
"SELECT FirstName, LastName, " & _
"StudentID, Age FROM Students " & _
"ORDER BY StudentID"
Set student_rs = _
db.OpenRecordset(query, dbOpenSnapshot)
' Read the name, ID, and age information.
With student_rs
Do While Not .EOF
NumStudents = NumStudents + 1
ReDim Preserve Students(1 To NumStudents)
Students(NumStudents).LastName = !LastName
Students(NumStudents).FirstName = !FirstName
Students(NumStudents).Age = !Age
Students(NumStudents).StudentID = !StudentID
' Get this student's test scores.
query = _
"SELECT TestNumber, Score FROM " & _
"TestScores WHERE StudentID=" & _
!StudentID & _
" ORDER BY TestNumber"
Set score_rs = _
db.OpenRecordset(query, dbOpenSnapshot)
Do While Not score_rs.EOF
Students(NumStudents).Score( _
score_rs!TestNumber) = _
score_rs!Score
Private Sub Command1_Click()
Dim obGR As Graph.Application
Set obGR = Me.OLE1.object.Application
obGR.FileImport "C:\bbb\ccc.xls"
'.......
End Sub
余下的照着“对象浏览器”慢慢研究吧