CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Posts
    2

    exporting to fixed length

    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.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: exporting to fixed length

    Try something likerivate 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
    [email protected]
    [email protected]
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured