Click to See Complete Forum and Search --> : exporting to fixed length


Derek Smigelski
February 8th, 2000, 01:28 PM
I have a set of data that I'm exporting to a text file. However the file is not in fixed length format. For instance, it looks like this:

"abcd","123 brwon street","Austin","TX"

When I need it to look like:

abcd 123 brown street Austin TX

Any ideas? Thanks in advance.

Aaron Young
February 8th, 2000, 02:50 PM
Try something like:private Type NewRecord
Field1 as string * 4
Field2 as string * 17
Field3 as string * 7
Field4 as string * 3
End Type

private Sub Command1_Click()
Dim iFile as Integer
Dim sRecord as string
Dim sValues as Variant
Dim tFormatted() as NewRecord
Dim iRecs as Long

iFile = FreeFile
Open "C:\File.txt" for input as iFile
While Not EOF(iFile)
Line input #iFile, sRecord
sValues = Split(sRecord, ",")
ReDim Preserve tFormatted(iRecs)
With tFormatted(iRecs)
.Field1 = Replace(sValues(0), Chr(34), "")
.Field2 = Replace(sValues(1), Chr(34), "")
.Field3 = Replace(sValues(2), Chr(34), "")
.Field4 = Replace(sValues(3), Chr(34), "")
End With
iRecs = iRecs + 1
Wend
Close iFile

iFile = FreeFile
Open "C:\Fixed.txt" for binary Access Write as iFile
for iRecs = 0 to UBound(tFormatted)
Put #iFile, , tFormatted(iRecs)
next
Close iFile

End Sub



Aaron Young
Analyst Programmer
ajyoung@pressenter.com
aarony@redwingsoftware.com