vb6 如何读取文件指定行内容
桌面有一文件123.txt,现在我想按command1后将两个空行下面的第一行文件放到text1中,按command2后将第一个两个空行和第二个两个空行之间的文件放到te...
桌面有一文件123.txt,现在我想按command1后将两个空行下面的第一行文件放到text1中,按command2后将第一个两个空行和第二个两个空行之间的文件放到text
2中,请问代码应该如何写?谢谢! 展开
2中,请问代码应该如何写?谢谢! 展开
1个回答
展开全部
Private Sub command1_click()
Dim s1 As String
Dim s2 As String
Dim ss As String
Dim tem As String
Open "D:\123.txt" For Input As #1
Line Input #1, s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Line Input #1, tem
ss = tem
Exit Do
Else
s1 = tem
End If
Loop
Close #1
Text1.Text = ss
End Sub
Private Sub command2_click()
Dim s1 As String
Dim s2 As String
Dim ss As String
Dim tem As String
Open "D:\123.txt" For Input As #1
Line Input #1, s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Line Input #1, tem
ss = tem
Exit Do
Else
s1 = tem
End If
Loop
Line Input #1, tem
s1 = tem
ss = ss & Chr(13) + Chr(10) & s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Exit Do
Else
ss = ss & Chr(13) + Chr(10) & tem
s1 = tem
End If
Loop
Close #1
Text2.Text = ss
End Sub
注意:Text2点Multiline要设为true,还有,文件地址自己改一下
Dim s1 As String
Dim s2 As String
Dim ss As String
Dim tem As String
Open "D:\123.txt" For Input As #1
Line Input #1, s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Line Input #1, tem
ss = tem
Exit Do
Else
s1 = tem
End If
Loop
Close #1
Text1.Text = ss
End Sub
Private Sub command2_click()
Dim s1 As String
Dim s2 As String
Dim ss As String
Dim tem As String
Open "D:\123.txt" For Input As #1
Line Input #1, s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Line Input #1, tem
ss = tem
Exit Do
Else
s1 = tem
End If
Loop
Line Input #1, tem
s1 = tem
ss = ss & Chr(13) + Chr(10) & s1
Do While Not EOF(1)
Line Input #1, tem
If tem = "" And s1 = "" Then
Exit Do
Else
ss = ss & Chr(13) + Chr(10) & tem
s1 = tem
End If
Loop
Close #1
Text2.Text = ss
End Sub
注意:Text2点Multiline要设为true,还有,文件地址自己改一下
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询