<?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: Debug a JSL for Dat File open and modify then save to close in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274580#M53260</link>
    <description>&lt;P&gt;I fixed the bug by doing modification below,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Right( y[i], 3 ) == "dat", ...............&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jun 2020 10:43:02 GMT</pubDate>
    <dc:creator>Stokes</dc:creator>
    <dc:date>2020-06-22T10:43:02Z</dc:date>
    <item>
      <title>Debug a JSL for Dat File open and modify then save to close</title>
      <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274548#M53251</link>
      <description>&lt;P&gt;Anyone can help to fix the jsl below,&lt;/P&gt;
&lt;P&gt;The goal is to open all dat file under the same directory and delete 2 rows, then save it.&lt;/P&gt;
&lt;P&gt;Thanks&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;directory = Pick Directory();

fileNames = Files In Directory( directory );

For( iFile = 1, iFile &amp;lt;= N Items( fileNames ), iFile++, 

    filename = fileNames[iFile];

    If( Ends With( filename, ".dat" ), 

        dt = Open( directory || filename );

        //delete first 2 rows
        dt &amp;lt;&amp;lt; Select Where( Row() &amp;lt; 3 );
        dt &amp;lt;&amp;lt; delete rows;

        Close( dt, "save" );

    );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:29:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274548#M53251</guid>
      <dc:creator>Stokes</dc:creator>
      <dc:date>2023-06-09T23:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Debug a JSL for Dat File open and modify then save to close</title>
      <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274550#M53252</link>
      <description>&lt;P&gt;Do you get any errors in the log?&amp;nbsp; If so, what are they?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect the Select Where is running too soon, because the file is opening, which JMP will do in the background.&amp;nbsp; Try putting the line&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt &amp;lt;&amp;lt; rerun formulas;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;after the open() and see if that works.&lt;/P&gt;
&lt;P&gt;What I usually do with code like this, is to run lines 1&amp;amp;2.&amp;nbsp; Find the first file that ends in .dat, and set your "filename' to its value, and then run one at a time, the open, select where, delete and close lines to see what happens.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 00:20:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274550#M53252</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-06-20T00:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Debug a JSL for Dat File open and modify then save to close</title>
      <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274557#M53253</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/9711"&gt;@Stokes&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim gave you some great debug suggestions. Below are a couple notes/potential issues. As Jim suggested, the errors in the LOG&amp;nbsp; or a description your task and what happens when you run the script would be informative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Instead of select where() and delete, you can use dt &amp;lt;&amp;lt; delete rows(1::2);&lt;/LI&gt;
&lt;LI&gt;I often use wait( 0 ); after the save, to force its completion before continuing.&lt;/LI&gt;
&lt;LI&gt;Your script is looking for files with &lt;STRONG&gt;.DAT&lt;/STRONG&gt; extension, which is a generic file type. You are reading it into JMP data table and then script a &lt;STRONG&gt;SAVE&lt;/STRONG&gt;.&amp;nbsp; This has several potential issues,, unintended consequences:&lt;/LI&gt;
&lt;/UL&gt;
&lt;OL&gt;
&lt;LI&gt;The file type might need more details to be read properly, so the open might be causing an error.&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Assuming the file is read properly into a JMP data table, a &lt;STRONG&gt;SAVE&lt;/STRONG&gt; will save the file as a .JMP file. Is that your intention? or do you want to save it as a &lt;STRONG&gt;.DAT&lt;/STRONG&gt; file?&amp;nbsp; Often when users ask this type of question, they are wanting to use JMP to clean up a data file written by some automated metrology tool that has header information in a different format. That header information can cause Open() errors and other problems. So knowing the task will help the JMP community provide a solution. Depending upon the task, a &lt;STRONG&gt;Load Text File()&amp;nbsp;&lt;/STRONG&gt;or &lt;STRONG&gt;Open()&lt;/STRONG&gt; with import text options might be required.&lt;/LI&gt;
&lt;LI&gt;If the response to the &lt;STRONG&gt;Pick Directory()&lt;/STRONG&gt; prompt is a directory that is readable but not writable, this could cause an error, or the file being saved in an unintended directory. For example if I modify your script to read .TXT files and pick the directory for JMP Samples/Import Data, the program will read the .txt files but save them as .JMP files, but not in the JMP Samples/Import Data directory because it is not writable.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;These items are intended to help clarify the type of details that are needed to help you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 08:31:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274557#M53253</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2020-06-20T08:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: Debug a JSL for Dat File open and modify then save to close</title>
      <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274579#M53259</link>
      <description>&lt;P&gt;Thanks Jim, Morgon.&lt;/P&gt;&lt;P&gt;I used step by step method to check the loop, and it turns out the issue happens when open the .dat file.&lt;/P&gt;&lt;P&gt;There is no response after run open .dat.&lt;/P&gt;&lt;P&gt;I change it to open .txt and it works fine.&lt;/P&gt;&lt;P&gt;Do you have any idea why this happens and how to fix it?&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jun 2020 19:16:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274579#M53259</guid>
      <dc:creator>Stokes</dc:creator>
      <dc:date>2020-06-20T19:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: Debug a JSL for Dat File open and modify then save to close</title>
      <link>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274580#M53260</link>
      <description>&lt;P&gt;I fixed the bug by doing modification below,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;If( Right( y[i], 3 ) == "dat", ...............&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jun 2020 10:43:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Debug-a-JSL-for-Dat-File-open-and-modify-then-save-to-close/m-p/274580#M53260</guid>
      <dc:creator>Stokes</dc:creator>
      <dc:date>2020-06-22T10:43:02Z</dc:date>
    </item>
  </channel>
</rss>

