如何使用VB6将文本文件加载到字符串中

CJ7*_*CJ7 0 string vb6 text-processing filesystemobject

如何使用VB6快速将文本文件加载到字符串中?

Aut*_*ira 9

这是在VB6中逐行加载整个文件的最快方法:

Function FileText (filename$) As String
    Dim handle As Integer
    handle = FreeFile
    Open filename$ For Input As #handle
    FileText = Input$(LOF(handle), handle)
    Close #handle
End Function
Run Code Online (Sandbox Code Playgroud)


CJ7*_*CJ7 5

Public Function ReadFileIntoString(strFilePath As String) As String

    Dim fso As New FileSystemObject
    Dim ts As TextStream

    Set ts = fso.OpenTextFile(strFilePath)
    ReadFileIntoString = ts.ReadAll

End Function 
Run Code Online (Sandbox Code Playgroud)

  • @SetSailMedia 不正确,这是 VB6。它需要引用“scrrun.dll”(“Microsoft Scripting Runtime”) (4认同)