'------------------------------------------------------
'How To: Save Data to a Text File
'Posted: June 1998
'From: "Robert L. Walsh" rlwalsh@capecod.net
'------------------------------------------------------
Keywords to see in on-line help: Open, Print #, Close, FreeFile,
Input #, Line Input #, EOF(), LOF().
Text files are stored in sequential files, that is, files that must
always be read from the beginning to the end or to some point
before the end. It goes without saying that the files are also
written to disk from beginning to end.
'Writing to the file:
Dim iFB As Integer
iFB = FreeFile 'Get next available file buffer.
Open "C:\MyDir\MyFile" For Output As #iFB 'Open the file to write to disk.
Print #iFB, Text1.Text 'Write out contents of some textbox.
Close iFB 'Close the file buffer.
'Reading from the File:
Dim iFB As Integer, sTmp1 As String, sTmp2 As String
iFb = FreeFile
Open "C:\MyDir\MyFile" For Input As #iFB 'Open for read (input).
Do While EOF(iFB) = False 'Loop thru multiple lines.
Line Input #iFB, sTmp1 'Input a whole line or row.
sTmp2 = sTmp2 & sTmp1 & vbCrLf 'Append to sTmp2 with crlf.
Loop
Text1.Temp = sTmp2
Close iFB
The code to read the file includes a loop to allow reading in multiple
lines. Multiple lines can, of course, be written as well. Code to do
that has been omitted here for simplicity`s sake. The VB constant
vbCrLf supplies a pair of characters known as a Carriage Return,
Line Feed. They are, in fact, the Ascii characters 13 and 10.
Downloads
In IE right-click and select 'Save Target As...' or in Netscape
right-click and select 'Save Link As...'
View Plain Text
Not Available
Not Available