An unhandled exception of type 'System.StackOverflowException' occurred in System.Win

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KelvinNyota
    New Member
    • Nov 2015
    • 5

    An unhandled exception of type 'System.StackOverflowException' occurred in System.Win

    How do you resolve this problem in VB.NET? Press F1 to run the program. The dictionary can be found here:



    Here is the code:

    Code:
    Imports System.IO
    Imports System
    Imports System.Collections.Generic
    Public Class Form1
        Friend WithEvents RichTextBox1 As New RichTextBox With {.Dock = DockStyle.Fill}
        Friend WithEvents ReplaceMenu As New ContextMenuStrip
        Dim kamau As String
        Dim foundIndex As Integer
        Dim checkWord As String
        Dim replacementWords As List(Of String)()
        Private replacements As New Dictionary(Of String, List(Of String))
    
    
        Private nextCheckIndex As Integer
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Controls.Add(RichTextBox1)
    
    
            Using reader As New StreamReader("C:\Users\Acer\Desktop\Text Files\output10.txt")
                Do Until reader.EndOfStream
                    Dim parts = reader.ReadLine().Split("|"c)
    
                    If replacements.ContainsKey(parts(0)) Then
                        replacements(parts(0)).Add(parts(1))
                    Else
                        Dim newWordList As New List(Of String)
                        newWordList.Add(parts(1))
                        replacements.Add(parts(0), newWordList)
                    End If
    
    
                Loop
            End Using
    
    
    
    
            RichTextBox1.Text = "You gave a bad advice, irregardless of your intention. You provided a bad advice, irregardless of your intention. "
        End Sub
    
        Private Sub RichTextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyUp
            If e.KeyCode = Keys.F1 Then
                nextCheckIndex = 0
                CheckForReplacementText()
            End If
        End Sub
    
        Public Sub CheckForReplacementText()
    
            If nextCheckIndex = replacements.Count Then
    
                MessageBox.Show("Check complete.")
            Else
    
                checkWord = replacements.Keys.ElementAt(nextCheckIndex)
    
                foundIndex = RichTextBox1.Find(checkWord, 0, RichTextBox1.TextLength, RichTextBoxFinds.WholeWord)
           
    
            If foundIndex > -1 Then
    
                ReplaceMenu.Items.Clear()
    
                For Each replacement In replacements(checkWord)
                     ReplaceMenu.Items.Add(replacement, Nothing, Sub(sndr As Object, ea As EventArgs)
                                                                         RichTextBox1.SelectedText = kamau
                                                                         CheckForReplacementText()
                                                                     End Sub)
    
                    
                Next
                ReplaceMenu.Show(RichTextBox1, RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength))
            Else
                nextCheckIndex += 1
                CheckForReplacementText()
            End If
    
            End If
    
        End Sub
    
        Public Sub ReplaceMenu_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs) Handles ReplaceMenu.ItemClicked
    
            Dim checkWord = replacements.Keys.ElementAt(nextCheckIndex)
    
            For Each replacement In replacements(checkWord)
    
                replacement = e.ClickedItem.Text
                kamau = replacement
    
            Next
        End Sub
    
       
    End Class
Working...