Force User to Provide Input Within RangeHi, I'm fairly new to JMP and I'm not sure how to write a script that throws an error to prevent the user from inputting an invalid number. I want the user to input a number that is eventually saved into a variable but re-prompt for input if the number is outside the range 1-4.
This is what I have so far without any error checking:
Names Default To Here (1);
num = 0;
w = New Window( "Prompt",
<<MODAL></MODAL>
Any help or suggestions on accomplishing this would be appreciated!
Quality and Process EngineeringRe: Force User to Provide Input Within RangeJust add a close window after the function call.
b1 = button box("First Program",
program1();
nw << close window();
),
Re: Force User to Provide Input Within RangeThat works perfectly! Thanks again!
Re: Force User to Provide Input Within RangeIf you have additional code after the New Window, you could change the new window to modal window with << modal (might require some other small changes). This example will also close the modal window if any of the program buttons is pressed by using <
nw = new window("Test Options", << modal,
panel box("Click the button to run the desired program",
lineup box(ncol(1),
b1 = button box("First Program",
program1();
okBtn << Click();
),
b2 = button box("Second Program",
program2();
okBtn << Click();
),
b3 = button box("Third Program",
program3();
okBtn << Click();
),
b4 = button box("Fourth Program",
program4();
okBtn << Click();
),
),
),
h list box(okbtn = Button Box("OK"), cancelBtn=ButtonBox("Cancel"))
);
Show("shouldnt execute before window is closed");Re: Force User to Provide Input Within RangeRe-edit: It actually seems that any code coming after the button execution within the new window is running BEFORE the programs linked to the button for some reason. Does anyone know why this is happening?
Re: Force User to Provide Input Within RangeThat's great! I think that would work for my purposes, thanks for sharing! Lastly, this is not a super important functionality, but do you know if there is a way to press the button which executes the program and then the window closes automatically without the user pressing 'exit' ?
Re: Force User to Provide Input Within RangeIf you reference files on a fileshare that all users can access it would work.
You could also include the programs to run in the main JSL code itself as separate functions. Here's an example:
// First program
program1 = function({},
show("Running program1");
// JSL code for first program
);
// Second program
program2 = function({},
show("Running program2");
// JSL code for second program
);
// Third program
program3 = function({},
show("Running program3");
// JSL code for third program
);
// Fourth program
program4 = function({},
show("Running program4");
// JSL code for fourth program
);
nw = new window("Test Options",
panel box("Click the button to run the desired program",
lineup box(ncol(1),
b1 = button box("First Program",
program1();
),
b2 = button box("Second Program",
program2();
),
b3 = button box("Third Program",
program3();
),
b4 = button box("Fourth Program",
program4();
),
),
),
bexit = button box("Exit",
nw << close window();
),
);
Take a look at the JSL documentation for more information on functions.
Re: Force User to Provide Input Within RangeHi! That's a great approach to the problem. I am wondering though, would I be able to share all of the program scripts so anyone with the codes can run the same programs linked to the buttons? Or would it not be possible if the file directory paths would be unique to anyone who downloads the .jsl scripts?
Re: Force User to Provide Input Within RangeIf you want to run different programs depending on what users select (1-4), I would use buttons instead. Here's what it would look like:

Here's the code. Note that I'm using panel box to surround the buttons, and lineup box to align both sides of the button boxes. The programs to be run are stored in c:\myfiles, and are called program1.jsl, program2.jsl etc. Change the folder and JSL program names to suit your situation.
nw = new window("Test Options",
panel box("Click the button to run the desired program",
lineup box(ncol(1),
b1 = button box("First Program",
include("c:\myfiles\program1.jsl");
nw << close window();
),
b2 = button box("Second Program",
include("c:\myfiles\program2.jsl");
nw << close window();
),
b3 = button box("Third Program",
include("c:\myfiles\program3.jsl");
nw << close window();
),
b4 = button box("Fourth Program",
include("c:\myfiles\program4.jsl");
nw << close window();
),
),
),
bexit = button box("Exit",
nw << close window();
),
);Re: Force User to Provide Input Within RangeThanks so much again, super helpful!
Re: Force User to Provide Input Within RangeThat should be same, but it does look a bit weird. Using the modal example from Scripting Index:
This part is basically condition1 of the if:
ex = New Window("Dialog() example",
<<MODAL></MODAL>And this is the result1
ex["variable"]
and returnElse:
"CANCEL"
And because those results and basically last lines which will be executed depending on the if condition result, they will be printed to Log. You can test this by following two short scripts:
a = 1; //will print 1 to Log as this is the only and last row in script
a = 1;
Write(); //will print this as it is the last row of code
And if you did mean how ex variable works, you can fairly easily check it by running the example in scripting index and add Show(ex) in the end.
Below is an example with the if statement made a bit more clear by adding brackets and comments and I also added Show() for ex variable:
Names Default To Here(1);
If(
( //condition1 starts
ex = New Window("Dialog() example",
<<MODAL></MODAL>(note due to the Show() "CANCEL" isn't the last line of code when Cancel is pressed and it won't get printed, this will also show you that the variable value will be updated even if cancel is pressed)
Hopefully I did explain everything correctly. You can find more info from JMP Help and Scripting Guide: Construct a Modal Window
Re: Force User to Provide Input Within RangeThat's perfect! Thank you so much! :^)
For learning purposes, what does the end of the code mean? I know usually its If(condition 1, result 1, condition 2, result 2, ..... resultElse); but I'm not familiar with this:
ex["button"] == 1;
,
ex["variable"],
"CANCEL
Re: Force User to Provide Input Within RangeI think you can use << On Validate() for that.
Names Default To Here(1);
If(
ex = New Window("Dialog() example",
<<MODAL></MODAL>
Edit:
Or did you mean greying out/disabling the button?
Names Default To Here(1);
If(
ex = New Window("Dialog() example",
<<MODAL></MODAL>Re: Force User to Provide Input Within RangeThat's a good idea! Unfortunately with this, if the user accidentally types in 6 but really wanted to type 3 instead, their input will have been automatically chosen as 4. Sorry if the problem's a bit complicated.
Re: Force User to Provide Input Within RangeWould there be a way to prevent the user from pressing the OK button and exiting the window unless the value was 1-4? I think as it is, the user can exit the window and the input will be set to 0.
Re: Force User to Provide Input Within RangeHadn't seen this earlier (or have and have forgotten about it). Using << Set Minimum and << Set Maximum:
Names Default To Here (1);
num = 1;
w = New Window( "Prompt",
<<MODAL></MODAL>
Re: Force User to Provide Input Within RangeWouldn't it be simpler to use Radio Box for implementation like that?
Names Default To Here(1);
New Window("Example", rb = Radio Box({"True", "False", "None of the above"}, Print("Selection Changed")));Re: Force User to Provide Input Within RangeHi, thanks so much for the reply! I would like to make it so the user is forced to chose a number in range rather than have the code adjust to the user's mistake. For example, I'm thinking each number will tie to a piece of code that will be run.
Names Default To Here (1);<BR />num = 0;<BR />w = New Window( "Prompt",
<<MODAL></MODAL>
Then afterwards, I will code an if statement where if input == 1, run this code, if input == 2, run a different piece of code and so forth. So for my situation, I don't want the number to auto-correct to 1 or 4 if out of range. Sorry if that was confusing!
Re: Force User to Provide Input Within RangeYou can use a Number Edit Box and set lower and upper bounds for the input, and even declare if the bounds are valid or not. You do not need to write an expression or a function to check. It is built into this display box already.
Re: Force User to Provide Input Within RangeHere is a modification of your code that handles the requirement to only allow values 1-4
Names Default To Here( 1 );
num = 0;
input = 0;
w = New Window( "Prompt",
<<MODAL> 4 | str1 << get < 1,
str1 << set( 0 )
)
)
)
),
H List Box( Button Box( "Cancel" ), Button Box( "OK" ) )
),
);
If( w["button"] == 1,
input = w["str1"]
);
Show( input );</MODAL>Re: Force User to Provide Input Within RangeYou could use set function in some way.
Below is an example where the value is set to 1 if user tries to input value below 1 and to 4 if user inputs above 4
Names Default To Here (1);
num = 1;
w = New Window( "Prompt",
<<MODAL> 4, this << set(4)
);
))
)
),
);
input = w["str1"];
show(input);</MODAL>