home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form frm10_2_2
- Caption = "Multi-Line Chart"
- ClientHeight = 4665
- ClientLeft = 1410
- ClientTop = 1800
- ClientWidth = 6360
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- LinkTopic = "Form1"
- PaletteMode = 1 'UseZOrder
- ScaleHeight = 4665
- ScaleWidth = 6360
- Begin VB.PictureBox picEnroll
- Height = 3735
- Left = 240
- ScaleHeight = 3675
- ScaleWidth = 5835
- TabIndex = 1
- Top = 720
- Width = 5895
- End
- Begin VB.CommandButton cmdDraw
- Caption = "Draw Chart of Two-Year College Enrollments"
- Height = 495
- Left = 960
- TabIndex = 0
- Top = 120
- Width = 4215
- End
- Attribute VB_Name = "frm10_2_2"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Dim numYears As Integer, maxEnroll As Single
- Private Sub cmdDraw_Click()
- 'Line Charts of Two-Year College Enrollments
- numYears = 5
- ReDim label(1 To numYears) As String, male(1 To numYears) As Single
- ReDim female(1 To numYears) As Single, total(1 To numYears) As Single
- Call ReadData(label(), male(), female(), total())
- Call DrawAxes
- Call DrawData(male(), female(), total())
- Call ShowTitle
- Call ShowLabels(label())
- Call ShowLegend
- End Sub
- Private Sub DrawAxes()
- 'Draw axes
- picEnroll.Scale (-1, 1.2 * maxEnroll)-(numYears + 1, -0.2 * maxEnroll)
- picEnroll.Line (-1, 0)-(numYears + 1, 0)
- picEnroll.Line (0, -0.1 * maxEnroll)-(0, 1.1 * maxEnroll)
- End Sub
- Private Sub DrawData(male() As Single, female() As Single, total() As Single)
- Dim i As Integer
- For i = 1 To numYears
- If i < numYears Then
- 'Draw lines connecting data points
- picEnroll.DrawStyle = 2
- picEnroll.Line (i, male(i))-(i + 1, male(i + 1))
- picEnroll.DrawStyle = 1
- picEnroll.Line (i, female(i))-(i + 1, female(i + 1))
- picEnroll.DrawStyle = 0
- picEnroll.Line (i, total(i))-(i + 1, total(i + 1))
- End If
- 'Draw small circles around data points
- picEnroll.Circle (i, male(i)), 0.01 * numYears
- picEnroll.Circle (i, female(i)), 0.01 * numYears
- picEnroll.Circle (i, total(i)), 0.01 * numYears
- Next i
- End Sub
- Private Sub Locate(x As Single, y As Single)
- picEnroll.CurrentX = x
- picEnroll.CurrentY = y
- End Sub
- Private Sub ReadData(label() As String, male() As Single, female() As Single, total() As Single)
- Dim i As Integer
- 'Assume the data has been placed in the file "ENROLLMF.DAT"
- 'as Year, Male, Female
- '(First line of file is "1960", 283, 170)
- 'Read data into arrays, find highest enrollment
- Open App.Path & "\ENROLLMF.TXT" For Input As #1
- maxEnroll = 0
- For i = 1 To numYears
- Input #1, label(i), male(i), female(i)
- total(i) = male(i) + female(i)
- If maxEnroll < total(i) Then
- maxEnroll = total(i)
- End If
- Next i
- Close #1
- End Sub
- Private Sub ShowLabels(label() As String)
- Dim i As Integer, lbl As String, lblWid As Single
- Dim lblHght As Single, tickFactor As Single
- 'Draw tick marks and label them
- For i = 1 To numYears
- lblWid = picEnroll.TextWidth(label(i))
- tickFactor = 0.02 * maxEnroll
- picEnroll.Line (i, -tickFactor)-(i, tickFactor)
- Call Locate(i - lblWid / 2, -tickFactor)
- picEnroll.Print label(i)
- Next i
- lbl = Str(maxEnroll)
- lblWid = picEnroll.TextWidth(lbl)
- lblHght = picEnroll.TextHeight(lbl)
- tickFactor = 0.02 * numYears
- picEnroll.Line (-tickFactor, maxEnroll)-(tickFactor, maxEnroll)
- Call Locate(-tickFactor - lblWid, maxEnroll - lblHght / 2)
- picEnroll.Print lbl
- End Sub
- Private Sub ShowLegend()
- 'Show legend
- picEnroll.DrawStyle = 2
- picEnroll.Line (0.1, 1.05 * maxEnroll)-(0.9, 1.05 * maxEnroll)
- Call Locate(1, 1.1 * maxEnroll)
- picEnroll.Print "Male"
- picEnroll.DrawStyle = 1
- picEnroll.Line (0.1, 0.95 * maxEnroll)-(0.9, 0.95 * maxEnroll)
- Call Locate(1, maxEnroll)
- picEnroll.Print "Female"
- picEnroll.DrawStyle = 0
- picEnroll.Line (0.1, 0.85 * maxEnroll)-(0.9, 0.85 * maxEnroll)
- Call Locate(1, 0.9 * maxEnroll)
- picEnroll.Print "Total"
- End Sub
- Private Sub ShowTitle()
- 'Display source and title
- Call Locate(-0.5, -0.1 * maxEnroll)
- picEnroll.Print "Source: Statistical Abstract of the United States"
- Call Locate(0.5, 1.2 * maxEnroll)
- picEnroll.Print "Two-Year College Enrollments (in thousands)"
- End Sub
-