Writing To File
Writing to file is a method of storing data. To write or read from a file you open the file for either Output, Input, Append. Output is used to overwrite or create a new file, Input is used to read from a file and Append is used to write to the end of the file.
To open a file for output type:
Open Location For Output As #Number
Then after opening the file for output to write to file type:
Print #Number, What To Write
Note: The number needs to be the same as what you opened the file as.
Then to close the file type:
Close
You should close the file because if you have opened the file for output and then you open it for Input without closing the file you can't use the same number you used for Output. This isn't important but it keeps things tidy.
So for example to create a file at: C:\File.txt and then
write: hello
on the first line of the file and the text in a text box on the second line of the file type:
Open "C:\File.txt" For Output as #1
Print #1, "hello"
Print #1, Text1.Text
Close
To open a file for input type:
Open Location For Input As #Number
Then after opening the file for output to write to file type:
Input #Number, Variable
Note: The number needs to be the same as what
you opened the file as.
The Variable will equal what is in on the first line.
Then to close the file type:
Close
You should close the file because if you have opened the file for output and then you open it for Output without closing the file you can't use the same number you used for Input. This isn't important but it keeps things tidy.
So for example to read the first 2 lines of a file at:
C:\File.txt and have the data written into two variables, Variable1 and
Variable2 respectively type:
Open "C:\File.txt" For Input as #1
Input #1, Variable1
Input #1, Variable2
Close