Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem writing to text file

Status
Not open for further replies.
May 22, 2003
42
US
Hi

I'm trying to append a text file from input from a TextBox for some reason I get the following output:

frh001wa2555655
f
fr
frh
frh0
frh00
frh001
frh001w
frh001wa
frh001wa2
frh001wa26
frh001wa261
frh001wa2613
frh001wa26135
frh001wa261351
frh001wa2613519

code:

Dim objStreamWriter As StreamWriter

'Pass the file path and the file name to the StreamWriter constructor.
objStreamWriter = New StreamWriter("D:\Host.txt")

'Write a line of text.
objStreamWriter.WriteLine(Me.Textbox1.Text, True) 'True for append

'Close the file.
objStreamWriter.Close()

Thank you

Tony
 
I copy paste your code and trie it and it creates a file with just the txt in it nothing more nothing less. Are you sure you don't have any other code or is the textbox set as multiline?



Christiaan Baes
Belgium

"My old site" - Me
 
Code:
Dim objStreamWriter As TextWriter

        'Pass the file path and the file name to the StreamWriter constructor.
        objStreamWriter = New StreamWriter("Host.txt", True) 'True for append

        'Write a line of text.
        objStreamWriter.WriteLine(Me.TextBox1.Text)

        'Close the file.
        objStreamWriter.Close()

Your append code wasn't in the right place.

Christiaan Baes
Belgium

"My old site" - Me
 
Hi Christiaan

The code works fine for the first line. It's when I try to append the text file I get the funky output. Here is the actual code:

Dim sw As New System.IO.StreamWriter("D:\host.txt", True)
sw.WriteLine(Me.TextBox1.Text)
sw.Close()

What I'm trying to do is create the text file and append the file with machine names from textbox1.

the ideal output would be

frh001wa2555655
edi002ma2341234
etc...
etc...

Also,I would like to append with the host name only if the name doesn't already exist in the text file.

Thanks

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top