<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Append text to Save Text File function in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45265#M25869</link>
    <description>&lt;P&gt;Continue() is kind of like break. It immediately iterates and skips everything past it. &amp;nbsp;For instance&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for(i=1, i&amp;lt;=50, i++, 
	errortxt = ""
	If( File Exists( location ),
		csvlist[N Items( FilesIndex )] = Open( location )
	, //else
		//could just concat one text file and save after the for loop
		errortxt ||= "File doesnt exist" || Char( location ) ) || "\!n" //just a newline to make it more readable
		//or if you just want to append to the file
		Save Text File( path || "\" || "error.txt", 
			"File doesnt exist" || Char( location ) ) || "\!n", 
			mode("append")
		);
		Continue();
	);
	print("Doing other stuff")
	
);&lt;BR /&gt;//if using the errortxt method&lt;BR /&gt;Save Text File( path || "\" || "error.txt", errortxt);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this script, if it doesn't find the file, it will either append to the file or (really it does both) concatenate the error to the errortxt string. &amp;nbsp;Once it hits Continue(), it will immediately start the for loop over. &amp;nbsp;Skipping Print("Doing other stuff"). &amp;nbsp;Check out the scripting index under Help&amp;gt;&amp;gt;Scripting Index, it has really good documentation and examples on the functions and how they work. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helped.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2017 20:00:02 GMT</pubDate>
    <dc:creator>vince_faller</dc:creator>
    <dc:date>2017-09-28T20:00:02Z</dc:date>
    <item>
      <title>Append text to Save Text File function</title>
      <link>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45256#M25864</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using this function as part of the FOR loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( File Exists(location)
csvlist[N Items(FilesIndex)]= Open(location),
//else below
continue() &amp;amp;      // I am not sure this &amp;amp; function works.
Save Text File( path || "\" || "error.txt", "
\!"File doesnt exist\!";
" ||char(location)) ;
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically what I want to do is, I want to open the location if file exists, if not, I want to create a text file and iterate the loop. Also, I want to keep appending to the same error. txt file without replacing it everytime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyone know how to do this? I really appreciate your help.&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 19:45:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45256#M25864</guid>
      <dc:creator>vishwasanj</dc:creator>
      <dc:date>2017-09-28T19:45:46Z</dc:date>
    </item>
    <item>
      <title>Re: Append text to Save Text File function</title>
      <link>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45263#M25868</link>
      <description>&lt;P&gt;The scripting index is a great place to look up JSL functions.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Scripting Index showing mode(&amp;quot;append&amp;quot;)" style="width: 956px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/7816i3FE9809BED1DA9EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="SaveTextFile.PNG" alt="Scripting Index showing mode(&amp;quot;append&amp;quot;)" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Scripting Index showing mode("append")&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You probably don't want to use continue() like that. Continue() and Break() are statements in JSL that jump to the end of the containing loop and either continue the loop or break out of the loop. Possibly you want&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for(i=1,i&amp;lt;10,i+=1,
  if( condition,
    doSomethingIfTrue();
    doMoreThingsIfTrue();
  , // else
    doSomethingIfFalse();
    continue();
  ); // end of if statement
  codeThatIsSkippedByContinue();
); // end of for loop&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2017 19:53:56 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45263#M25868</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2017-09-28T19:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Append text to Save Text File function</title>
      <link>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45265#M25869</link>
      <description>&lt;P&gt;Continue() is kind of like break. It immediately iterates and skips everything past it. &amp;nbsp;For instance&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;for(i=1, i&amp;lt;=50, i++, 
	errortxt = ""
	If( File Exists( location ),
		csvlist[N Items( FilesIndex )] = Open( location )
	, //else
		//could just concat one text file and save after the for loop
		errortxt ||= "File doesnt exist" || Char( location ) ) || "\!n" //just a newline to make it more readable
		//or if you just want to append to the file
		Save Text File( path || "\" || "error.txt", 
			"File doesnt exist" || Char( location ) ) || "\!n", 
			mode("append")
		);
		Continue();
	);
	print("Doing other stuff")
	
);&lt;BR /&gt;//if using the errortxt method&lt;BR /&gt;Save Text File( path || "\" || "error.txt", errortxt);&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In this script, if it doesn't find the file, it will either append to the file or (really it does both) concatenate the error to the errortxt string. &amp;nbsp;Once it hits Continue(), it will immediately start the for loop over. &amp;nbsp;Skipping Print("Doing other stuff"). &amp;nbsp;Check out the scripting index under Help&amp;gt;&amp;gt;Scripting Index, it has really good documentation and examples on the functions and how they work. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helped.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:00:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45265#M25869</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2017-09-28T20:00:02Z</dc:date>
    </item>
    <item>
      <title>Re: Append text to Save Text File function</title>
      <link>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45269#M25873</link>
      <description>&lt;P&gt;The logic to your code is there.&amp;nbsp; You just don't seem to be looking up the syntax or the definitions in the Scripting Index.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( File Exists(location)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you are missing a comma and/or a completion&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( File Exists(location),
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( File Exists(location) == 1,
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't understand the logic of the next line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;csvlist[N Items(FilesIndex)]= Open(location),
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the way it is written, the pointer to every data table would be written on top of each other, unless somewhere in your code FilesIndex is getting added to between openning data tables.&amp;nbsp; I suggest an easier, safer method&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Open(location);
insert into(csvlist,dt),&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;there is no need for "continue", the code will contine automatically&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your "Save Text File" function is syntactically fine, if you want the each execution to write over the previous execution of the line.&amp;nbsp; Take a look in the Scripting Index to see how to keep from doing that if you want to add to the file rather than writing on top of it.&lt;/P&gt;
&lt;P&gt;I would also suggest that if you want the error lines to be added to the code, that you add "\!n" to each line, to force each listing to a new line.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2017 20:30:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Append-text-to-Save-Text-File-function/m-p/45269#M25873</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2017-09-28T20:30:32Z</dc:date>
    </item>
  </channel>
</rss>

