Saving Text Box to File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Asprisa
    New Member
    • Oct 2007
    • 30

    Saving Text Box to File

    Hi Guys,

    I'm new to programming and i am starting a basic project, so far i have done well researching various bits on the net but have come across a problem and wondered if any one would help?

    All i am trying to do is:

    click a button called save and the info from txtbox_txt.text to go to a .txt file on c:\ drive but i want it to name the file as the date and time the file is created.

    any ideas?

    p.s i am using visual studio express 2005

    Jay!
  • Ali Rizwan
    Banned
    Contributor
    • Aug 2007
    • 931

    #2
    Originally posted by Asprisa
    Hi Guys,

    I'm new to programming and i am starting a basic project, so far i have done well researching various bits on the net but have come across a problem and wondered if any one would help?

    All i am trying to do is:

    click a button called save and the info from txtbox_txt.text to go to a .txt file on c:\ drive but i want it to name the file as the date and time the file is created.

    any ideas?

    p.s i am using visual studio express 2005

    Jay!
    Hello,
    I don't know a lot of VB 2005 but the code i m providing will help you in VB 2005 to save a textbox to a file.

    First add a refrence Microsoft Scripting Runtime

    Declarations

    Code:
    Dim fso As New FileSystemObject
    Dim f As File
    Dim s As TextStream
    Now add this code to Save button on Click Event

    Code:
        
    fso.CreateTextFile(txtpath.text,true)
    Set f = fso.GetFile(txtPath.text)
    Set s = f.OpenAsTextStream(ForReading)
    s.writeline(txtbox_txt.text)

    Add another textbox named txtpath where you will enter the path and file name

    GOODLUCK
    ALI

    Comment

    • Asprisa
      New Member
      • Oct 2007
      • 30

      #3
      Hi There,

      Thanks for the reply! I managed to do it a slightly diffrent way in the end, but you set me on the right path, here is what i did!

      SaveFileDialog1 .FileName = Name + ".txt"
      SaveFileDialog1 .InitialDirecto ry = "z:\public_html \handovernotes\ "
      SaveFileDialog1 .Filter = "Text files (*.txt)|*.txt|A ll files (*.*)|*.*"

      If SaveFileDialog1 .ShowDialog() = Windows.Forms.D ialogResult.OK Then

      My.Computer.Fil eSystem.WriteAl lText(SaveFileD ialog1.FileName , RichTextBox1.Te xt, False)

      End If


      Thanks for your help!!

      Jay

      Comment

      Working...