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.

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

EXAMPLE 2<br />

Consider Figure 9.4.<br />

(a) Give the statement that specifies the range for the numbers on the axes.<br />

(b) Give the statements that will draw the axes.<br />

(c) Give the statement that will draw the line.<br />

FIGURE 9-4 Graph for Example 2<br />

SOLUTION:<br />

(a) picOutput.Scale (-1, 120)-(5, -10)<br />

(b) x axis: picOutput.Line (-1, 0)-(5, 0)<br />

y axis: picOutput.Line (0, -10)-(0, 120)<br />

(c) picOutput.Line (1, 100)-(4, 50)<br />

There are two other graphics methods that are just as useful as the Line method. The<br />

statement<br />

picOutput.PSet (x, y)<br />

plots the point with coordinates (x, y). The statement<br />

picOutput.Circle (x, y), r<br />

draws the circle with center (x, y) <strong>and</strong> radius r.<br />

EXAMPLE 3<br />

Write an event procedure to plot the point (7, 6) in a picture box <strong>and</strong> draw a circle of radius 3 about the<br />

point.<br />

SOLUTION:<br />

The rightmost point to be drawn will have x coordinate 10; therefore the numbers on the x axis must range<br />

beyond 10. In the following event procedure, we allow the numbers to range from –2 to 12. See<br />

Figure 9-5.<br />

Private Sub cmdDraw_Click()<br />

‘Draw circle with center (7, 6) <strong>and</strong> radius 3<br />

picOutput.Cls‘Clear picture box

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

Saved successfully!

Ooh no, something went wrong!