Click here to Skip to main content
14,934,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to save various customer details onto a textile, I am currently able to save customer information however when I add a new customers' details the previous information is overwritten.

What I have tried:

Dim Filenum As Integer = FreeFile()

FileOpen(Filenum, "Z:\Desktop\original.txt", OpenMode.Output)

PrintLine(Filenum, txtBoxFullName.Text & txtBoxFullAddress.Text & txtBoxDateOfBirth.Text & txtBoxEmailAddress.Text & txtBoxPostcode.Text & txtBoxPhoneNumber.Text & txtBoxItemDetails.Text & txtBoxRepairDescription.Text & txtBoxDateOfBirth.Text)

FileClose(Filenum)

MessageBox.Show("Customer/s has been successfully registered")
Posted
Updated 17-Jan-18 1:59am
Comments
[no name] 21-Dec-17 9:59am
   
I don't know VB, but after a quick Google search I think you can use FileOpen(1, "TextFile1.txt", OpenMode.Append)
BTW: Think about, how you would decodes your lines :-)

1 solution

Don't open it for Output: that specifically deletes the file if it exists and opens a new one: use OpenMode.Append instead.

But ... I would suggest that rather than keeping the data in a flat file, use a "defined format" file such as CSV, XML, or JSON - the latter is trivial to support a list of customers and can serialize and deserialize the entire list of instances in a single line of code if you use NewtonSoft.JSON: you can add it to your project via the NuGet Package Manager (Tools ... NuGet Package Manager ... Package Manager Console):
PM> Install-Package Newtonsoft.Json
And then just one line of code does all the work:
C#
File.WriteAllText(path, JsonConvert.SerializeObject(MyCustomers));
And
C#
MyCustomers =  JsonConvert.DeserializeObject<List<Customer>>(File.ReadAllText(path));

Plus, you get a file format that is usable directly in many other applications.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900