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.

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

Call DisplayArray(spokLang(), numSpokLangs)<br />

End Sub<br />

Private Sub DisplayArray(lang() As String, howMany As Integer)<br />

Dim i As Integer<br />

‘Display the languages in the array<br />

picAllLang.Cls<br />

For i = 1 To howMany<br />

picAllLang.Print lang(i) & “ ”;<br />

Next i<br />

End Sub<br />

Private Sub Form_Load()<br />

‘Fill computer language array from COMPLANG.TXT<br />

numCompLangs = 0 Open “COMPLANG.TXT” For Input As #1<br />

Do While (Not EOF(1)) And (numCompLangs < 20)<br />

numCompLangs = numCompLangs + 1<br />

Input #1, compLang(numCompLangs)<br />

Loop<br />

Close #1<br />

‘Fill spoken language array from SPOKLANG.TXT<br />

numSpokLangs = 0<br />

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

Do While (Not EOF(1)) And (numSpokLangs < 20)<br />

numSpokLangs = numSpokLangs + 1<br />

Input #1, spokLang(numSpokLangs)<br />

Loop<br />

Close #1<br />

End Sub<br />

[Run, type in German, <strong>and</strong> click Add to Spoken List.]<br />

[Type in FORTRAN <strong>and</strong> click Add to <strong>Computer</strong> List.]<br />

COMMENTS<br />

1. In Examples 1 <strong>and</strong> 5 we searched successive elements of an ordered list beginning<br />

with the first element. This is called a sequential search. An efficient<br />

alternative to the sequential search is the binary search, which is considered in<br />

the next section.<br />

2. A single element of an array can be passed to a procedure just like any ordinary<br />

numeric or string variable.<br />

Private Sub cmdButton_Click()<br />

Dim num(1 To 20) As Integer

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

Saved successfully!

Ooh no, something went wrong!