五一七教育网
您的当前位置:首页VB读取文本文件的某一行

VB读取文本文件的某一行

来源:五一七教育网


Function lines(txtpath As String, ByVal startline As Integer, linenum As Integer) As String '显示 txtpath 文件的从startline 行开始的 linenum 行的内容

lines = \"\"

Dim filetxt As String, x As Variant, i As filetxt = String(FileLen(txtpath), \" \")

Open txtpath For Binary As 1

Get #1, , filetxt

Close 1

x = Split(filetxt, vbCrLf)

msgbox ubound(x)+1 '行数

If startline > UBound(x) Then MsgBox \"err!\": Exit Function

If startline <= UBound(x) Then

If startline + linenum <= UBound(x) Then Integer \"行溢出\

,

For i = startline To startline + linenum - 1

lines = lines & x(i) & \" \"

Next

Else

For i = startline lines = lines & Next

End If: End If

End Function

To UBound(x)

x(i) & \" \"

因篇幅问题不能全部显示,请点此查看更多更全内容