ACC1x: Sample Function to Insert CR/LF in Fixed-Width FilesID: Q109938
|
Fixed-width text files imported into Microsoft Access must have a
carriage return/line feed character at the end of each line. This article
describes a sample Access Basic function to add carriage return/line feed
characters to the end of each line in a file.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools
provided with Microsoft Access. For more information on Access Basic,
please refer to the "Introduction to Programming" manual.
The following sample function will add a carriage return/line feed
character to the end of each line in a file that does not have one. This
function can process files with records larger than 255 bytes.
NOTE: In the following sample code, an underscore (_) is used as a line-
continuation character. Remove the underscore when re-creating this code
in Access Basic.
Option Explicit
Function AddCRLF (InFile As String, OutFile As String, _
RecLen As Integer)
Dim InFileNo As Integer, OutFileNo As Integer, Rec As String
' Get an open file handle and open the input file.
InFileNo = FreeFile
Open InFile For Input As #InFileNo
' Get an open file handle and open the output file.
OutFileNo = FreeFile
Open OutFile For Output As #OutFileNo
' Process the file.
Do While Not EOF(InFileNo)
' Read one fixed-width record, RecLen in size.
Rec = Input$(RecLen, InFileNo)
' Output the record to the output file.
' NOTE: Print automatically places a carriage return/line feed
' character at the end of the line.
Print #OutFileNo, Rec
Loop
' Close the files.
Close #InFileNo
Close #OutFileNo
End Function
Additional query words: Import Fixed Width FreeFile
Keywords : kb3rdparty IsmTxtfx
Version : 1.0 1.1
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: April 2, 1999