merging ascii files

G

GBA

the issue is maintaining a field size where there is a null and padding with
spaces where the data is less that the field size....current write to ascii
just writes whatever data is there and doesn't maintain any fixed field sizes
with spaces. which doesn't surprise me.

I can write vb to pad each field as part of the ascii file vb creation in
memory; but field by field that is a ton of repetitive code. there's ~ 120
fields that all need fixed size. but that still may be the way to go. just
thought I would seek a sanity check from y'all....

I have experimented with the export specification approach - and that sets &
maintains the field sizes very nicely with spaces when there is no data -
which is what the recipient requires. But now, because I have 2 queries - I
have 2 ascii files. No way to merge those two queries as they are totally
different. So I wonder about the ease of perhaps merging ascii text from 2
ascii files. I have never merged ascii files. Perhaps it is easy.

Have no idea what syntax, references etc one uses in a situation like this
or whether there is some 'gotchas' I do not yet know about. Would welcome
input from someone whom has trod this path before....TIA.
 
G

Gina Whipp

Look up the Space() function, ie... Left([YourField] & Space(8),8) OR
Space(13),13)

As for merging two ASCII files I'm not sure what you are asking. Are you
trying to export them to one file?

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 
K

KC-Mass

Hi,

Merging two or one hundred ascii files couldn't be easier.

In Xp go to you "start" menu, select "Run", type in CMD.

You will be given a DOS like window.

In that window negotiate to the directory where the files are.

Type the command "Copy filename1 + filename2 + filename3 bigfile.

Hit enter and all the data from filename 1, 2 and 3 will be in bigfile.

If they all have similar naming you can use wildcards as in Copy *.txt
bigfile.

Regards
Kevin
 
G

GBA

thank you for taking the time to reply. going to DOS probably is not
something I am going to be able to automate in vba. but I googled around and
found a great solution that works and post here so others might have a need:

It uses File System Object and you need to add a reference of Microsoft
Scripting Runtime

Sub Append_Text_Files()

Dim oFS As FileSystemObject
Dim oFS1 As FileSystemObject

Dim oTS As TextStream
Dim oTS1 As TextStream

Dim vTemp

Set oFS = New FileSystemObject
Set oFS1 = New FileSystemObject


For i1 = 1 To 30

Set oTS = oFS.OpenTextFile("c:\Sheet" & i1 & ".txt", ForReading)
vTemp = oTS.ReadAll

Set oTS1 = oFS.OpenTextFile("c:\CombinedTemp.txt", ForAppending, True)
oTS1.Write (vTemp)

Next i1

End Sub

The code is simple.. it searches for files from Sheet1.txt ...Sheet30.txt
and copies the content into one variable. Then it appends the content to
CombinedTemp.txt
I myself modified this simply to read the 2 existing ascii files and combine
them into a 3rd. Works great.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top