CSV File Amendment in VB.Net

Soldato
Joined
17 Jan 2006
Posts
2,890
Location
Dundee
I have writen 2 seperate progs (Client & Server) aimed a simulating an ATM.
The data is kep in a CSV file which is simple:

username,pin,balance.

Everything works fine except I dont know how to update the csv file with a new balance if the customer has made a "withdrawl".

The client receives the balance from the server after usrname and pin verifiaction and will calcuate any new balance and return in to the server. The server prog has a scrolling log window to display all traffic data (testing purposes) and the new balance comes across ok.

However, I am at a loss as to how to update the balance section of the csv file for the particular cust that is logged on.

:confused: :confused: :confused: :confused:

Any help really appreciated - I need to hand this in on Friday at 4 pm !!!!! :eek:
 
You'll need to use a temporary file to output the changed line.

Read in the csv file as a text stream, read/write individual lines to the temporary output file until you reach the one you want to change, make the change to the value, write it out, then carry on reading/writing the rest of the file.

Then delete the old file and rename the temporary file.

Of course whilst this is going on, no-one will be able to access the file and using a CSV as an updateable datasource is just plain CRAZY. But hey who am I to argue.

I get the feeling that more and more of these posts are for homework, which you should probably consider doing yourself (or at least use google to come up with the answer) if you're actually going to learn anything.

:)
 
Mr^B said:
You'll need to use a temporary file to output the changed line.

Read in the csv file as a text stream, read/write individual lines to the temporary output file until you reach the one you want to change, make the change to the value, write it out, then carry on reading/writing the rest of the file.

Then delete the old file and rename the temporary file.

Of course whilst this is going on, no-one will be able to access the file and using a CSV as an updateable datasource is just plain CRAZY. But hey who am I to argue.

I get the feeling that more and more of these posts are for homework, which you should probably consider doing yourself (or at least use google to come up with the answer) if you're actually going to learn anything.

:)

Cheers, but got it working. I know I should use an SQL database rather than a plain mold simple csv file, but I just wanted to get this working. I hate programming and am really a networker but there is a small section of vb programming in my degeree course (3rd year) and I was expected to know it fluently, despite not being taught it at all!!

Cheers for the reply.
 
Back
Top Bottom