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.

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

index = Asc(letter)<br />

charCount(index) = charCount(index) + 1<br />

End If<br />

Next letterNum<br />

‘List the tally for each letter of alphabet<br />

picLetterCount.Font = “Courier”<br />

picLetterCount.Cls<br />

column = 1 ‘Next column at which to display letter & count<br />

For letterNum = Asc(“A”) To Asc(“Z”)<br />

letter = Chr(letterNum)<br />

picLetterCount.Print Tab(column); letter;<br />

picLetterCount.Print Tab(column + 1); charCount(letterNum);<br />

column = column + 6<br />

If column > 42 Then ‘only room for 7 sets of data in a line<br />

picLetterCount.Print<br />

column = 1<br />

End If<br />

Next letterNum<br />

End Sub<br />

[Run, type in the given sentence, <strong>and</strong> click the comm<strong>and</strong> button.]<br />

COMMENTS<br />

1. Arrays must be dimensioned in a Dim or ReDim statement before they are used.<br />

If a statement such as a(6) = 3 appears without a previous Dim or ReDim of the<br />

array a( ), then the error message “Sub or Function not defined” will be displayed<br />

when an attempt is made to run the program.<br />

2. Subscripts in ReDim statements can be numeric expressions. Subscripts whose<br />

values are not whole numbers are rounded to the nearest whole number. Subscripts<br />

outside the range of the array produce an error message as shown below<br />

when the last line of the event procedure is reached.

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

Saved successfully!

Ooh no, something went wrong!