设计一个查找程序,运行时在文本框text1中输入要查找的内容,单击"开始查找"按钮开始在文本框text2中查找,找到时,将找到的内容选中,text2中是一段文字。在线等!!!

解决方案 »

  1.   

    Private Sub Command1_Click()    Dim pos As Long
        Static POS1
        If Check1.Value = 1 Then
            pos = InStr(POS1 + 1, frmTips.Text1.Text, txtKey.Text, vbBinaryCompare)
        Else
            pos = InStr(POS1 + 1, frmTips.Text1.Text, txtKey.Text, vbTextCompare)
        End If
        POS1 = pos
        If pos > 0 Then
            If pos > 450 Then
                Me.Top = frmTips.Top + 1500
            Else
                Me.Top = frmTips.Top + 4500
            End If
            frmTips.Show
            frmTips.Text1.SelStart = pos - 1
            frmTips.Text1.SelLength = Len(txtKey.Text)
            frmTips.Text1.SetFocus
        Else
         MsgBox "Nothing else found!"
        End If
        
    End Sub
      

  2.   


        If InStr(Text2, Text1) > 0 Then
            Text2.SetFocus
            Text2.SelStart = InStr(Text2, Text1) - 1
            Text2.SelLength = Len(Text1)
          Else
            MsgBox "没找到", vbInformation
        End If
      

  3.   

    Private Sub Command1_Click()
    s = InStr(Text2.Text, Text1.Text)
    If s Then Text2.SelStart = s - 1: Text2.SelLength = Len(Text1): Text2.SetFocus
    End Sub