Guys, what are the different ways of creating a sequential or text file? Thanks a lot!
Printable View
Guys, what are the different ways of creating a sequential or text file? Thanks a lot!
Example..
VB Code:
'Put data into File Dim Data As String Data = "Whatever" Open "C:\YourFile.txt" For Output As #1 Print#1, Data Close #1 'Get data from file Dim tmp As String Open "C:\YourFile.txt" For Input As #1 Do While Not EOF(1) Line Input#1, tmp Loop Close #1
Or, using File System Object (add reference to: Microsoft Scripting Runtime)
VB Code:
Dim Mfso As Scripting.FileSystemObject 'Should be declared modular Dim Tstr As TextStream Set Mfso = New Scripting.FileSystemObject Set Tstr = Mfso.CreateTextFile("C:\MyFile.txt", True) 'True = Overwrite Tstr.Write ("Hi!") Tstr.WriteBlankLines (1) Tstr.WriteLine ("How are you?") Tstr.Close Set Tstr = Nothing Set Mfso = Nothing 'Could be released when unloading form, not sure if its necessary