Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
jimmsky
Level I

Execute a custom function when the condition satisfied in nested if


Once the condition satisfied only one function are executed which exports  graphs into a window instead of multiple functions based on the condition.
Here's my sample code :

 

 

//list box
graph_chk_val = chk_graph << get selected;
tab_chk_val = chk_tab << get selected;
anal_chk_val = chk_analysis << get selected;
list_selected = graph_chk_val || tab_chk_val || anal_chk_val;

For( i = 1, i <= N Items( list_selected ), i++,
    If(
        "SDET Chart" == list_selected[i], Show( "SDET" ),
        "Sensitiviity" == list_selected[i], sens_graph_exe(),
        "Sensitivity CDF" == list_selected[i], sens_cdf_graph_exe(),
        "Parametric Boxplot" == list_selected[i], parametric_boxplot_graph_exe(),
    )
);

 

 

6 REPLIES 6
Highlighted
ih
ih
Level VII

Re: Execute a custom function when the condition satisfied in nested if

I am not sure I understand what you are trying to achieve here; what part of your code is not working? Do you want to combine sens_graph_exe and sens_cdf_graph_exe into a single function?

Highlighted
jimmsky
Level I

Re: Execute a custom function when the condition satisfied in nested if

thank you for your response, the code and the function are working, the result that I want, is to execute all the  function  that satisfies the condition, but  only one function is called. I tried to debug using print("function1") in every condition, and they are all working, but when i use a function, only the first selected function are called.

Highlighted
jimmsky
Level I

Re: Execute a custom function when the condition satisfied in nested if

I think it is because i use 1 datatable for all the function which creates graph and make a data analysis, but when i called them without using a nested if statement they are all working.

Highlighted
ih
ih
Level VII

Re: Execute a custom function when the condition satisfied in nested if

Here is your code along with a simple window containing check boxes.  When I run this I get one formula evaluation per box that is checked.  Is this your expected behavior?

names default to here(1);

//Window with check boxes
win = New Window( "Check Boxes",
	h list box(
		chk_graph = check box( { "A", "B" } ),
		chk_tab = check box( { "C", "D" } ),
		chk_analysis = check box( { "E", "F" } )
	);
);

//get check box values
graph_chk_val = chk_graph << get selected;
tab_chk_val = chk_tab << get selected;
anal_chk_val = chk_analysis << get selected;
list_selected = graph_chk_val || tab_chk_val || anal_chk_val;

//For each list item
For( i = 1, i <= N Items( list_selected ), i++,
    Write( "\!NList Item " || char(i) || ": " );
    
    //Evaluate a single function based on the item's value
    If(
        "A" == list_selected[i], Write( "A" ),
        "B" == list_selected[i], Write( "B" ),
        "C" == list_selected[i], Write( "C" ),
        "D" == list_selected[i], Write( "D" ),
        "E" == list_selected[i], Write( "E" ),
        "F" == list_selected[i], Write( "F" )
    )
);
Highlighted
jimmsky
Level I

Re: Execute a custom function when the condition satisfied in nested if

No.

Highlighted
ih
ih
Level VII

Re: Execute a custom function when the condition satisfied in nested if

 Can you explain what you do expect to happen in this example, perhaps by explaining what you would expect to show up in the log and in which order?  I apologize as I do not understand what you are trying to do.

Article Labels