2016-01-23 195 views
0

這裏是我的代碼,我正在尋找一種不同的方式來訪問一個字典,這是一個替代這個因爲一個stackoverflow。儘管調試和設置斷點,但無法找到錯誤。當我用
昏暗教育作爲新詞典的詞典(字符串列表(字符串))訪問字典的另一種方法

效果很不錯,但是這一次是給我的問題。你有什麼建議?

 checkWord = replacements.Keys.ElementAt(nextCheckIndex) 

     foundIndex = RichTextBox1.Find(checkWord, 0, RichTextBoxFinds.WholeWord) 
     If foundIndex > -1 Then 
      ContextMenuStrip1.Items.Clear() 
      For Each replacement In replacements(checkWord) 
+0

什麼錯誤,你在說什麼?你有什麼問題?我不是一個心靈讀者,我沒有一個水晶球來看你的屏幕。請你應該精確地解釋你的錯誤,上面的代碼中沒有任何內容似乎是錯誤的。 – Steve

+0

@steve。我在這裏得到了一個stackoverflow:** foundIndex = RichTextBox1.Find(checkWord,0,RichTextBoxFinds.WholeWord)** –

+0

_checkWord_的值是什麼?你確定這個單詞出現在richtextbox文本中嗎?沒有理由使用Find查找StackOverflow異常。嘗試使用調試器,並在達到異常之前檢查變量的值。順便問一下,你確定這個異常是StackOverflowException,而不是來自前一行(ElementAt .....) – Steve

回答

0
Private Sub CheckForReplacementText() 

    Dim foundIndex As Integer = 0 
    Dim start As Integer = 0 

    Try 
     For Each checkWord In replacements.Keys 

      foundIndex = RichTextBox1.Find(checkWord, start, RichTextBoxFinds.WholeWord) 
      If foundIndex > -1 Then 
       ContextMenuStrip1.Items.Clear() 
       For Each replacement In replacements(checkWord) 

        ContextMenuStrip1.Items.Add(replacement, Nothing, Sub(sndr As Object, ea As EventArgs) 
                    RichTextBox1.SelectedText = GetWordWithOutBracketedText(kamau) 
                   End Sub) 

        ContextMenuStrip1.Show(RichTextBox1, RichTextBox1.GetPositionFromCharIndex(RichTextBox1.SelectionStart + RichTextBox1.SelectionLength)) 
       Next 
      End If 
     Next 

    Catch e As Exception 
     MessageBox.Show(e.ToString) 
    End Try 
End Sub 
+0

額外下一個不應該在那裏,但爲了更正。謝謝。但是當你在這裏刪除這部分時,它不顯示上下文菜單:'Else nextCheckIndex = nextCheckIndex + 1 CheckForReplacementText() End If'你能幫我嗎?這就好像該部分對於運行該程序非常重要。 –

相關問題