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.

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

picPop.CurrentX = .7 ‘Beginning horizontal position of<br />

label for CA<br />

picPop.Print “California”; ‘Beginning horizontal position of<br />

label for NY<br />

picPop.CurrentX = 1.7 picPop.Print “New York”;<br />

End Sub<br />

FIGURE 9-14 Coordinates of Principal Points of Example 1<br />

Any program that draws a line chart can be easily modified to produce a bar chart. Multiple<br />

line charts are converted into so-called clustered bar charts.<br />

EXAMPLE 2<br />

Display the 2-year college enrollments for males <strong>and</strong> females in a clustered bar chart. Use the data in<br />

Table 9.2 of Section 9.4.<br />

SOLUTION:<br />

The output of the following program appears in Figure 9-15. This program is very similar to the program<br />

that produced Figure 9-11 of Section 9.4.<br />

Private Sub cmdDraw_Click()<br />

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

‘Bar Chart of Total 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 />

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

Call DrawAxes(numYears, maxEnroll)<br />

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

Call ShowTitle(maxEnroll)<br />

Call ShowLabels(label(), numYears, maxEnroll)<br />

Call ShowLegend(maxEnroll)<br />

End Sub<br />

Private Sub<br />

DrawAxes(numYears As Integer, maxEnroll As Single)<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

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

Saved successfully!

Ooh no, something went wrong!