Nested Loops with Reading 2 File
‘ This program reads the states.txt database file, and looks for matches corresponding to the ones in the file
‘ typed into the txtMyStates text box.
Dim strReadLine, strReadMyList As String
‘Note file location is in bin\debug of this project
Dim srdatabase As IO.StreamReader
Dim srmylist As IO.StreamReader = _
IO.File.OpenText(txtMyStates.Text & ".txt")
Do While srmylist.Peek <> -1
srdatabase = IO.File.OpenText("states.txt")
strReadMyList = srmylist.ReadLine
Do While srdatabase.Peek <> -1
strReadLine = srdatabase.ReadLine
If strReadLine.Length > strReadMyList.Length Then
If strReadMyList = _
strReadLine.Substring(0, strReadMyList.Length) Then
lstResults.Items.Add(strReadLine)
End If
End If
Loop
srdatabase.Close()
Loop
srmylist.Close()
End Sub

Leave a comment
You must be logged in to post a comment.