作者a9 (a9)
看板Visual_Basic
标题Re: [VB6 ] 如何不用回圈读文字档
时间Sun Jul 6 23:53:28 2008
※ 引述《ClubT (We will Wii)》之铭言:
: 如果我现在要一次把整个文字档读入
: 都是用回圈一次读一行
: 有没有方法可以一次读全部
: 我有在网路上找到下面这个例子
: txtContent.Text = "" '清除内容
: Open sFile$ For Input As #1 '开启文字档
: txtContent.Text = StrConv(InputB(LOF(F), #1), vbUnicode) '一次读入整个档案
: Close #1 '关闭档案
: 但是不知道这是不是VB6的
: 如果是的话档名是应该放在sFile$吗?
: THANKS^^
把文字档当 Binary 读,就能一次读全部
Function TextReadAll(ByVal sFile As String) As String
If sFile = Empty Or Len(Dir$(sFile)) = 0 Then
Exit Function
End If
Dim Buff As String
Dim f As Integer
f = FreeFile
Open sFile For Binary As #f
Buff = Space(LOF(f))
Get #f, , Buff
Close #1
TextReadAll = Buff
End Function
要使用的话只要
Result = TextReadAll(档名)
ex.
Text1 = TextReadAll(App.Path & "\Data.txt")
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 163.26.228.44
※ 编辑: a9 来自: 163.26.228.44 (07/07 00:20)
1F:推 ClubT:谢啦^^ 07/07 08:32