Results 1 to 4 of 4

Thread: How can I put output an array into a text file?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Location
    I'm right here!
    Posts
    849

    Question How can I put output an array into a text file?

    hello,

    I have an array of strings, I want to put it in a text file so that in
    each line in the text file will be an item from the array.
    how can I do that?

    thanks

    Dekel C.

  2. #2
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016
    something like this
    VB Code:
    1. Dim i As Integer
    2.  
    3. Open "C:\test.txt" For Output As #1
    4.  For i = LBound(yourarray) To UBound(yourarray)
    5.   Print #1, yourarray(i)
    6.  Next i
    7. Close #1

    casey.

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    This would be faster:

    dim Lines() as string
    dim tmp as string

    open "C:\Your file.txt" for input as #1
    tmp=input$(lof(1),1)
    close #1

    lines=split(tmp,vbcrlf)
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,425
    If you using VB6, you can use 'Join' (which works with String Data Types) like:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Open App.Path & "\MyFile.txt" For Output As #1
    3.         Print #1, Join(strArr, vbCrLf)
    4.     Close #1
    5. End Sub
    (Three lines of code!)



    Bruce.
    Handy References:
    MSDN Library
    ADO Tutorial Excel Tutorial MZTools (VB6)

    • Please pull down the Thread Tools menu and click the 'Mark Thread Resolved' button, or alternately edit your original post and add "Resolved" or place a in the subject when your question(s) have been answered.
    • Please use code tags [highlight=vb] your code goes here between the tags [/highlight] when posting code.

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