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.

picOutput.Scale (-2, 12)-(12, -2) ‘Specify coordinate system<br />

picOutput.Line (-2, 0)-(12, 0) ‘Draw x-axis<br />

picOutput.Line (0, -2)-(0, 12) ‘Draw y-axis<br />

picOutput.PSet (7, 6) ‘Draw center of circle<br />

picOutput.Circle (7, 6), 3<br />

End Sub<br />

‘Draw the circle<br />

[Run, <strong>and</strong> then click the comm<strong>and</strong> button. The contents of the picture box is shown in<br />

Figure 9-5.]<br />

FIGURE 9-5 Graph for Example 3<br />

The numbers appearing in the Scale, Line, PSet, <strong>and</strong> Circle methods can be replaced by<br />

variables or expressions. The following example demonstrates this feature.<br />

EXAMPLE 4<br />

Write an event procedure to draw a graph of the square root function.<br />

SOLUTION:<br />

We will graph the function for values of x from 0 to 100. See Figure 9.6.<br />

Private Sub cmdDraw_Click()<br />

Dim x As Single<br />

‘Graph the Square Root Function<br />

picOutput.Cls<br />

picOutput.Scale (-20, 12)-(120, -2) ‘Specify coordinate system<br />

picOutput.Line (-5, 0)-(100, 0) ‘Draw x-axis<br />

picOutput.Line (0, -1)-(0, 10) ‘Draw y-axis<br />

For x = 0 To 100 Step 0.2 ‘Plot about 500 points<br />

picOutput.PSet (x, Sqr(x)) ‘Plot point on graph<br />

Next x<br />

End Sub<br />

[Run, <strong>and</strong> then click the comm<strong>and</strong> button. The resulting picture box is shown in Figure 9-6.]<br />

FIGURE 9-6 Graph of the Square Root Function<br />

■ POSITIONING TEXT<br />

Introduction to Graphics 263<br />

There are times when text is placed on the screen in conjunction with graphics. This would be<br />

the case if a graph were to be titled or a tick mark needed a label. The ability to position such

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

Saved successfully!

Ooh no, something went wrong!