[RESOLVED] Really strange bug!
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?
Re: [RESOLVED] Really strange bug!
Hey,
I think a better way to achieve this would be to use the Trim Method:
http://msdn.microsoft.com/en-us/libr...im(VS.71).aspx
Gary