Outputting text to a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ash Phillips

    Outputting text to a file

    Ok, I'm not sure how I can explain this but here goes.

    I have this program that uses a ListView for entries. What I have the
    program doing is taking all the items from the listview, and writing them to
    an HTML document.

    Well what I did in VB6 was get all the info from the listview in a loop
    routine and write the HTML into a text box. When that was completed I then
    exported all the text from that text box to an html file.

    In VB .NET however, I have a problem where (I think, but am not 100% sure)
    all the HTML code can't fit into a text box so I can export it to a file.

    Is there any way I can open the file and just keep writing lines of text to
    the file instead of doing it to a textbox then to a file?

    Hope that made sense :\

    Thanks in advance,
    Ash


  • Fabricio

    #2
    RE: Outputting text to a file

    Try using a System.IO.Strea mWriter, like so:

    -------------------------------------------------------------
    Dim sw as System.IO.Strea mWriter;

    sw = new System.IO.Strea mWriter("output .txt")

    sw.WriteLine("A dd this to file.")
    sw.WriteLine("A lso add this.")
    sw.WriteLine("F inally, add this as well!")

    sw.Close()
    -------------------------------------------------------------

    "Ash Phillips" wrote:
    [color=blue]
    > Ok, I'm not sure how I can explain this but here goes.
    >
    > I have this program that uses a ListView for entries. What I have the
    > program doing is taking all the items from the listview, and writing them to
    > an HTML document.
    >
    > Well what I did in VB6 was get all the info from the listview in a loop
    > routine and write the HTML into a text box. When that was completed I then
    > exported all the text from that text box to an html file.
    >
    > In VB .NET however, I have a problem where (I think, but am not 100% sure)
    > all the HTML code can't fit into a text box so I can export it to a file.
    >
    > Is there any way I can open the file and just keep writing lines of text to
    > the file instead of doing it to a textbox then to a file?
    >
    > Hope that made sense :\
    >
    > Thanks in advance,
    > Ash
    >
    >
    >[/color]

    Comment

    • Cor Ligthert

      #3
      Re: Outputting text to a file

      Ash,

      I don't see your problem as you do it as now. (Your textbox has than to be
      in the multiline status, what is in fact a kind of different approach of the
      textbox than the single line because it has vbcrlf at the end of a line)

      However I don't see the reason why you bring it first to a textbox.
      This should go in the loop direct as well.

      And when you change it use than directly that streamwriter as Fabricio shows
      you.

      I hope this helps?

      Cor


      Comment

      • Jorge Serrano [MVP VB]

        #4
        RE: Outputting text to a file

        Hi Ash,

        in VB.NET you can do it identical.
        You have to use a loop taking the values inside of listbox and write line
        per line into the html file.

        Kind Regards,

        Jorge Serrano Pérez
        MVP VB.NET


        "Ash Phillips" wrote:
        [color=blue]
        > Ok, I'm not sure how I can explain this but here goes.
        >
        > I have this program that uses a ListView for entries. What I have the
        > program doing is taking all the items from the listview, and writing them to
        > an HTML document.
        >
        > Well what I did in VB6 was get all the info from the listview in a loop
        > routine and write the HTML into a text box. When that was completed I then
        > exported all the text from that text box to an html file.
        >
        > In VB .NET however, I have a problem where (I think, but am not 100% sure)
        > all the HTML code can't fit into a text box so I can export it to a file.
        >
        > Is there any way I can open the file and just keep writing lines of text to
        > the file instead of doing it to a textbox then to a file?
        >
        > Hope that made sense :\
        >
        > Thanks in advance,
        > Ash
        >
        >
        >[/color]

        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: Outputting text to a file

          Ash,

          "Ash Phillips" <ash@expwin.net > schrieb:[color=blue]
          > Is there any way I can open the file and just keep writing lines of text
          > to
          > the file instead of doing it to a textbox then to a file?[/color]

          File Access with Visual Basic Run-Time Functions:

          Visual Basic Language Concepts -- File Access with Visual Basic Run-Time
          Functions
          <URL:http://msdn.microsoft. com/library/en-us/vbcn7/html/vbconProcessing Files.asp>

          - or -

          ..NET Framework Class Library -- 'FileStream' Class
          <URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfSystemIOFi leStreamClassTo pic.asp>

          ..NET Framework Class Library -- 'StreamWriter' Class
          <URL:http://msdn.microsoft. com/library/en-us/cpref/html/frlrfsystemiost reamwriterclass topic.asp>

          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Ash Phillips

            #6
            Re: Outputting text to a file

            wow, thanks everyone for your replies - I appreciate it :)


            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
            news:OPPA$AcEFH A.3416@TK2MSFTN GP09.phx.gbl...[color=blue]
            > Ash,
            >
            > "Ash Phillips" <ash@expwin.net > schrieb:[color=green]
            > > Is there any way I can open the file and just keep writing lines of text
            > > to
            > > the file instead of doing it to a textbox then to a file?[/color]
            >
            > File Access with Visual Basic Run-Time Functions:
            >
            > Visual Basic Language Concepts -- File Access with Visual Basic Run-Time
            > Functions
            >[/color]
            <URL:http://msdn.microsoft.com/library/en...rocessingFiles
            ..asp>[color=blue]
            >
            > - or -
            >
            > .NET Framework Class Library -- 'FileStream' Class
            >[/color]
            <URL:http://msdn.microsoft.com/library/en...ystemIOFileStr
            eamClassTopic.a sp>[color=blue]
            >
            > .NET Framework Class Library -- 'StreamWriter' Class
            >[/color]
            <URL:http://msdn.microsoft.com/library/en...ystemiostreamw
            riterclasstopic .asp>[color=blue]
            >
            > --
            > M S Herfried K. Wagner
            > M V P <URL:http://dotnet.mvps.org/>
            > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
            >[/color]


            Comment

            Working...