bjwade62 Posted September 3, 2008 Posted September 3, 2008 I have an existing txt file that I want to open, get the text (which is a number), add 1 to the number and save/close the txt file. Sound like filestream but I'm not sure how to use it. I've founds peices of information but nothing I can use together. Any help out there? Thanks, Quote
Leaders snarfblam Posted September 3, 2008 Leaders Posted September 3, 2008 Assuming that you are using DotNet 2.0 or later, and the number is the only contents of the text file, you could do something along the lines of the following: [Vb] Dim FileName As String Dim Lines() As String 'Contents of the files will be stored here Lines = System.IO.File.ReadAllLines(FileName) ' This assumes that the first line of the file contains a properly formatted number Dim Value As Double = Double.Parse(Lines(0)) ' Increment the number Value += 1 ' Store it back in the document Lines(0) = Value.ToString() ' Write the document back to the disk System.IO.File.WriteAllLines(FileName, Lines) [/code] I haven't tested it and some exception handling would be a very good idea, but that's the jist of it. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.