Re: [VB6 ] 如何不用回圈讀文字檔

看板Visual_Basic作者 (a9)時間16年前 (2008/07/06 23:53), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #18SEfvP9 (Visual_Basic)
文章代碼(AID): #18SEfvP9 (Visual_Basic)