Hi, could anyone point me in the direction of a tutorial on saving variables to a text file and then accessing this value at a later date. I know how to write a variable to a textfile using
but how do I read the value back into the variable from the textfile, and if there is more than one value in the text file how do I tell it which value to put into which variable...?
The full code i used for writing the variables to the file is...
----------------------
Dim oFile As System.IO.File
Dim oWrite As System.IO.StreamWriter
(on form load)
oWrite = oFile.CreateText("C:\Program Files\Folder\filename.txt")
(on button click)
oWrite.WriteLine(variable1)
oWrite.WriteLine(variable2)
oWrite.Close()
----------------------
I know how to open the file at a later date [using 'Dim oRead As System.IO.StreamReader' and 'oRead = oFile.OpenText("C:\Program Files\Folder\filename.txt")'], its everything after that I'm stuck on!
Many thanks in advance for any help you can give and sorry if I don't make enough sense for you to help!
thats great. What if I don't know the variable line though... Is there a way of writing the variable name AND the value it holds to the textfile, then reading this back and entering it into the correct variable.
say i have a variable called 'name' that holds the value "Ross", can i write both the variable name and value to the textfile ( in a format such as name = "Ross"), then read this back into the variable 'name'.
Ok , that can be done but it would require a lot of code and not efficient way , if you ask me . What datatypes are you writing to the file ? I'm thinking you can declare an array of string or whatever , then you write a these values , separate them with separator , then it would be so easy to get them in the right order into the array . Tell me if you want a demo ?
Originally posted by Pirate Ok , that can be done but it would require a lot of code and not efficient way , if you ask me . What datatypes are you writing to the file ? I'm thinking you can declare an array of string or whatever , then you write a these values , separate them with separator , then it would be so easy to get them in the right order into the array . Tell me if you want a demo ?
A demo of this would be great if you have the time. I am using integers and strings. I am pretty new to this as you can tell!