Results 1 to 3 of 3

Thread: [RESOLVED] Really strange bug!

Threaded View

  1. #1

    Thread Starter
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Posts
    3,250

    Resolved [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:
    1. Private Sub LoadNewWord()
    2.         Dim sr As New System.IO.StreamReader(WordList)
    3.         Dim strData As String = String.Empty
    4.         strData = sr.ReadToEnd
    5.         Dim strRecs() As String = strData.Split(CChar(vbCrLf))
    6.  
    7.         MenuItem3.Enabled = True
    8.         Dim Number As Integer = RandomNumber(0, strRecs.GetUpperBound(0))
    9.         Dim word As String = strRecs(Number)
    10.         GlobalWord = word
    11.         Try
    12.             For Each ch As Char In GlobalWord
    13.                 PictureBox1.Image = letterImages(ch) 'Right here, the ch is a weird character
    14.                 PictureBox1.Refresh()
    15.                 System.Threading.Thread.Sleep(speed)
    16.                 PictureBox1.Image = letterImages(CChar(" "))
    17.                 PictureBox1.Refresh()
    18.                 System.Threading.Thread.Sleep(10)
    19.             Next
    20.         Catch ex As Exception
    21.             MessageBox.Show("There was an error with the program. Please restart the program!")
    22.             WriteErrorReport(ex.StackTrace)
    23.             Me.Close()
    24.         End Try
    25.     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?
    Last edited by formlesstree4; Jul 13th, 2009 at 03:35 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width