cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
HSS
HSS
Level IV

How to run a part of script or include a script based on a condition

Hi All,

I am trying to run a part of a script based on condition on a column. If that condition is failed, it should run other part of the script or include other script.

It seems very simple but I am not able to do that. I have followed two approaches - using  "include" function to call a script  and "Expr" function to call a part of the code. None is working. Any help here ?


1st Approach - 

dt = Data Table( "Data" ) << If ( PRODUCT == "A", include("C:\....\Script1.jsl"), include("C:\....\Script2.jsl"), );

This is not working while both scripts 1 and 2 are working independently. 

 

2nd Approach is similar to 1st but using "Expr", the way mentioned in - Sectioning or Segmenting Code in JSL 

Many thanks,

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to run a part of script or include a script based on a condition

I believe the issue you are having is in attempting to pass the If() statement to the data table.  What should work is

dt = Data Table( "Data" );
If ( PRODUCT == "A", include("C:\....\Script1.jsl"), include("C:\....\Script2.jsl"), );
Jim

View solution in original post

jthi
Super User

Re: How to run a part of script or include a script based on a condition

I think we might need a bit more information about what you are trying to do and what the "external" parts are. Include() and expressions should both work just fine if you are just running parts of some code.

Names Default To Here(1);

exprA = Expr(Show("A"));
exprB = Expr(Show("B"));

PRODUCT = "B";

If(PRODUCT == "A",
	exprA;
,
	exprB;
);
-Jarmo

View solution in original post

txnelson
Super User

Re: How to run a part of script or include a script based on a condition

I ran this code without error

Names Default To Here( 1 );

b = 1;

If( b == 1,
	Include( "path to one of the includes" ),
	Include( "path to the second include" )
);

The first include code was

a=1;
show(a);

The second include code was:

a=2;
show(a);

and it worked as expected

As @jthi has suggested you probably need to provide more information about the includes.

Jim

View solution in original post

7 REPLIES 7
txnelson
Super User

Re: How to run a part of script or include a script based on a condition

I believe the issue you are having is in attempting to pass the If() statement to the data table.  What should work is

dt = Data Table( "Data" );
If ( PRODUCT == "A", include("C:\....\Script1.jsl"), include("C:\....\Script2.jsl"), );
Jim
HSS
HSS
Level IV

Re: How to run a part of script or include a script based on a condition

Hi Nelson,

I have tried that as well. That is also not working.

jthi
Super User

Re: How to run a part of script or include a script based on a condition

I think we might need a bit more information about what you are trying to do and what the "external" parts are. Include() and expressions should both work just fine if you are just running parts of some code.

Names Default To Here(1);

exprA = Expr(Show("A"));
exprB = Expr(Show("B"));

PRODUCT = "B";

If(PRODUCT == "A",
	exprA;
,
	exprB;
);
-Jarmo
txnelson
Super User

Re: How to run a part of script or include a script based on a condition

I ran this code without error

Names Default To Here( 1 );

b = 1;

If( b == 1,
	Include( "path to one of the includes" ),
	Include( "path to the second include" )
);

The first include code was

a=1;
show(a);

The second include code was:

a=2;
show(a);

and it worked as expected

As @jthi has suggested you probably need to provide more information about the includes.

Jim
HSS
HSS
Level IV

Re: How to run a part of script or include a script based on a condition

Hello @txnelson  and @jthi,

Actually both of yours codes are working fine (and in fact, my own way is also working). The issue was with JMP session.  After few more attempts my JMP crashed and I gave up. Today after restarting the JMP, the same code is working fine. I believe it may be same memory/cache/path/variables issue with JMP session. Once it is restarted, it worked fine.

I am really thankful for both of yours support.

Reards, HSS

jthi
Super User

Re: How to run a part of script or include a script based on a condition

Happens from time to time. If you aren't already, I suggest starting all your scripts with

Names Default To Here(1);

It will provide you some protection against namespace collisions. This link is fairly helpful regarding Names Default To Here(1) (there is multiple pages)  Scripting Guide > Programming Methods > Advanced Scoping and Namespaces (jmp.com) 

-Jarmo
HSS
HSS
Level IV

Re: How to run a part of script or include a script based on a condition

Thanks Jarmo,

I learnt using 

Names Default To Here(1);


from Nelson (@txnelson) few years back and I do use it. I will have a look into the guideline again.
Thank you guys.