Question Export to Notepad

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Hello.
I want to Export the content of my textboxes and comboboxes to a Notepad File.
I have this code:

Private Sub btnNotepad_Click(sender As Object, e As EventArgs) Handles btnNotepad.Click
Dim myOutputFile As String = "C:\Users\ELIANE\Desktop\Exported-to-Notepad.txt"
Dim myText As String = String.Format("{0},{1},{2},{3},{4},{5}", txtCode.Text, cmbTitle.Text, txtName.Text, cmbPosition.Text, txtAddress.Text,txtPhoneNumber.Text)
My.Computer.FileSystem.WriteAllText(myOutputFile, myText, False)
End Sub

this code works. But i need your help in something.
If i write a second time in the notepad , the first record i writed before will be gone.
Any help keeping all the records in the notepad separated by a line?
or a carriage return or something?

Thank You :)
 
Hi,

If you look at the final argument value in the WriteAllText Method that you have you will see that this is currently set to False but ask yourself this question, what is that Value doing and what could it be doing by setting it to what value?

That said, I would personally use a StreamWriter if I was just arbitrarily writing a line of text to a file every now and again. i.e:-

Using myWriter As New StreamWriter("d:\temp\YourFilename.txt", True)
  myWriter.WriteLine("The String To Be Written To The File")
End Using


Notice the True value as the final argument in the above declaration of the StreamWriter. What do you think that will do?:cool:

Hope that helps.

Cheers,

Ian
 
Actually i noticed it. I set it to True.
it gave me approximately the same result. But not what i wanted:
0,,,,,1,Miss,Eliane,Manager,Beirut,12122

the StreamWriter works perfectly.

Thank you. I should've figure that out.
Thanks again :)
 
Back
Top