Friday, July 30, 2010

To get File Contents / read file on VB 6

When i develop some application, i need to read file contents. And this code will help you to create it.

Public Function GetFileContents(ByVal FullPath As String) As String
        Dim strContents As String
        Dim fso As FileSystemObject
        Dim ts As TextStream
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        strContents = ""
        If fso.FileExists(FullPath) Then
            Set ts = fso.OpenTextFile(FullPath)
            Do Until ts.AtEndOfStream
             strContents = strContents + ts.ReadLine + vbCrLf
            Loop
                  
            ts.Close
        End If
        GetFileContents = strContents
    End Function







Have a nice days.






No comments:

Hukum Tabur Tuai

Ingatlah hukum dasar ini, dalam kehidupanmu  Barang siapa yang menanam, dia pula yang akan menuai