vb6 如何读取文件指定行内容

桌面有一文件123.txt,现在我想按command1后将两个空行下面的第一行文件放到text1中,按command2后将第一个两个空行和第二个两个空行之间的文件放到te... 桌面有一文件123.txt,现在我想按command1后将两个空行下面的第一行文件放到text1中,按command2后将第一个两个空行和第二个两个空行之间的文件放到text
2中,请问代码应该如何写?谢谢!
展开
 我来答
苏州老三石
推荐于2016-03-17 · TA获得超过1150个赞
知道小有建树答主
回答量:1300
采纳率:33%
帮助的人:940万
展开全部
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,还有,文件地址自己改一下
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式