Basically there are 3 different methods for reading and writing to files.
Input
This is for reading text from files,
That would read one line from the file
To read the whole thing use
Output
Out put completely erases a file and replaces it with your data
Append
Instead of over writing the file with append you can add to it
Input
This is for reading text from files,
- Code:
Dim Data As String 'Declares a variable to hold the data you get from file
Open "C:\new.txt" For input as #1'open it for input
input #1,Data
Close #1'Finally close the file once youve finished reading from it
Call Msgbox(Data)'Display data in a file
That would read one line from the file
To read the whole thing use
- Code:
Dim Data,allData As String 'Declares a variable to hold the data you get from file
Open "C:\new.txt" For input as #1'open it for input
do until EOF(1)'Loop until EOF(end of file) = true (or 1)
input #1,Data
alldata = alldata & Data
loop
Close #1'Finally close the file once youve finished reading from it
Call Msgbox(allData)'Display data in a file
Output
Out put completely erases a file and replaces it with your data
- Code:
Open "C:\File.txt" for output as #1,
Print #1,yourvar
close #1
Append
Instead of over writing the file with append you can add to it
- Code:
Open "File.txt" for append as #1
print #1,data
close #1