Results 1 to 6 of 6

Thread: text files always get me...

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    text files always get me...

    I always hate doing this and I always forget how. I promise to write it down this time...

    I want to create a text file in say C:\ and write records to it from a database.

    While not rs.eof
    Write to text file
    rs.movenext
    wend

    I want to make sure the line in the text file has a carriage return for the next record

    How do I do this simple darn process.
    Dont forget to show me how to clean up resources
    I love you guys

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    VB Code:
    1. Dim iHandle as Integer
    2. iHandle = FreeFile
    3. Open "C:\MyFile.txt" for Output as #iHandle
    4. Do Until RS.EOF
    5.     Write #iHandle, RS("ID") & "," & RS("Name")
    6.     RS.MoveNext
    7. Loop
    8. Close #iHandle

    assuming RS is already been opened (and closed after the loop)

    You can use Write or Print in that line
    Print writes the data exactly, and Write prints the data with quotes around it (good if you want to read in data later)

    also I just wrote this.. didnt test so if it comes up with any errors, just let me know

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Open "C:\filename.txt" for output as #1
    Do while not rs.EOF
    tmp = ""
    For x = 0 to rs.fields.count -1
    tmp = tmp & " " & rs.fields(x) 'put a delimiter in there?
    next
    Print #1, tmp
    rs.movenext
    Loop
    Close #1
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    kleinma! to quick on the draw!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    haha, yeah, but nice loop for the RS fields

  6. #6

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    Shanks folks.

    Jon

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