• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

framescript: write to text file

Participant ,
Mar 28, 2015 Mar 28, 2015

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

TOPICS
Scripting

Views

481

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 31, 2015 Mar 31, 2015

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

Votes

Translate

Translate
Participant ,
Mar 31, 2015 Mar 31, 2015

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2015 Mar 31, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 31, 2015 Mar 31, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 31, 2015 Mar 31, 2015

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 31, 2015 Mar 31, 2015

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines