Re: [VB6 ] 如何不用回圈讀文字檔
※ 引述《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)
推
07/07 08:32, , 1F
07/07 08:32, 1F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):