home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH10 / 10-2-1.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-18  |  3.7 KB  |  115 lines

  1. VERSION 5.00
  2. Begin VB.Form frm10_2_1 
  3.    Caption         =   "Line Chart"
  4.    ClientHeight    =   4665
  5.    ClientLeft      =   1395
  6.    ClientTop       =   1560
  7.    ClientWidth     =   6360
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   4665
  20.    ScaleWidth      =   6360
  21.    Begin VB.PictureBox picEnroll 
  22.       Height          =   3735
  23.       Left            =   240
  24.       ScaleHeight     =   3675
  25.       ScaleWidth      =   5835
  26.       TabIndex        =   1
  27.       Top             =   720
  28.       Width           =   5895
  29.    End
  30.    Begin VB.CommandButton cmdDraw 
  31.       Caption         =   "Draw Chart of Two-Year College Enrollments"
  32.       Height          =   495
  33.       Left            =   960
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   4215
  37.    End
  38. Attribute VB_Name = "frm10_2_1"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Dim numYears As Integer, maxEnroll As Single
  44. Private Sub cmdDraw_Click()
  45.   'Line Chart of Total Two-Year College Enrollments
  46.   numYears = 5
  47.   ReDim label(1 To numYears) As String, total(1 To numYears) As Single
  48.   Call ReadData(label(), total())
  49.   Call DrawAxes
  50.   Call DrawData(total())
  51.   Call ShowTitle
  52.   Call ShowLabels(label())
  53. End Sub
  54. Private Sub DrawAxes()
  55.   'Draw axes
  56.   picEnroll.Scale (-1, 1.2 * maxEnroll)-(numYears + 1, -0.2 * maxEnroll)
  57.   picEnroll.Line (-1, 0)-(numYears + 1, 0)
  58.   picEnroll.Line (0, -0.1 * maxEnroll)-(0, 1.1 * maxEnroll)
  59. End Sub
  60. Private Sub DrawData(total() As Single)
  61.   Dim i As Integer
  62.   'Draw lines connecting data and circle data points
  63.   For i = 1 To numYears
  64.     If i < numYears Then
  65.         picEnroll.Line (i, total(i))-(i + 1, total(i + 1))
  66.     End If
  67.     picEnroll.Circle (i, total(i)), 0.01 * numYears
  68.   Next i
  69. End Sub
  70. Private Sub Locate(x As Single, y As Single)
  71.   picEnroll.CurrentX = x
  72.   picEnroll.CurrentY = y
  73. End Sub
  74. Private Sub ReadData(label() As String, total() As Single)
  75.   Dim i As Integer
  76.   'Assume the data has been placed in the file "ENROLL.TXT"
  77.   '(First line of the file is "1960",453)
  78.   'Read data into arrays, find highest enrollment
  79.   maxEnroll = 0
  80.   Open App.Path & "\ENROLL.TXT" For Input As #1
  81.   For i = 1 To numYears
  82.     Input #1, label(i), total(i)
  83.     If total(i) > maxEnroll Then
  84.         maxEnroll = total(i)
  85.     End If
  86.   Next i
  87.   Close #1
  88. End Sub
  89. Private Sub ShowLabels(label() As String)
  90.   Dim i As Integer, lbl As String, lblWid As Single, lblHght As Single
  91.   Dim tickFactor As Single
  92.   'Draw tick marks and label them
  93.   For i = 1 To numYears
  94.     lblWid = picEnroll.TextWidth(label(i))
  95.     tickFactor = 0.02 * maxEnroll
  96.     picEnroll.Line (i, -tickFactor)-(i, tickFactor)
  97.     Call Locate(i - lblWid / 2, -tickFactor)
  98.     picEnroll.Print label(i)
  99.   Next i
  100.   lbl = Str(maxEnroll)
  101.   lblWid = picEnroll.TextWidth(lbl)
  102.   lblHght = picEnroll.TextHeight(lbl)
  103.   tickFactor = 0.02 * numYears
  104.   picEnroll.Line (-tickFactor, maxEnroll)-(tickFactor, maxEnroll)
  105.   Call Locate(-tickFactor - lblWid, maxEnroll - lblHght / 2)
  106.   picEnroll.Print lbl
  107. End Sub
  108. Private Sub ShowTitle()
  109.   'Display source and title
  110.   Call Locate(-0.5, -0.1 * maxEnroll)
  111.   picEnroll.Print "Source: Statistical Abstract of the United States"
  112.   Call Locate(0.5, 1.2 * maxEnroll)
  113.   picEnroll.Print "Two-Year College Enrollments (in thousands)"
  114. End Sub
  115.