Text Manipulation

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi,
How can I move all the carriage returns (Chr13) in a
textfile to the same position on each line.

Example1: The * marks the position of each carriage return.
Andy*
Michelle*
Sandra*

Example2: The * is lined up at the same position.
Andy *
Michelle *
Sandra *

This is so I can load each field in the text to a custom
datatype.

Any ideas please
Regards
Andy
 
You are looking to create a fixed-width table/text file.

Import or Link the text file as a table.
Open the table in design mode and step through the fields -
at the bottom restrict the Field Size to a set length.
Close & Save the table. Next, use a User-defined string
format on the field(s). (See Access Help for further
explanation: Format function>>See Also>>User-defined
String formats

The @ is a place holder and will insert a space when no
character is present. This will keep the field at a fixed
width. Use the correct number of placeholders to fill the
entire Field Size.
Example:
Maybe use an update query on the table. Where it says...

Field: Field1
Table: Table1
Update to: Format([Field1], "@@@@@@@@@@@@@@@@@@")

If Field1 had "123ABC" before, after the update query the
field would look like "123ABC "

For Numeric fields use a zero:

Update to: Format([Field2], "0000000000")

before= 12345 after= 0000012345

Use similar Formats, Named formats (i.e. "Currency"), or
design your own, on all of the fields, then update the
table.

If you want to see that it worked, open the text file in
MS Word and on the Tools menu select Options, then on the
View tab, under the section that says NonPrinting
Characters, check the box that says ALL.
 
This is so I can load each field in the text to a custom
datatype.

Rewrite each line with something like

' get the short line
Input #wInFile, strTemp

' this pads out the right hand end, or truncates as
' required, to wLineLength characters
Print #wOutFile, Left(strTemp & Space$(wLineLength), wLineLength)

Hope that helps


Tim F
 
Back
Top