A few comments on Brian's answer:
1) You should use "Write" instead of "Print" to output comma separated values. e.g.:
Dim iOne as integer, iTwo as integer, iThree as String
iOne=1
iTwo=12
iThree="A"
...
Write #intFileHandle, iOne,iTwo,iThree
...
Gives this output:
1,12,A
etc.
2) You should then use "Input" not "Line Input" to read the comma separated values:
Dim xOne as integer, xTwo as integer, xThree as String
...
Input #intFileHandle, xOne,xTwo,xThree
...
This reads each separated value into the specified variables...
Main Topics
Browse All Topics





by: brianb99999Posted on 2004-11-04 at 13:53:42ID: 12498730
Standard flat file Read and write routines:
--" --"
--" --"
Read:
Dim intFileHandle As Integer
Dim strRETP As String
intFileHandle = FreeFile
Open "path to file" For Input As #intFileHandle
Do While Not EOF(intFileHandle)
Line Input #intFileHandle, strRETP
MsgBox strRETP
Loop
Close #intFileHandle
Write (creates a new file overwriting any existing file):
Dim intFileHandle As Integer
Dim strRETP As String
strRETP = "Hi There"
intFileHandle = FreeFile
Open "path to file" For Output As #intFileHandle
Print #intFileHandle, "-------------------------
Print #intFileHandle, strRETP
Print #intFileHandle, "-------------------------
Close #intFileHandle
Write (appends data to an existing file):
Dim intFileHandle As Integer
Dim strRETP As String
strRETP = "Hi There"
intFileHandle = FreeFile
Open "path to file" For Append As #intFileHandle
Print #intFileHandle, "-------------------------
Print #intFileHandle, strRETP
Print #intFileHandle, "-------------------------
Close #intFileHandle
Brian.