Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

opening output files by naming it with the help of variables i and j

  Asked By: Ibthaj    Date: Aug 27    Category: MS Office    Views: 811
  

I have 1000 output files which I need to write. There names are
lp1_0.txt, lp1_1.txt, ---lp1_4.txt, lp2_1.txt,---, lp 200_4.txt.

If I open a file lp5_4.txt by giving exact file name
Open "D:\lp5_4.txt" for output as #1
I will have to type it 1000 times.

Therefore, I wanted to open the file using variables like
for i=1 to 200
for j=0 to 4
Open "D:\lp" i "_" j ".txt" for output as #1
...
Next
Next

What exact command should be given in place of
Open "D:\lp" i "_" j ".txt" for output as #1

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Herbert Weaver     Answered On: Aug 27

strFName= "D:\lp" & i & "_" & j & ".txt"
open strFName for output  as #1

It could all be in one line

open "D:\lp" & i & "_" & j & ".txt" for output as #1

But it is easier to debug if it is separate.

 




Tagged: