<?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 JSL script (rename columns) feedback: it works but I'm not sure why! in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109781#M39694</link>
    <description>&lt;P&gt;Hi JMP community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After 2 days of learning, I have finally produced a JSL script that performs the column name change operation I was looking for. However, considering the rather laborious process to get to this result, I suspect that I may have used sub-optimal approaches. Therefore, I'm looking for ways to clean up this script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

src=.;
trg = .;

sfx = "";
pfx = "";

n = 0;
m = 0;

win = New Window (
	" WARNING ",
	&amp;lt;&amp;lt; Modal,
	Text Box (" It is recommended that you save your table before proceeding "),
	Button Box (
		"SAVE NOW",
		dt &amp;lt;&amp;lt; Save("");
		),
	);

cd = Column Dialog(
		cl1 = ColList( "SOURCES", Min Col (1)),
		cl2 = ColList( "TARGETS", Min Col (1)),
		Line Up( 2,
			Text Box( "Prefix" ), ex = EditText( "P_" ),
			Text Box( "Suffix" ), ey = EditText( "_S" )
		),
		
);


src=cd[1];
srcx = right (src,length (src)); // I'm not sure how this works but without this the script fails
n = N items (srcx);

trg = cd[2];
trgx = right (trg,length (trg)); // I'm not sure how this works but without this the script fails
m = N items (trgx);

pfx = cd [4];
sfx = cd [6];

If (n == m, 
	
	st = "";
	For (i=1, i &amp;lt;= m, i++,
		
		scol = srcx [i] &amp;lt;&amp;lt; Get Name;
		st = pfx || scol || sfx;
		trgx [i] &amp;lt;&amp;lt; Set Name (st);
		
				
	);

,Stop());&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Your feedback would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TS&lt;/P&gt;</description>
    <pubDate>Sun, 10 Feb 2019 19:03:37 GMT</pubDate>
    <dc:creator>Thierry_S</dc:creator>
    <dc:date>2019-02-10T19:03:37Z</dc:date>
    <item>
      <title>JSL script (rename columns) feedback: it works but I'm not sure why!</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109781#M39694</link>
      <description>&lt;P&gt;Hi JMP community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After 2 days of learning, I have finally produced a JSL script that performs the column name change operation I was looking for. However, considering the rather laborious process to get to this result, I suspect that I may have used sub-optimal approaches. Therefore, I'm looking for ways to clean up this script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

src=.;
trg = .;

sfx = "";
pfx = "";

n = 0;
m = 0;

win = New Window (
	" WARNING ",
	&amp;lt;&amp;lt; Modal,
	Text Box (" It is recommended that you save your table before proceeding "),
	Button Box (
		"SAVE NOW",
		dt &amp;lt;&amp;lt; Save("");
		),
	);

cd = Column Dialog(
		cl1 = ColList( "SOURCES", Min Col (1)),
		cl2 = ColList( "TARGETS", Min Col (1)),
		Line Up( 2,
			Text Box( "Prefix" ), ex = EditText( "P_" ),
			Text Box( "Suffix" ), ey = EditText( "_S" )
		),
		
);


src=cd[1];
srcx = right (src,length (src)); // I'm not sure how this works but without this the script fails
n = N items (srcx);

trg = cd[2];
trgx = right (trg,length (trg)); // I'm not sure how this works but without this the script fails
m = N items (trgx);

pfx = cd [4];
sfx = cd [6];

If (n == m, 
	
	st = "";
	For (i=1, i &amp;lt;= m, i++,
		
		scol = srcx [i] &amp;lt;&amp;lt; Get Name;
		st = pfx || scol || sfx;
		trgx [i] &amp;lt;&amp;lt; Set Name (st);
		
				
	);

,Stop());&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Your feedback would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TS&lt;/P&gt;</description>
      <pubDate>Sun, 10 Feb 2019 19:03:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109781#M39694</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2019-02-10T19:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script (rename columns) feedback: it works but I'm not sure why!</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109789#M39700</link>
      <description>&lt;P&gt;Great that you want to learn JSL. It's really useful! And it's not that hard to get started &amp;nbsp;if you have experience of working in JMP interactively. Much of the JSL syntax then seems logical and straightforward. However, there's of course some quirky things such as the list returned by&amp;nbsp;&lt;EM&gt;Column Dialog().&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would probably used a non-modal New Window() as a control panel instead for this task.&lt;/P&gt;
&lt;P&gt;Below is an attempt to simplify your script, still using &lt;EM&gt;Column Dialog&lt;/EM&gt;. I use &lt;EM&gt;Eval List() &lt;/EM&gt;to execute the some of the assignement expressions of the output of &lt;EM&gt;Column Dialog,&lt;/EM&gt; which eliminates the need for extra variables.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Current Data Table();

cd = Column Dialog(
    src=ColList("SOURCES", Min Col(1)),
    trg = ColList("TARGETS", Min Col(1)),
    Line Up(2,
        Text Box("Prefix"), pfx = EditText("P_"),
        Text Box("Suffix"), sfx = EditText("_S")
    )
);
Eval List(cd[[1 2 4 6]]); //Execute relevant assignments within list cd
Show(src, trg, pfx, sfx); // Just to confirm (can be deleted)

n = N Items(src);
m = N Items(trg);

For(i = 1, i &amp;lt;= Min(n, m), i++,
    trg[i] &amp;lt;&amp;lt; Set Name(pfx || (src[i] &amp;lt;&amp;lt; get name) || sfx)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 00:21:01 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109789#M39700</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2019-02-11T00:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script (rename columns) feedback: it works but I'm not sure why!</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109880#M39748</link>
      <description>Hi MS,&lt;BR /&gt;Thank you for your feedback, it is very much appreciated&lt;BR /&gt;Best,&lt;BR /&gt;TS</description>
      <pubDate>Mon, 11 Feb 2019 19:24:21 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-rename-columns-feedback-it-works-but-I-m-not-sure-why/m-p/109880#M39748</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2019-02-11T19:24:21Z</dc:date>
    </item>
  </channel>
</rss>

