Writing to Multiple Files - VB6

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have an idea that I want to write to many (qty unknown untill run
time but in the order of 5) text files as my application runs. They're
log files dealing with different aspects of the application and will
ultimately be sent to different users, hence why they have to be
different files. I know that I want to be using the File System Object
to manage files, but I don't know how to open many files, keep them
open and write to them as and when required.

The FSO is a collection, so I guess it should be possible but I could
do with some hints or tips from you guys as to the best way to go about
this.

Cheers,

<M>
 
First, this is a dotnet group (VB 6 is pre-dotnet). Now for the answer
since I cringe when that's all I see is "Wrong NG."

I'm not going to use FSO simply because it's too slow and different versions
of Windows have slightly different versions of the scripting runtime engine.

dim FileOutput(5) as long
dim i as integer
for i = 1 to 5
FileOutput(i) = freefile(1)
open "Myfile_" & i & ".log" for output as FileOutput(i)
next i

When you write to a file, simply select the index in the FileOutput array
that you want to use

print #FileOutput(someindex), "This is output"

You can either close the files individually (preferable) with

Close FileOutput(i)

or all at once with

Close

For further reference, a better NG for VB 6 questions is
microsoft.public.vb.general.discussion.

Mike Ober.
 
Sorry for the posting in the wrong group. I didn't spot the mistake
untill after I posted. I subsequently did raise a new subject in the
other group you mentioned.

That solution looks ideal. Thanks very much for the help.

<M>
 
Back
Top