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.

268 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><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(total() As Single)<br />

i As Integer<br />

‘Draw lines connecting data <strong>and</strong> circle data points<br />

For i = 1 To numYears<br />

If i < numYears Then<br />

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

End If<br />

picEnroll.Circle (i, total(i)), .01 * numYears<br />

Next i<br />

End Sub<br />

Private Sub Locate(x As Single, y As Single)<br />

picEnroll.CurrentX = x<br />

picEnroll.CurrentY = y<br />

End Sub<br />

Private Sub ReadData(label() As String, total() As Single)<br />

Dim i As Integer<br />

‘Assume the data have been placed in the file “ENROLL.TXT”<br />

‘(First line of the file is “1960”,453)<br />

‘Read data into arrays, find highest enrollment<br />

maxEnroll = 0<br />

Open ”ENROLL.TXT” For Input As #1<br />

For i = 1 To numYears<br />

Input #1, label(i), total(i)<br />

If total(i) > maxEnroll Then<br />

maxEnroll = total(i)<br />

End If<br />

Next i<br />

Close #1<br />

End Sub<br />

Private Sub ShowLabels(label() As String)<br />

Dim i As Integer, lbl As String, lblWid As Single<br />

Dim lblHght As Single, tickFactor As Single<br />

‘Draw tick marks <strong>and</strong> label them<br />

For i = 1 To numYears<br />

lbl = Right(label(i), 2)<br />

lblWid = picEnroll.TextWidth(lbl)<br />

tickFactor = .02 * maxEnroll<br />

picEnroll.Line (i, -tickFactor)-(i, tickFactor)<br />

Call Locate(i - lblWid / 2, -tickFactor)<br />

picEnroll.Print lbl<br />

Next i<br />

lbl = Str(maxEnroll)<br />

lblWid = picEnroll.TextWidth(lbl)<br />

lblHght = picEnroll.TextHeight(lbl)<br />

tickFactor = .02 * numYears<br />

picEnroll.Line (-tickFactor, maxEnroll)-(tickFactor, maxEnroll)<br />

Call Locate(-tickFactor - lblWid, maxEnroll - lblHght / 2)<br />

picEnroll.Print lbl<br />

End Sub

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

Saved successfully!

Ooh no, something went wrong!