VB文本查找问题

来源:百度知道 编辑:UC知道 时间:2024/06/27 09:58:03
文本放在1.txt中
要求:在程序的编辑框中输入需要查找的文字如:1
于是连接1.txt里的数据进行查找,把所有符合条件的文字所在的那一行都弄到编辑框2中
记住是所有符合条件文字的那一行!
谢谢50分拿走!!
又如查找:123
查到:
123456
654123
1233333
65412333
反正是所有符合条件的那一行!

3个文本框,1个按钮
text1中是文本,text2显示结果,text3需要查找的文字

Private Sub Command1_Click()

Dim p As Long, s As Long
Dim L As String

p = -1

Do While True

s = p + 2
p = InStr(s + 1, Text1.Text, vbCrLf)

If p = 0 Then
Text1.SelStart = s - 1
Text1.SelLength = Len(Text1.Text) - s + 1
Else
Text1.SelStart = s - 1
Text1.SelLength = p - s + 1
End If

If InStr(1, Text1.SelText, Text3.Text) > 0 Then

If Text2.Text = "" Then
Text2.Text = Text1.SelText
Else
Text2.Text = Text2.Text & vbCrLf & Text1.SelText
End If

End If

If p = 0 Then Exit Do
Loop

End Sub

'Text2的MultiLine属性要设置成True,ScrollBars属性赋值为3,该控件初始化时,调节出足够的高度

Private Sub Command1_Click()
Dim s As String, txtLine As String
s = Text1.Text
Text2.Text = ""
Open "1.txt" For