writing data to a tab delimited text file?

F

festdaddy

I'm using VBA to generate random numbers for four fields and write the
data to a text file for use in another program. I'd like the data to be
in tab-delimited format, but the WRITE statement only seems able to
produce comma delimited, and the PRINT statement only seems to produce
spaces. I've searched this group, but all the answers appear to be
related to "save as" type of solutions, which won't work for me as I'm
trying to write 100k+ lines. Is there a way to force WRITE (or PRINT)
to use tabs instead of commas (or spaces)? . is there a "/t"
equivalent type of character I can append to the data or something?
 
T

Tom Ogilvy

Dim num as long, j as long, i as long
Dim sStr as String
For j = 1 to 100000
sStr = ""
for i = 1 to 4
num = int(rnd()*1000+1)
sStr = sStr & num
if i <> 4 then
sStr = sStr & vbTab
end if
Next
' place sStr in your file
Next
 
F

festdaddy

Thanks Tom! the vbTab was what I was missing. I just appended it the
end of each variable and that did the trick. Thanks for posting the
other code as well. Its always instructive to see how others do things.
Thanks again!
 

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