Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading and Writing to .txt files

Status
Not open for further replies.

Edge118

Programmer
Jun 15, 2004
104
US
Does anyone know any "useful" sites that explain how to read(line by line) and write data to .txt files? My search came up empty.

Thanks.

"Pin me. Perl me."

Regards,

Chris
 
In my opinion, nothing beats the FileSystemObject.

Code:
Private Sub LoadFile(ByVal FileName As String)

    Dim FSO As Scripting.FileSystemObject
    Dim cAllData As String
    Dim arTemp() As String
    Dim i As Long
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    cAllData = FSO.GetFile(FileName).OpenAsTextStream(ForReading).ReadAll
    Set FSO = Nothing
    
    arTemp = Split(cAllData, vbCrLf)

    For i = LBound(arTemp) To UBound(arTemp)
        Debug.Pring arTemp(i)
    Next i


End Sub

Public Sub SaveFile(ByVal FileName As String, ByVal Data As String)
    
    Dim FSO As Scripting.FileSystemObject
    Dim cParentFolder As String
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    cParentFolder = FSO.GetParentFolderName(FileName)
    If Not FSO.FolderExists(cParentFolder) Then
        Call FSO.CreateFolder(cParentFolder)
    End If
    
    Call FSO.CreateTextFile(FileName, True).Write(Data)
    Set FSO = Nothing
    
End Sub



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
or you could use the FileSystemObject;-)


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top