I had this code running for quite a while, thanks to petevick, but suddenly, a weird error happened with this code:
vb.net Code:
Private Sub LoadNewWord() Dim sr As New System.IO.StreamReader(WordList) Dim strData As String = String.Empty strData = sr.ReadToEnd Dim strRecs() As String = strData.Split(CChar(vbCrLf)) MenuItem3.Enabled = True Dim Number As Integer = RandomNumber(0, strRecs.GetUpperBound(0)) Dim word As String = strRecs(Number) GlobalWord = word Try For Each ch As Char In GlobalWord PictureBox1.Image = letterImages(ch) 'Right here, the ch is a weird character PictureBox1.Refresh() System.Threading.Thread.Sleep(speed) PictureBox1.Image = letterImages(CChar(" ")) PictureBox1.Refresh() System.Threading.Thread.Sleep(10) Next Catch ex As Exception MessageBox.Show("There was an error with the program. Please restart the program!") WriteErrorReport(ex.StackTrace) Me.Close() End Try End Sub
I stepped through the debugger on the function, and as it went over to set the PictureBox, the character was a square, like an invalid character, which makes no sense. The letterImages is a list of lowercase and capital letters, and a space for showing letter change.
Now, what I don't get is why it did an invalid character, when the word list is:
"one two three four"
and the string is splitting at the spaces. Any clues?
EDIT: I stepped through again, and noticed it wasn't removing the spaces before the words, and I can't seem to get it to do that, any help?


Reply With Quote
