By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,757 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,757 IT Pros & Developers. It's quick & easy.

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

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

https://docs.google.com/document/d/1...it?usp=sharing

Here is the code:

Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System
  3. Imports System.Collections.Generic
  4. Public Class Form1
  5.     Friend WithEvents RichTextBox1 As New RichTextBox With {.Dock = DockStyle.Fill}
  6.     Friend WithEvents ReplaceMenu As New ContextMenuStrip
  7.     Dim kamau As String
  8.     Dim foundIndex As Integer
  9.     Dim checkWord As String
  10.     Dim replacementWords As List(Of String)()
  11.     Private replacements As New Dictionary(Of String, List(Of String))
  12.  
  13.  
  14.     Private nextCheckIndex As Integer
  15.  
  16.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  17.         Controls.Add(RichTextBox1)
  18.  
  19.  
  20.         Using reader As New StreamReader("C:\Users\Acer\Desktop\Text Files\output10.txt")
  21.             Do Until reader.EndOfStream
  22.                 Dim parts = reader.ReadLine().Split("|"c)
  23.  
  24.                 If replacements.ContainsKey(parts(0)) Then
  25.                     replacements(parts(0)).Add(parts(1))
  26.                 Else
  27.                     Dim newWordList As New List(Of String)
  28.                     newWordList.Add(parts(1))
  29.                     replacements.Add(parts(0), newWordList)
  30.                 End If
  31.  
  32.  
  33.             Loop
  34.         End Using
  35.  
  36.  
  37.  
  38.  
  39.         RichTextBox1.Text = "You gave a bad advice, irregardless of your intention. You provided a bad advice, irregardless of your intention. "
  40.     End Sub
  41.  
  42.     Private Sub RichTextBox1_KeyUp(sender As Object, e As KeyEventArgs) Handles RichTextBox1.KeyUp
  43.         If e.KeyCode = Keys.F1 Then
  44.             nextCheckIndex = 0
  45.             CheckForReplacementText()
  46.         End If
  47.     End Sub
  48.  
  49.     Public Sub CheckForReplacementText()
  50.  
  51.         If nextCheckIndex = replacements.Count Then
  52.  
  53.             MessageBox.Show("Check complete.")
  54.         Else
  55.  
  56.             checkWord = replacements.Keys.ElementAt(nextCheckIndex)
  57.  
  58.             foundIndex = RichTextBox1.Find(checkWord, 0, RichTextBox1.TextLength, RichTextBoxFinds.WholeWord)
  59.  
  60.  
  61.         If foundIndex > -1 Then
  62.  
  63.             ReplaceMenu.Items.Clear()
  64.  
  65.             For Each replacement In replacements(checkWord)
  66.                  ReplaceMenu.Items.Add(replacement, Nothing, Sub(sndr As Object, ea As EventArgs)
  67.                                                                      RichTextBox1.SelectedText = kamau
  68.                                                                      CheckForReplacementText()
  69.                                                                  End Sub)
  70.  
  71.  
  72.             Next
  73.             ReplaceMenu.Show(RichTextBox1, RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength))
  74.         Else
  75.             nextCheckIndex += 1
  76.             CheckForReplacementText()
  77.         End If
  78.  
  79.         End If
  80.  
  81.     End Sub
  82.  
  83.     Public Sub ReplaceMenu_ItemClicked(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs) Handles ReplaceMenu.ItemClicked
  84.  
  85.         Dim checkWord = replacements.Keys.ElementAt(nextCheckIndex)
  86.  
  87.         For Each replacement In replacements(checkWord)
  88.  
  89.             replacement = e.ClickedItem.Text
  90.             kamau = replacement
  91.  
  92.         Next
  93.     End Sub
  94.  
  95.  
  96. End Class
  97.  
Dec 17 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.

Browse more Visual Basic .NET Questions on Bytes