Posted the other day.......
There is prbably a better way to read form a text file using stream reader and compare to the text in a text box.... this is what I have..... It produces an out of bounds error but I still cant see why !
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
intOccur = 0
Dim intSeekStart As Integer = 0
Dim intStrLen As Integer = TextBox1.Text.Length
If TextBox1.Text <> "" Then
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
Dim fsStream As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim srReader As New StreamReader(fsStream)
Do
Dim chrCheckString(TextBox1.Text.Length - 1) As Char
srReader.Read(chrCheckString, intSeekStart, intStrLen)
Dim strCompare As New String(chrCheckString)
If strCompare.ToUpper = TextBox1.Text.ToUpper Then
intOccur += 1
Label1.Text = "Occurences = " & CStr(intOccur)
chrCheckString = Nothing
End If
intSeekStart += 1
Loop While (intSeekStart <= (srReader.BaseStream.Length - intSeekStart))
srReader.Close()
End If
End If
End Sub
