Results 1 to 6 of 6

Thread: write to text file

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    243

    write to text file

    Hi

    I want to write the user input data to the text file. I want it to be in same line like this

    G1 Z1. F80.

    If i use my coding like this is not working:
    Code:
     Dim FILENAME As String = "C:\kaya.txt"
    
                   Dim objStreamWriter As StreamWriter
            objStreamWriter = File.AppendText(FILENAME)
    
           
            objStreamWriter.WriteLine("G1 " & TextBox2.Text, "F " & TextBox3.Text)
    
    
    
    
            ' Close the stream   
            objStreamWriter.Close()

    if i change it like this :
    Code:
    objStreamWriter.WriteLine("G1 " & TextBox2.Text)
            objStreamWriter.WriteLine("F " & TextBox3.Text)
    It become two lines. How can i solve this problem?
    Can any one help me.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: write to text file

    Try this method

    Code:
     
     'Open the File for writing
      Dim sw As New System.IO.StreamWriter("C:\text.txt", True)
           'Write at the end
            sw.WriteLine("TEsst1")
           'Close the stream
            sw.Close()
            sw.Dispose()
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    243

    Re: write to text file

    But i want the G1 and F to be in same line not in two lines. Your code still give me a same answer

  4. #4
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: write to text file

    I am not getting you... I think you are dumping forum with Text File question
    Please mark you thread resolved using the Thread Tools as shown

  5. #5
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: write to text file

    Look at the help file on the StreamWriter object, specifically the Write methods. Or do you want someone to write the code for you?
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  6. #6
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: write to text file

    Try this:
    Code:
    objStreamWriter.Write("G1 " & TextBox2.Text)
            objStreamWriter.Write("F " & TextBox3.Text)
    (using objStreamWriter.Write instead of objStreamWriter.WriteLine)

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