Results 1 to 7 of 7

Thread: Saving a *.txt file in VB 2005 - Help Please

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    33

    Saving a *.txt file in VB 2005 - Help Please

    Can someone help me save some text to a text file in VB 2005? (VB 6's way dosn't work)

  2. #2
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: Saving a *.txt file in VB 2005 - Help Please

    in VB6 you can use the richtextbox for saving a txt file

    in vb 2005 you can use the richtextbox too:

    Code:
    SaveFileDialog1.ShowDialog()
    RichTextBox1.SaveFile(SaveFileDialog1.FileName,RichTextBoxStreamType.PlainText)
    has you can see i use more objects to these example:
    button and savefiledialog(don't forget to write the extencion *.txt)

    i hope these helps

    PS: in vb6 is more or less the same....
    Last edited by joaquim; Mar 15th, 2008 at 05:12 PM.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Saving a *.txt file in VB 2005 - Help Please

    Moved to VB.NET

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    33

    Re: Saving a *.txt file in VB 2005 - Help Please

    Quote Originally Posted by joaquim
    in VB6 you can use the richtextbox for saving a txt file

    in vb 2005 you can use the richtextbox too:

    Code:
    SaveFileDialog1.ShowDialog()
    RichTextBox1.SaveFile(SaveFileDialog1.FileName,RichTextBoxStreamType.PlainText)
    has you can see i use more objects to these example:
    button and savefiledialog(don't forget to write the extencion *.txt)

    i hope these helps

    PS: in vb6 is more or less the same....
    Thank you for your help, but is there a way to do it without the FD?

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Saving a *.txt file in VB 2005 - Help Please

    vb.net Code:
    1. IO.File.WriteAllText("file path here", myString)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2008
    Posts
    33

    Re: Saving a *.txt file in VB 2005 - Help Please

    vb Code:
    1. IO.File.WriteAllText("file path here", myString)

    When using this code how would I make the file name varie?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Saving a *.txt file in VB 2005 - Help Please

    The first parameter is just a String. That String can come from anywhere. One place it might come from is the FileName property of an OpenFileDialog, thus allowing the user to select the destination, e.g.
    vb.net Code:
    1. Using ofd As New OpenFileDialog
    2.     If ofd.ShowDialog() = Windows.Forms.DialogResult.OK Then
    3.         IO.File.WriteAllText(ofd.FileName, Me.TextBox1.Text)
    4.     End If
    5. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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