请教如何知道一个文本文件有多少行,或读取指定行的内容

Boible 2003-09-30 10:11:48
如题。

...全文
159 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
pigpag 2003-10-01
  • 打赏
  • 举报
回复
试试FileSystemObject

Dim K As New FileSystemObject, L As TextStream
Set L = K.OpenTextFile("C:\WINDOWS\upgrade.txt")
Do Until L.AtEndOfStream
L.SkipLine
Loop
MsgBox L.Line-1
踏平扶桑 2003-10-01
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2250/2250384.xml?temp=.6102869
flc 2003-10-01
  • 打赏
  • 举报
回复
学习
laihongbo524 2003-10-01
  • 打赏
  • 举报
回复
Dim Lines, chars As String
Dim blah() As String
Dim bleh() As String
Dim Curline As String
Dim CurChar, TotalChar As String
Curline = Mid(Text1.Text, 1, Text1.SelStart)
blah() = Split(Curline, Chr$(10))
bleh() = Split(Text1.Text, Chr$(10))
If Text1.SelStart = 0 Then
CurChar = 0
Curline = 1
If Len(Text1.Text) = 0 Then
TotalChar = 0
Else
TotalChar = Len(Text1.Text) - (UBound(bleh) * 2)
End If
Else
CurChar = Text1.SelStart - (UBound(blah) * 2)
Curline = UBound(blah) + 1
TotalChar = Len(Text1.Text) - (UBound(bleh) * 2)
End If
Lines = "行数:第 " & Curline & " 行/共 " & SendMessage(Text1.hWnd, EM_GETLINECOUNT, ByVal 0&, ByVal 0&) & " 行"
chars = "字节:第 " & CurChar & " 字节/共 " & TotalChar & " 字节"
sb2.SimpleText = chars & " " & Lines
jiazhuo 2003-10-01
  • 打赏
  • 举报
回复
up
rainstormmaster 2003-10-01
  • 打赏
  • 举报
回复
要想加快速度,应以数据库方式操作文本文件,注意配置好ini文件
Boible 2003-09-30
  • 打赏
  • 举报
回复
以上两位,对不起,这样做是不是太慢了呢,特别是第二种方法,我已经用过了,文件一大就太慢了,我观察人家的程序,要显示出行数来是很快的
kmzs 2003-09-30
  • 打赏
  • 举报
回复
dim stra as string,al as long
open "..." for input as #1
al=1
while not eof(1)
line input #1,stra '?line input stra,#1
al=al+1
wend
stra=""
close #1
al为行数
rainstormmaster 2003-09-30
  • 打赏
  • 举报
回复
手写的,可能有错:

dim mbyte() as byte
dim mlen as long
dim filename as string
filename="c:\test.txt"
mlen=filelen(filename)
redim mbyte(mlen-1)
open filename for binary as #1
get #1,,mbyte
close #1
dim s as string
s=strconv(mbyte,vbunicode)
dim arr
arr=split(s,vbcrlf)
'文件行数为mline+1
dim mline as long
mline=ubound(arr)
'第n行的内容为,arr(n-1)
dim linestr as string
linestr=arr(5)

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧