Results 1 to 4 of 4

Thread: [2005] Write a list to a text file

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    [2005] Write a list to a text file

    Code:
    ' total is a list
    Dim string_array() As String
            string_array = DirectCast(total.ToArray(GetType(String)), String())
            File.AppendAllText("c:\test.txt", string_array)
    Need help.
    Thanks.

  2. #2
    Addicted Member
    Join Date
    Apr 2006
    Posts
    137

    Re: [2005] Write a list to a text file

    Try this

    vb Code:
    1. 'open stream writer
    2.             Dim objsw As New System.IO.StreamWriter("yourfile.txt")
    3.             Dim string_array() As String
    4.             Dim i As Integer = 0
    5.             'write array elements one per line
    6.             Do Until i = string_array.Length - 1
    7.                 objsw.WriteLine(string_array(i))
    8.                 'increment
    9.                 i += 1
    10.             Loop
    11.             'close stream
    12.             objsw.Close()

    Hope it helps!
    Jesse Bunch
    www.getbunch.com/
    If I have helped you, please rate my posts!

    Unless otherwise indicated, I am using the following Products:

    Visual Studio .NET 2010
    .NET Framework 4.0

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Re: [2005] Write a list to a text file

    I don't know why I get an error if I use Direcast
    Code:
    Overload resolution failed because no accessible 'ToArray' accepts this number of arguments.
    Code:
    string_array = DirectCast(total.ToArray(GetType(String)), String())

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    470

    Re: [2005] Write a list to a text file

    Okay. Ignore "DireCast(...)".

    But only last row is wroten to the file.

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