Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This was the ONLY place that I could find information that I could use to resolve the problem. So thanks once again to member TomSark and the SQL forum!..."

Geography

Where in the world do Tek-Tips members come from?

Script to Convert TAB Delimited File to Fixed Width Format

NickC111 (TechnicalUser)
27 Jul 12 10:58
I have an export file that is created in TAB delimited format. Record example below:

8000004449 5910.00 0.00 5910.00 XX 2012 1 5594.90 315.10 Extract
8000006341 6732.00 0.00 6732.00 XX 2012 1 6372.93 359.07 Extract
8000009894 5082.00 0.00 5082.00 XX 2012 1 4810.86 271.14 Extract
8000018985 10854.00 0.00 10854.00 XX 2012 1 10275.09 578.91 Extract
8000022166 11334.00 0.00 11334.00 XX 2012 1 10729.44 604.56 Extract
8000024096 29952.00 0.00 29952.00 XX 2012 1 28354.50 1597.50 Extract
8000025690 37650.00 0.00 37650.00 XX 2012 1 35642.13 2007.87 Extract
8000025850 858.00 0.00 858.00 XX 2012 1 812.19 45.81 Extract
8000028875 39846.00 0.00 39846.00 XX 2012 1 37720.88 2125.12 Extract

I need a script that will copy the data from the above file and use it to create a new file called import in Fixed Width format.

Field Lengths are all 15

Any help would be great
jges (TechnicalUser)
27 Jul 12 11:38
As a general strategy, I would:
  1. open the file and read it line by line
  2. use the split function on each line to break it into individual values (split(line, vbtab)
  3. use the space function to pad each value
  4. combine the array of values back into a single line
  5. write the line to the new file
NickC111 (TechnicalUser)
30 Jul 12 3:54
Thank You - can you show me how this can be done?
jges (TechnicalUser)
2 Aug 12 9:27
What code do you have so far?
SkipVought (Programmer)
2 Aug 12 10:42
Please post the specifications for the FIXED WIDTH of each column.

Skip,

glassesJust traded in my old subtlety...
for a NUANCE!tongue

macropod (TechnicalUser)
3 Aug 12 3:06

Quote:

Please post the specifications for the FIXED WIDTH of each column.
That would be:

Quote:

Field Lengths are all 15

Cheers
Paul Edstein
[MS MVP - Word]

Swi (Programmer)
7 Aug 12 16:50
Something like this should work for you.

CODE

Option Explicit
Dim fso
Dim InStream
Dim OutStream
Dim InputData
Dim aryTemp
Dim i

Set fso = CreateObject("Scripting.FileSystemObject")
Set InStream = fso.OpenTextFile("\\secpykpw01\RedirectedFolders\sdelp\Desktop\Test.txt", 1, True)
Set OutStream = fso.CreateTextFile("\\secpykpw01\RedirectedFolders\sdelp\Desktop\Test2.txt", True)

Do
    InputData = InStream.ReadLine
    aryTemp = Split(InputData, vbTab)
    For i = LBound(aryTemp) To UBound(aryTemp)
        OutStream.Write aryTemp(i) & Space(15 - Len(Trim(aryTemp(i))))
    Next
    OutStream.WriteLine
Loop Until InStream.AtEndOfStream
InStream.Close
OutStream.Close
Set fso = Nothing
MsgBox "Done!" 

Swi

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close