writing text to text files in vb. need help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?am9obmFicmFoYW0xMDE=?=

    #1

    writing text to text files in vb. need help

    hello all,
    I've already posted a thread with the same problem but
    couldn't satisfactory answer. Let's come to the point.

    I can write some text to a text file with WriteAllText method. How can I
    start new lines? Example, c:\test.txt is a file, then:

    "This text should be written in 1st line of c:\test.txt"
    "This text should be written in 2nd line of c:\test.txt"

    Please write a that demonstrate the above task.

    bye






  • Robert Dufour

    #2
    Re: writing text to text files in vb. need help

    Dim MyLine as string
    MyLine = "this is line 1" & vbcrlf
    however you do append this line to your open text file, next
    Myline = "this is line 2" & vbcrlf
    however you do append this line to your open text file, next
    and so on
    HTH
    "johnabraham101 " <johnabraham101 @discussions.mi crosoft.comwrot e in message
    news:56861051-9598-40B4-BA85-C3F124293AE1@mi crosoft.com...
    hello all,
    I've already posted a thread with the same problem but
    couldn't satisfactory answer. Let's come to the point.
    >
    I can write some text to a text file with WriteAllText method. How can I
    start new lines? Example, c:\test.txt is a file, then:
    >
    "This text should be written in 1st line of c:\test.txt"
    "This text should be written in 2nd line of c:\test.txt"
    >
    Please write a that demonstrate the above task.
    >
    bye
    >
    >
    >
    >
    >
    >

    Comment

    • Armin Zingler

      #3
      Re: writing text to text files in vb. need help

      "johnabraham101 " <johnabraham101 @discussions.mi crosoft.comschr ieb
      hello all,
      I've already posted a thread with the same problem
      but couldn't satisfactory answer. Let's come to the point.
      >
      I can write some text to a text file with WriteAllText method. How
      can I start new lines? Example, c:\test.txt is a file, then:
      >
      "This text should be written in 1st line of c:\test.txt"
      "This text should be written in 2nd line of c:\test.txt"
      >
      Please write a that demonstrate the above task.
      >
      bye

      http://msdn2.microsoft.com/en-us/library/k3352a4t.aspx

      Especially, if "new lines" means appending to a file:
      http://msdn2.microsoft.com/en-us/library/3zc0w663.aspx

      Also:
      http://msdn2.microsoft.com/en-us/lib...b6(VS.71).aspx


      Armin

      Comment

      • Phill W.

        #4
        Re: writing text to text files in vb. need help

        johnabraham101 wrote:
        I've already posted a thread with the same problem but
        couldn't satisfactory answer. Let's come to the point.
        >
        I can write some text to a text file with WriteAllText method.
        Short answer - Environment.New Line will add a line break into your file.

        Longer answer -

        WriteAllText() is what I call a "convenienc e method"; it wraps up lots
        of other stuff and, so long as it does everything the way you want, all
        well and good.
        However, I suspect you're reaching a point where it's /not quite/
        fitting your requirements any more and you need something else.

        Here's another way ...

        Dim sw as New StreamWriter( "file", False )

        sw.WriteLine( "This text should be written in 1st line of c:\test.txt" )
        sw.WriteLine( "This text should be written in 2nd line of c:\test.txt" )

        sw.Close()

        The StreamWriter class sports other useful methods that may help you in
        your file creation as well, for example:

        Dim sw as New StreamWriter( "file", False )

        For iSub as Integer = 1 to 10
        sw.Write( "Line " )
        sw.Write( iSub.ToString() )
        sw.WriteLine( " of 10" )
        Next
        sw.Close()

        HTH,
        Phill W.

        Comment

        Working...