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.

last = middle - 1<br />

Case Is < searchCity<br />

first = middle + 1<br />

End Select<br />

Loop<br />

If foundFlag Then<br />

result = middle<br />

Else<br />

result = 0<br />

End If<br />

End Sub<br />

Private Sub Form_Load()<br />

Dim i As Integer<br />

‘Assume that the data for city name, population, medium income, % native,<br />

‘<strong>and</strong> % advanced degree have been placed in the file “CITYSTAT.TXT”<br />

‘(First line of file is “Boston”, 4.2, 4066, 73, 12)<br />

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

For i = 1 To 10<br />

Input #1, city(i), pop(i), income(i), natives(i), advDeg(i)<br />

Next i<br />

Close #1<br />

End Sub<br />

Private Sub GetCityName(searchCity As String)<br />

‘Request name of city as input<br />

searchCity = UCase(Trim(txtCity.Text))<br />

End Sub<br />

Private Sub ShowData(index As Integer)<br />

‘Display city <strong>and</strong> associated information<br />

picResult.Print , “Pop. in”, “Med. income”, “% Native”, “% Advanced”<br />

picResult.Print “Metro Area”, “millions”, “per hsd”, “to State”, “Degree”<br />

picResult.Print picResult.Print city(index), pop(index), income(index),<br />

picResult.Print natives(index), advDeg(index)<br />

End Sub<br />

[Run, type San Francisco into the text box, <strong>and</strong> click the comm<strong>and</strong> button.]<br />

COMMENTS<br />

1. Suppose our bubble sort algorithm is applied to an ordered list. The algorithm<br />

will still make n – 1 passes through the list. The process could be shortened for<br />

some lists by flagging the presence of out-of-order items as in the Shell sort. It<br />

may be preferable not to use a flag, because for greatly disordered lists the flag<br />

would slow down an already sluggish algorithm.<br />

Sorting <strong>and</strong> Searching 195

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

Saved successfully!

Ooh no, something went wrong!