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.

Private Sub ShowTitle()<br />

‘Display source <strong>and</strong> title<br />

Call Locate(-.5, -.1 * maxEnroll)<br />

picEnroll.Print “Source: Statistical Abstract of the United States”<br />

Call Locate(.5, 1.2 * maxEnroll)<br />

picEnroll.Print “Two-Year College Enrollments (in thous<strong>and</strong>s)”<br />

End Sub<br />

FIGURE 9-9 Chart for Example 1<br />

Remarks on the program in Example 1<br />

1. The value of tickFactor in the Sub procedure ShowLabels was set to 2 percent<br />

of the scale determiners (numYears <strong>and</strong> maxEnroll) for the x <strong>and</strong> y axes. This<br />

percentage is appropriate for picture boxes that occupy 1/4th to 1/3rd of the<br />

screen. Smaller picture boxes might require a factor of 3 percent or 4 percent<br />

for good-looking tick marks. Picture boxes that almost fill the screen might<br />

have good results with a factor as small as 1 percent.<br />

2. In the Sub procedure ShowLabels, the TextWidth <strong>and</strong> TextHeight methods were<br />

used to obtain the width <strong>and</strong> height of each label. These values were used<br />

together with the coordinates of the appropriate end of the tick mark to assign<br />

values to CurrentX <strong>and</strong> CurrentY for proper placement of the label relative to<br />

the graphics.<br />

3. In the event procedure cmdDraw_Click, the number of data points (5) was<br />

assigned to the variable numYears, <strong>and</strong> then numYears was used as a parameter<br />

to all other Sub procedures. This feature makes it easy to add additional data to<br />

the line chart. For instance, if we decide to include the data for one additional<br />

year, we will only have to change the value of numYears <strong>and</strong> add one more line<br />

to the data file.<br />

■ LINE STYLING<br />

Patterned, or “styled,” lines can be drawn between two points. Some available line styles are<br />

shown in Figure 9-10. Each line has an associated number identifying its style. If s is one of<br />

the numbers in the figure, then the statements<br />

picBox.DrawStyle = s<br />

picBox.Line (a, b)-(c, d)<br />

draw the line from (a, b) to (c, d) in the style corresponding to the number s.<br />

Line Charts 269

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

Saved successfully!

Ooh no, something went wrong!