有一个文本框里面有内容
点击窗体时候 弹出对话框输入要查找的字符
点击确定按钮  文本框被找到的字符被涂黑显示
若文本框没有被找到的字符  则弹出对话框提示 没找到
我写了一段代码 但是实现不了这个功能
请高手帮忙
如果使用了instr函数,请一定要解释一下,谢谢!

解决方案 »

  1.   

    代码很简单,不给你写注释了!
    使用了RichTextBox1控件
    microsoft rich textbox control6.0Private Sub Command1_Click()
       Dim strInput         As String
       Dim strRichBox       As String
       Dim intPosition      As Integer
       strRichBox = RichTextBox1.Text
       strInput = InputBox("Please Input KeyWord", "Input")
       If strInput = vbNullString Then
            Call MsgBox(" Input Value is Null")
            Exit Sub
            
       End If
       
       intPosition = InStr(1, strRichBox, strInput)
       If intPosition = 0 Then Call MsgBox(" Not Anly String")
       
       Do While intPosition <> 0
           With RichTextBox1
            .SelStart = intPosition - 1
            .SelLength = Len(strInput)
            .SelColor = vbRed
           End With
           
           intPosition = intPosition + Len(strInput)
           If intPosition >= Len(strRichBox) Then Exit Do
           intPosition = InStr(intPosition, strRichBox, strInput)
       Loop
     
    End Sub