Copy link to clipboard
Copied
Hello fellows,
When I loop through a list of book files and write their names to the FM console, the full list is displayed. However, when I write the list to a text file, only the 1st file name is written. Any ideas why?
Loop ForEach(BookComponent) In(vCurrentBook) LoopVar(v_File)
...
Write Console v_File;
vs.:
Set vPath = v_UserPath+DIRSEP+'_'+'Test'+'.txt';
New TextFile File(vPath) NewVar(vFile_Listing);
Write Object(vFile_Listing) v_File;
EndLoop
Thank you for your input in advance!
Roman
Hi Roman, This works for me:
Set sPath = 'C:\DATA\Test.txt';
New TextFile File(sPath) NewVar(oFile);
Set oBook = ActiveBook;
Loop ForEach(BookComponent) In(oBook) LoopVar(oBookComp)
Write Object(oFile) oBookComp.Name;
EndLoop
Close TextFile Object(oFile);
You have to close the text file when you are done with it. Maybe that is the problem with your code.
-Rick
Copy link to clipboard
Copied
Fellows,
Do you have any ideas?
I tried to add "+ CHARCR" to make the next book component to appear on the next line, but that did not help.
Thanks for your input in advance!
Copy link to clipboard
Copied
Hi Roman, This works for me:
Set sPath = 'C:\DATA\Test.txt';
New TextFile File(sPath) NewVar(oFile);
Set oBook = ActiveBook;
Loop ForEach(BookComponent) In(oBook) LoopVar(oBookComp)
Write Object(oFile) oBookComp.Name;
EndLoop
Close TextFile Object(oFile);
You have to close the text file when you are done with it. Maybe that is the problem with your code.
-Rick
Copy link to clipboard
Copied
Hi Rick,
Thank you for your response and for the suggestion!
I found the problem -- I put the file creation function inside the loop...
Your example helped me understand what the problem is.
By the way, I do not add any instruction to open the created text file, so why do I need to close it?
Thank you again!
Best regards,
Roman
Copy link to clipboard
Copied
Hi Roman, When you create a new text file with the New TextFile command, it opens it automatically for writing. So to be safe, you should explicitly close it. -Rick
Copy link to clipboard
Copied
Hi Rick,
By saying "opens it automatically for writing" you mean that the file becomes writable and not that the text file is opened in the default text editor after creating it, correct? I guess, by running the Close() function, you just save the latest changes.
Thank you!
Roman