vb中如何根据关键字读取txt 中包含关键字的那一行
比如说一个txt中有这样的内容:hj2_ghg.exe>|1/2|136408065|21:572007/October/09yu212.exe>|2/2|2767289...
比如说一个txt中有这样的内容:
hj2_ghg.exe>|1/2|136408065|21:57 2007/October/09
yu212.exe>|2/2|276728958|17:18 2009/January/25
比如当我在一个文本框中输入yu212.exe 就能把
yu212.exe>|2/2|276728958|17:18 2009/January/25
这一行都读出来? 展开
hj2_ghg.exe>|1/2|136408065|21:57 2007/October/09
yu212.exe>|2/2|276728958|17:18 2009/January/25
比如当我在一个文本框中输入yu212.exe 就能把
yu212.exe>|2/2|276728958|17:18 2009/January/25
这一行都读出来? 展开
1个回答
展开全部
Option Explicit
Dim arr
Private Sub Command1_Click()
Dim i As Long
For i = 0 To UBound(arr)
If InStr(arr(i), Text1) = 1 Then '查到就退出,可以装入数组
MsgBox arr(i)
Exit For
End If
Next
If i = UBound(arr) + 1 Then MsgBox "未查到:" & Text1
End Sub
Private Sub Form_Load()
If Dir("c:\1.txt") <> "" Then
Open "c:\1.txt" For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
Else
MsgBox "为找到文件:" & "c:\1.txt"
Unload Me
End If
Text1 = "yu212.exe"
End Sub
Dim arr
Private Sub Command1_Click()
Dim i As Long
For i = 0 To UBound(arr)
If InStr(arr(i), Text1) = 1 Then '查到就退出,可以装入数组
MsgBox arr(i)
Exit For
End If
Next
If i = UBound(arr) + 1 Then MsgBox "未查到:" & Text1
End Sub
Private Sub Form_Load()
If Dir("c:\1.txt") <> "" Then
Open "c:\1.txt" For Input As #1
arr = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbNewLine)
Close #1
Else
MsgBox "为找到文件:" & "c:\1.txt"
Unload Me
End If
Text1 = "yu212.exe"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询