求一段vb代码(简单读写文件)

来源:百度知道 编辑:UC知道 时间:2024/07/07 10:28:11
读c:\test.txt,然后按条件写到另一个文件。条件:把文件中good morning和glad to meet you之间的数据照写不误。其他的省略掉,不写到新文件中。
请各位一定要帮个忙啊。vb扔下好长时间,都忘光了。

Private Sub Form_click()
Dim str1 As String, temp As String, x As Integer, y As Integer
Open "z:\test.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, temp
str1 = str1 & temp & vbCrLf
Loop
Close #1
x = InStr(1, str1, "good morning")
y = InStr(1, str1, "glad to meet you")
If x > 0 And y > 0 And y > x Then
Print Mid(str1, x + Len("good morning"), y - x - Len("good morning"))
ElseIf x > 0 And y > 0 And x > y Then
Print Mid(str1, y + Len("glad to meet you"), x - y - Len("glad to meet you"))
End If
End Sub