- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
For loop in New Window
Hi! I am a very beginner JMP user, and am having trouble with getting my for loop to work. I am trying to ask the user what type of factor each of their factors are. The number of times the question is asked depends on the number of coloumns in the jmp file. I was attempting to use a radio box, but am having trouble with the appending. Below is little snapshot of what I have done. Thanks!
Names Default to Here(1);
dt = Open("Example1.jmp");
number = ncols(dt);
FactorType = {"Continuous", "Categorical"};
New Window("Data Entry", << Modal, << return results,
Text Box("Type of Factor");,
type= V list Box(),
);
For(i= 1, i <= number, i++,
type << Append(Radio Box(FactorType, Max Selected(1)));
);
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Hi @dg1,
You're doing everything correctly! But, your use of <<Modal is inhibiting your script from functioning correctly. With a modal window, the remaining script is not executed until the OK button is clicked. If you remove <<modal your script will operate just fine, or alternatively, you can move the For() into the window statement.
Names Default To Here( 1 );
dt = Open("Example1.jmp");
number = N Cols( dt );
FactorType = {"Continuous", "Categorical"};
New Window( "Data Entry",
<<Modal,
<<return results,
Text Box( "Type of Factor" ),
type = V List Box(),
For( i = 1, i <= number, i++,
type << Append( Radio Box( FactorType, Max Selected( 1 ) ) )
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Hi again @dg1,
Just to follow up, I looked a little more closely at your code and there were a few places where I think you'll hit a snag. The biggest is unloading the results. Each of your RadioBox() objects should have a handle so you can reference them later to grab the data. Below is one way to do that, that assigns the reference to a list, and then later steps through that list of references, sends the message to get the selected item, and stores the result to another list. This all happens when the OK button is clicked.
Names Default To Here( 1 );
dt = Current Data Table();
number = N Cols( dt );
rbList = {};
rbResult = {};
FactorType = {"Continuous", "Categorical"};
win = New Window( "Data Entry",
<<Modal,
type = V List Box(),
Button Box( "OK",
For( i = 1, i <= number, i++,
rbResult[i] = rbList[i] << Get Selected
);
win << close window;
),
For( i = 1, i <= number, i++,
type << Append( Text Box( "Type of Factor" ) );
type << Append( rbList[i] = Radio Box( FactorType ) );
);
);
Print( rbResult );
If you haven't yet, I highly suggest you read the JMP Scripting Guide, Help > Books > Scripting Guide. It will be invaluable as you learn the language and the operations necessary to have a script work as you want. Also, I really enjoyed the book JSL Companion: Applications of the JMP Scripting Language. I would start with the Scripting Guide because it is included free in JMP, but the JSL Companion does provide a structured introduction to using JSL through a series of practical applications (and all the code is included).
Hope this helps you along your way! Enjoy!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Hi @dg1,
You're doing everything correctly! But, your use of <<Modal is inhibiting your script from functioning correctly. With a modal window, the remaining script is not executed until the OK button is clicked. If you remove <<modal your script will operate just fine, or alternatively, you can move the For() into the window statement.
Names Default To Here( 1 );
dt = Open("Example1.jmp");
number = N Cols( dt );
FactorType = {"Continuous", "Categorical"};
New Window( "Data Entry",
<<Modal,
<<return results,
Text Box( "Type of Factor" ),
type = V List Box(),
For( i = 1, i <= number, i++,
type << Append( Radio Box( FactorType, Max Selected( 1 ) ) )
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Hi @dg1,
It appears to be showing up for me at the top of the window, but just the once as you have it programmed. If you want one textbox for each column selection, you could do another append in each iteration of your for() loop:
Names Default To Here( 1 );
dt = Open("Example1.jmp");
number = N Cols( dt );
FactorType = {"Continuous", "Categorical"};
New Window( "Data Entry",
<<Modal,
<<return results,
type = V List Box(),
For( i = 1, i <= number, i++,
type << Append( Text Box( "Type of Factor" ) );
type << Append( Radio Box( FactorType, Max Selected( 1 ) ) );
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Hi again @dg1,
Just to follow up, I looked a little more closely at your code and there were a few places where I think you'll hit a snag. The biggest is unloading the results. Each of your RadioBox() objects should have a handle so you can reference them later to grab the data. Below is one way to do that, that assigns the reference to a list, and then later steps through that list of references, sends the message to get the selected item, and stores the result to another list. This all happens when the OK button is clicked.
Names Default To Here( 1 );
dt = Current Data Table();
number = N Cols( dt );
rbList = {};
rbResult = {};
FactorType = {"Continuous", "Categorical"};
win = New Window( "Data Entry",
<<Modal,
type = V List Box(),
Button Box( "OK",
For( i = 1, i <= number, i++,
rbResult[i] = rbList[i] << Get Selected
);
win << close window;
),
For( i = 1, i <= number, i++,
type << Append( Text Box( "Type of Factor" ) );
type << Append( rbList[i] = Radio Box( FactorType ) );
);
);
Print( rbResult );
If you haven't yet, I highly suggest you read the JMP Scripting Guide, Help > Books > Scripting Guide. It will be invaluable as you learn the language and the operations necessary to have a script work as you want. Also, I really enjoyed the book JSL Companion: Applications of the JMP Scripting Language. I would start with the Scripting Guide because it is included free in JMP, but the JSL Companion does provide a structured introduction to using JSL through a series of practical applications (and all the code is included).
Hope this helps you along your way! Enjoy!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: For loop in New Window
Is putting a for-loop in a new window function call really legitimate? My view is that you shouldn't stick JSL in places where display boxes are expected, even if the code runs. For a modal window, the JSL can be placed in the OnOpen event handler.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content