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.

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

picEnroll.DrawStyle = 0<br />

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

End If<br />

‘Draw small circles around data points<br />

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

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

picEnroll.Circle (i, total(i)), .01 * numYears 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, male() As Single, _ female()<br />

As Single, total() As Single)<br />

‘The two lines above should be enter as one line<br />

Dim i As Integer<br />

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

‘as Year, male, female<br />

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

‘Read data into arrays, find highest enrollment Open ”ENROLLMF.TXT”<br />

For Input As #1<br />

maxEnroll = 0<br />

For i = 1 To numYears<br />

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

total(i) = male(i) + female(i)<br />

If maxEnroll < total(i) 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<br />

Line Charts 271

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

Saved successfully!

Ooh no, something went wrong!