vb读取文本文件的问题,请高手指点!谢谢

zhangy_0221 2004-01-09 09:35:31
想用vb打开一文本文件,逐行读出每一行
以下代码有什么问题,请指教:
set fso=createobfect("scripting.filesystemobject")
set ts=fso.opentextfile("c:\1.text")
do while not ts.eof
msgbox ts.readline
loop
do while not ts.eof这里老报错,说对象不支持的属性或方法,究竟判断文件结束的eof应该怎么使用啊?请指点,谢谢!
...全文
97 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhjjhjhj 2004-01-10
  • 打赏
  • 举报
回复
Do While Not ts.AtEndOfStream
MsgBox ts.readline
ts.skipline
Loop
windsandy 2004-01-10
  • 打赏
  • 举报
回复
引用 m Scripting runtime
Dim cxbl As String
Dim fso As FileSystemObject
Dim fil As TextStream
Const ForWriting = 8
Dim vstring As String
cxbl="c:\1.text"
Set fso = New Scripting.FileSystemObject
Set fil = fso.OpenTextFile(cxbl, ForReading, True)
Do While Not fil.AtEndOfStream
vstring = fil.ReadLine
loop
fil.close
rocketliu8899 2004-01-10
  • 打赏
  • 举报
回复
hao ,xuyao
windsandy 2004-01-10
  • 打赏
  • 举报
回复
引用 m Scripting runtime
Dim cxbl As String
Dim fso As FileSystemObject
Dim fil As TextStream
Const ForWriting = 8
Dim vstring As String
Set fso = New Scripting.FileSystemObject
Do While Not fil.AtEndOfStream
vstring = fil.ReadLine
loop
fil.close
zhangy_0221 2004-01-09
  • 打赏
  • 举报
回复
Do While Not ts.AtEndOfStream
MsgBox ts.readline
Loop
我试过,好象只能读出第一行,其它行不行也
我要读的文件很大了,有10m多的,原来我做过一个,可以的,不小心把原程序删了,只有exe文件在了,这次要做的功能上有所差异,但读文本文件这里是一样的,我记不到当时怎么用的了,痛苦啊!求到家帮帮忙啊,详细指点下.
firechun 2004-01-09
  • 打赏
  • 举报
回复
判断是否到文件的结尾,用atendofstream,不是EOF
northwolves 2004-01-09
  • 打赏
  • 举报
回复
fso可以这样用:

Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.opentextfile("c:\1.txt")
Do While Not ts.AtEndOfStream
MsgBox ts.readline
Loop
End Sub
lingll 2004-01-09
  • 打赏
  • 举报
回复
最好的方式还是binary
xueyi0008 2004-01-09
  • 打赏
  • 举报
回复
do while not ts.eof


我不是很清楚
但我知道如果你使用工作区打开的

open "c:\1.txt" for input as #1

do while not eof(1)
.............
loop

close #1

但是这种读取方式要求文件不能大于64k的


希望能对你所帮助

7,763

社区成员

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

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