Having a problem with this piece of code i have wrote. for some reason if the word i have searched is found it will post the message but if it is not found it will not post and crashes on me. I think it gets stuck in the loop. Any tips? Thanks in advance
Code:
Public Class Form1
Dim foundWord As Boolean
Dim allWords() As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
'Code for Spell Checker, Created by Murray Hart'
'Version1 - 08/11/2012'
allWords = IO.File.ReadAllLines("words.txt")
'Call sub routine to search for the entered word'
Call checkWord()
End Sub
Private Sub checkWord()
'Code for search routine'
Dim enteredWord As String = txtInput.Text
'Set found statud to false until found'
foundWord = False
While foundWord = False
For Each Str As String In allWords
If Str.Contains(enteredWord) Then
foundWord = True
End If
Next
End While
If foundWord = True Then
lblResult.Text = enteredWord & " was found"
Else
lblResult.Text = enteredWord & " was not found"
End If
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
'add word in textbox to the text file'
My.Computer.FileSystem.WriteAllText("words.txt", txtInput.Text & vbCrLf, True)
lblResult.Text = "Word Added"
End Sub
End Class