2011-11-04 82 views
1

我已经完成的搜索功能正在工作,但它只能找到一次单词,我有困难的是,我不能让搜索功能来阅读整个文本框,并找到所有在搜索文本框中输入的词我如何搜索文本框中的视觉基本文本

Private Sub btnSearch_Click(ByVal sender As System.Object, _ 
    ByVal e As System.EventArgs) Handles btnSearch.Click 
    Dim Search As String 
    Dim Where As Long 

    ' Get search string from user. 
    Search = InputBox("Enter text to be found:") 

    ' Find string in text. 
    Where = InStr(TheText.Text, Search) 

    If Where <> 0 Then 
    TheText.Focus() 
    TheText.SelectionStart = Where - 1 
    TheText.SelectionLength = Len(Search) 
    Else 
    MsgBox("String not found.") 
    End If 

    txtR.Text = CountWords(Search) 

    Sorting.Items.Add(txtR.Text) 
End Sub 

回答

0

文本框控件不允许多个选择,但Rich Textbox控件确实如此。它本质上与您拥有的代码相同,但您需要一个位置号来跟踪最近的查找和循环,直到没有更多搜索字符串实例。