关于VB读取文本的第几行

来源:百度知道 编辑:UC知道 时间:2024/05/28 13:05:35
Private Sub Command1_Click()
Open "f:\新建 文本文档 .inf" For Input As #1 '(打开文件,方式是读取)
Line Input #1, s '(读取第一行)
Text1.Text = s
Close #1 '('关闭文件)
End Sub

上面这个代码是读取第1行 请问 要如何修改 才能让他 读取第2行?

Private Sub Command1_Click()
Open "f:\新建 文本文档 .inf" For Input As #1 '(打开文件,方式是读取)
for i=1 to n
Line Input #1, s '(读取第一行)
next i
Text1.Text = s
Close #1 '('关闭文件)
End Sub
这里n取几,text1里显示的就是第几行。

下边的代码返回了文本文件的所有行,你参考一下

'***************************************************************
'读文件返回字符串函数
Private Function ReadFile(filePath As String) As String
Dim fileStr As String
Open filePath For Input As #1

Do While Not EOF(1)
Line Input #1, tem
fileStr = fileStr & tem & vbCrLf
Loop
Close #1
ReadFile = fileStr
End Function
'***************************************************************

private sub command1_click()
dim str() as string
str=split(readfile("f:\新建 文本文档 .inf"),vbcrlf)
print "文本总行数为:" & ubound(str)+1 & "行"
for i=0 to ubound(str)
print "第"