Results 1 to 2 of 2

Thread: [RESOLVED] Ways to Create a Text File

  1. #1

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Resolved [RESOLVED] Ways to Create a Text File

    Guys, what are the different ways of creating a sequential or text file? Thanks a lot!

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: Ways to Create a Text File

    Example..
    VB Code:
    1. 'Put data into File
    2. Dim Data As String
    3. Data = "Whatever"
    4. Open "C:\YourFile.txt" For Output As #1
    5.     Print#1, Data
    6. Close #1
    7.  
    8. 'Get data from file
    9. Dim tmp As String
    10. Open "C:\YourFile.txt" For Input As #1
    11.     Do While Not EOF(1)
    12.         Line Input#1, tmp
    13.     Loop
    14. Close #1

    Or, using File System Object (add reference to: Microsoft Scripting Runtime)
    VB Code:
    1. Dim Mfso As Scripting.FileSystemObject 'Should be declared modular
    2. Dim Tstr As TextStream
    3.  
    4.     Set Mfso = New Scripting.FileSystemObject
    5.     Set Tstr = Mfso.CreateTextFile("C:\MyFile.txt", True) 'True = Overwrite
    6.     Tstr.Write ("Hi!")
    7.     Tstr.WriteBlankLines (1)
    8.     Tstr.WriteLine ("How are you?")
    9.     Tstr.Close
    10.     Set Tstr = Nothing
    11.     Set Mfso = Nothing 'Could be released when unloading form, not sure if its necessary
    Last edited by jcis; Dec 3rd, 2005 at 06:11 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width