Link to home
Start Free TrialLog in
Avatar of chadmanvb
chadmanvb

asked on

Read file and then write to it

I have a script and I need to document how many times a certain procedure is being used.  I would just like to write this out to a text file to look like:

10-26-2006 20
10-27-2006 55
10-28-2006 20

Total=95

I will 6 people all using the same script and would like this written to a text file in a shared location.  I doubt anyone would be using this at the same time, but I guess it could happen.  I have never written to a text file and not really sure how to set this up since it needs to read the file to get a number, then add +1 to this number.  I guess it also must know what date it is to see if it needs to start  new date.

Thanks, Chad
Avatar of gangwisch
gangwisch

Dim fs As New FileStream("c:\file.txt", FileMode.Append)
        Dim sw As New StreamWriter(fs)
        sw.WriteLine("Hello")

make sure you import system.io
ASKER CERTIFIED SOLUTION
Avatar of sandip132
sandip132
Flag of Japan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with sandip132. You will have better luck if you move to some other structure. You will run into problems when multiple people hit the file at the same time, if it ever happens. And at some point your app will slow down due to the large number of lines in the file.

I’m not sure of the scope of your available options but one thing you could do:

Setup a web service, which is called by the app.
Make the web service write to a common location, say a database of some sorts.

Even though a database is just a fancy “file”, it provides a means to manage multiple streams of data coming in at or near the same time. By using the database you are able to “ignore” this aspect and just write to the database.