19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

270 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

FIGURE 9-10 Line Patterns<br />

Styling is useful when displaying several line charts on the same coordinate system.<br />

EXAMPLE 2<br />

Alter the program in Example 1 so that it will draw line charts displaying the male, female, <strong>and</strong> total<br />

enrollments of 2-year colleges.<br />

SOLUTION:<br />

The data file must be changed to contain the enrollment figures for males <strong>and</strong> females, <strong>and</strong> arrays must<br />

be created to hold this information. The totals can be computed from the other numbers. The styled lines<br />

for male <strong>and</strong> female enrollments must be drawn. Finally, legends must be given to identify the different<br />

line charts. Figure 9-11 shows the picture box that results from the modified program.<br />

‘In (Declarations) section of (General)<br />

Dim numYears As Integer, maxEnroll As Single<br />

Private Sub cmdDraw_Click()<br />

‘Line Charts of Two-Year College Enrollments<br />

numYears = 5<br />

ReDim label(1 To numYears) As String<br />

ReDim male(1 To numYears) As Single<br />

ReDim female(1 To numYears) As Single<br />

ReDim total(1 To numYears) As Single<br />

Call ReadData(label(),male(),female(),total())<br />

Call DrawAxes<br />

Call DrawData(male(), female(), total())<br />

Call ShowTitle<br />

Call ShowLabels(label())<br />

Call ShowLegend<br />

End Sub<br />

Private Sub DrawAxes()<br />

‘Draw axes<br />

picEnroll.Scale (-1, 1.2 * maxEnroll) - (numYears + 1, -.2 * maxEnroll)<br />

picEnroll.Line (-1, 0)-(numYears + 1, 0)<br />

picEnroll.Line (0, -.1 * maxEnroll)-(0, 1.1 * maxEnroll)<br />

End Sub<br />

Private Sub DrawData(male() As Single, female() As Single, total() As Single)<br />

Dim i As Integer<br />

For i = 1 To numYears<br />

If i < numYears Then<br />

‘Draw lines connecting data points<br />

picEnroll.DrawStyle = 2<br />

picEnroll.Line (i, male(i))-(i + 1, male(i + 1))<br />

picEnroll.DrawStyle = 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!