Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving and reformating data between text files

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
I am trying to open two text files and write from one to the other changing the format as I do it. The file I open to pull from has one long string of data of indeterminate length. It can vary with each file. I want to open the first file, pull the first 80 characters and put them on the first line of the second file. Then grab the next 80 characters of the first file and put them on the second line of second file. And so on until I am at the end of the record of the first file.

Opening the files I've done before but can I get som guidence on parsing out 80 characters putting them in the other file then grabbing the next 80 characters? I don't know where to begin.
Thanks
 
'Code that gets entire line of file and sets it to strIN

lngIN = Len (strIN)

lngPos = 1

While lngPos <= lngIn
strForWrite = Mid(strIn, lngPos, iif((lngPos + 79) > lngIn, lngIn - lngPos + 1, 80)
lngPos = lngPos + 80
'Code to write line to second file
Wend

'Code to loop to next line of file 1

It has been a long time since i've written anything to do with files from scratch, but I think the input and write commands are each one line.

Anyways, if I worked it out in my head write, that out to work. Although I often get strings off by 1 or 2 either by not adding or subtracting something or adding 1 when I should subtract. If I goofed, it shouldn't be that hard to fix. Let us know if it works.
 
Hi Eddy,

You may find the FileSystemObject very useful in handling and writing to text files.

HTH,

alr

_____________________________________
If a large part of intelligence is the ability to generalize, it is ironic that a large part of what we call wisdom is the ability not to generalize.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top