JasonK
JasonK

Reputation: 21

VB.NET write/read data from text file

This might be something that I am overlooking, as I am currently reading a book on VB.NET. I canceled a course in VB.Net recently because I was stuck on a problem and the lecturer did not get back to me with my questions that I had.

The objective was to create a business application with VB.NET that writes data from text boxes to a text file, seperated by a comma or a pipe. The user of the application must be able to select the directory where they want the file to be saved.

So I have for example 2 forms, one that captures the data for a client, and another form where you can select from a drop-down control, Now I know that streamwriter allows for the user to select self where they want the file to be saved, but how do I make the second form intelligent to know where the user saved the form and then reads the client_id, and fills the other data associated with the client_id to the text boxes in the form. I know streamreader is the one to use when you want to read data from a file, but how will streamreader know where the user will save the file to?

I am not doing the course any more, but I will keep on thinking what I could have done to actually get the project to work.

Upvotes: 0

Views: 21882

Answers (1)

jarvis
jarvis

Reputation: 81

For writing to file

// Write single line to new file.
Using writer As New StreamWriter("C:\log.txt", True)
writer.WriteLine("Important data line 1")
End Using

For reading from file

// read from a file
Dim line As String
Using reader As New StreamReader("file.txt")
    line = reader.ReadLine()
End Using
Console.WriteLine(line)

Upvotes: 4

Related Questions