Index was outside the bounds of the array.

I_R_Lee

Regular
Joined
Jul 18, 2002
Messages
50
Location
Sydney, Australia
How would I avoid that error? It happens on this line of code:
Visual Basic:
            txtWord.Text = Replace$(txtWord.Text.Chars(I), txtWord.Text.Chars(I), "*")

I've also tried
Visual Basic:
            txtWord.Text = Replace$(txtWord.Text, txtWord.Text.Chars(I), "*")
but I get the same error.
Any help?
 
Actually, I do need help.
I get that error on these lines instead:
Visual Basic:
        Dim SB As New System.Text.StringBuilder(CurWord)
        Dim SBW As New System.Text.StringBuilder(txtWord.Text)
        Dim SBG As New StringBuilder(txtGuess.Text)
        For I = 0 To SB.Length ' Here
            If SB(I) = SBG(I) Then ' Here
                txtWord.Text = Replace(SBW(I), SB(I), SBG(I), 1, I) ' and here
            End If
        Next

How do I stop that? Or at least, how do you replace individual characters?
 
Is there a way to replace individual characters
e.g
Visual Basic:
Dim This As String = "ThisThis"
Dim That As String = "ThatThat"
txtWord.Text = This & That
For I = 0 To txtWord.Text - 1
txtWord.Text = Replace(txtWord.Text, This.Chars(I), That.Chars(I+1))
Next
Something like that, is it possible, if not, how would it be done with the string builder class?
 
Back
Top