Button Box
Button Box using New Window
Summary: Creates a new window with MATLAB control interface, allowing users to initiate and terminate connections, and display the status of the connection.
Code:
//
nw_matlab =
New Window( "MATLAB Control Interface",
Button Box(
"Initiate Matlab Connection",
matconnect = MATLAB Connect();
MATLAB Init();
MATLAB Control( Visible( 1 ) );
MATLAB Submit( "close all" );
MATLAB Submit( "clear all" );
MATLAB Submit( "whos" );
tb_matlab_con_status <<
set Text( " Connected" ) <<
font color( "Green" );
),
V Center Box(
H List Box(
Text Box( " Status:" ),
tb_matlab_con_status =
Text Box(
" Not Connected",
<<font color( "Red" )
),
)
),
Button Box(
"Terminate Matlab Connection",
MATLAB Term();
tb_matlab_con_status <<
set Text( " Not Connected" ) <<
font color( "Red" );
),
);
Code Explanation:
- Create new window.
- Add initiate button.
- Connect to MATLAB.
- Initialize MATLAB.
- Show MATLAB control.
- Close all MATLAB figures.
- Clear all MATLAB variables.
- Display MATLAB workspace.
- Update status text.
- Set status color to green.
- Add status display.
- Add terminate button.
- Terminate MATLAB connection.
- Update status text.
- Set status color to red.
Button Box using Column
Example 1
Summary: Records state values in a data table, changing 'AL' and 'WY' to blank, and sets the combo box in the Recode window to the third option.
Code:
dt = Open("data_table.jmp");
Column( "state" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( "AL", " " );
recodeObj << Change Value( "WY", " " );
wrc = Window( "Recode - State" );
wrc[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc[Button Box( 4 )] << Click(),
wrc[Button Box( 6 )] << Click()
);
Code Explanation:
- Open data table.
- Select state column.
- Initiate recode operation.
- Change AL to blank.
- Change WY to blank.
- Access Recode window.
- Set combo box to third option.
- Check host operating system.
- Click OK button for Windows.
- Click OK button for non-Windows.
Example 2
Summary: Runs the recoding and window configuration process for a specific data table, replacing missing values with -25.5 and setting combo box and button values based on the host operating system.
Code:
dt = Open("data_table.jmp");
Column( dt, "Longitude" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( ., -25.5 );
wrc = Window( "Recode - Longitude" );
wrc[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc[Button Box( 4 )] << Click(),
wrc[Button Box( 6 )] << Click()
);
long = Column( dt, "Longitude" )[19];
Code Explanation:
- Open data table.
- Select "Longitude" column.
- Initiate recode operation.
- Replace missing values with -25.5.
- Access Recode window.
- Set combo box value to 3.
- Check host operating system.
- Click appropriate button based on OS.
- Retrieve value from "Longitude" column at row 19.
Example 3
Summary: Recoding process for 'Return' and sets values in number column edit boxes for 'Recode - Date' and 'Recode - Date/Time' windows.
Code:
dt = Open("data_table.jmp");
Column( dt, "Date" ) << Set Selected;
Column( dt, "Date/Time" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( 2881983600, 2913606000 );
recodeObj << Change Value( 2881990800, 2913613200 );
wrc1 = Window( "Recode - Date" );
wrc1[Number Col Edit Box( 1 )] << Set Values( [2981958400, 2982044800, 2982131200, 2982217600, 2982304000] );
wrc2 = Window( "Recode - Date/Time" );
wrc2[Number Col Edit Box( 1 )] << Set Values(
[2981983600, 2981990800, 2981998000, 2982005200, 2982012400, 2882019600, 2882026800, 2882034000, 2882070000, 2882077200, 2882084400,
2882091600, 2882098800, 2882106000, 2882113200, 2882120400, 2882156400, 2882163600, 2882170800, 2882178000, 2882185200, 2882192400,
2882199600, 2882206800, 2882242800, 2882250000, 2882257200, 2882264400, 2882271600, 2882278800, 2882286000, 2882293200, 2882329200,
2882336400, 2882343600, 2882350800, 2882358000, 2882365200, 2882372400, 2882379600]
);
wrc1[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc1[Button Box( 4 )] << Click(),
wrc1[Button Box( 6 )] << Click()
);
wrc2[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc2[Button Box( 4 )] << Click(),
wrc2[Button Box( 6 )] << Click()
);
date1 = Column( dt, "Date" ) << Get Values;
date2 = Column( dt, "Date/Time" ) << Get Values;
Code Explanation:
- Open data table.
- Select "Date" column.
- Select "Date/Time" column.
- Initiate recoding for "Return".
- Change specific value in recode object.
- Change another specific value in recode object.
- Access "Recode - Date" window.
- Set values in number column edit box.
- Access "Recode - Date/Time" window.
- Set multiple values in number column edit box.
Example 4
Summary: Recoding process for the 'Return' column based on the selected values in the 'Sex' column, and configures a Recode window with specific settings.
Code:
dt = Open("data_table.jmp");
Column( dt, "Sex" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( "F", "B" );
wrc1 = Window( "Recode - sex" );
wrc1[String Col Edit Box( 1 )] << Set Values( {"B", "A"} );
wrc1[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc1[Button Box( 4 )] << Click(),
wrc1[Button Box( 6 )] << Click()
);
Code Explanation:
- Open data table.
- Select "Sex" column.
- Initiate recode process.
- Change "F" to "B".
- Access Recode window.
- Set new values for recoding.
- Select recode method.
- Check host operating system.
- Click appropriate button on Windows.
- Click appropriate button on non-Windows.
Example 5
Summary: Runs the recoding and selection of columns in a JMP data table, utilizing the Recode function to change missing values and interactively selecting columns for deletion.
Code:
dt = Open("data_table.jmp");
Column( dt, "Longitude" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( ., -25.5 );
wrc = Window( "Recode - Longitude" );
wrc[Combo Box( 1 )] << Set( 3 );
dt << Select Columns( :Direction );
dt << Delete columns();
If( Host is( "windows" ),
wrc[Button Box( 4 )] << Click(),
wrc[Button Box( 6 )] << Click()
);
long = Column( dt, "Longitude" )[19];
Code Explanation:
- Open data table.
- Select "Longitude" column.
- Initiate recode operation.
- Change missing values to -25.5.
- Access Recode window.
- Set combo box to third option.
- Select "Direction" column.
- Delete selected column.
- Check host operating system.
- Click appropriate button based on OS.
Button Box using Run Script
Summary: Process of running a Bivariate script, recoding values, and configuring path diagram properties in JMP.
Code:
dt = Open("data_table.jmp");
biv = dt << Run Script( "Bivariate" );
biv << Automatic Recalc( 1 );
Column( dt, "Height" ) << Set Selected;
recodeObj = dt << Recode( “Return” );
recodeObj << Change Value( 51, 998 );
wrc = Window( "Recode - height" );
wrc[Combo Box( 1 )] << Set( 3 );
If( Host is( "windows" ),
wrc[Button Box( 4 )] << Click(),
wrc[Button Box( 6 )] << Click()
);
dt << Clear Column Selection;
bivMat = Report( biv )["Summary of Fit"][Table Box( 1 )] << Get as Matrix;
Code Explanation:
- Open data table.
- Run Bivariate script.
- Enable automatic recalculation.
- Select Height column.
- Initiate Recode platform.
- Change value 51 to 998.
- Access Recode window.
- Set combo box to option 3.
- Click appropriate button based on host OS.
- Clear column selection.
- Extract Summary of Fit matrix.
Button Box using Window
Example 1
Summary: Concatenates data tables using the Tables:Concatenate menu in JMP, with options to match all columns and append new data.
Code:
dt2 = Open("data_table.jmp");
Main Menu( "Tables:Concatenate" );
w = Window( "Concatenate" );
w[listboxbox( 1 )] << Set Selected( 1, 1 );
w[Button Box( 1 )] << Click;
w[checkboxbox( 1 )] << Set( 1, 1 );
w[checkboxbox( 2 )] << Set( 1, 1 );
w[checkboxbox( 3 )] << Set( 1, 1 );
w[Button Box( 3 )] << click;
Code Explanation:
- Open data table;
- Access Tables:Concatenate menu.
- Open Concatenate window.
- Select first item in listbox.
- Click OK button.
- Check Match All Columns option.
- Check Append option.
- Check Use Source Data Table Names option.
- Click Submit button.
Example 2
Summary: Concatenates two data tables using the Concatenate option in JMP, with options to include all columns, remove duplicates, and sort by original order.
Code:
dt1 = Open("data_table.jmp");
dt2 = Open("data_table.jmp");
Main Menu( "Tables:Concatenate" );
w = Window( "Concatenate" );
w[listboxbox( 1 )] << Set Selected( 1, 1 );
w[Button Box( 1 )] << Click;
w[checkboxbox( 1 )] << Set( 1, 1 );
w[checkboxbox( 2 )] << Set( 1, 1 );
w[checkboxbox( 3 )] << Set( 1, 1 );
w[Button Box( 3 )] << click;
Code Explanation:
- Open data table;
- Open data table;
- Access Concatenate option.
- Select Concatenate window.
- Set first listbox selection.
- Click OK button.
- Enable Include All Columns.
- Enable Remove Duplicates.
- Enable Sort by Original Order.
- Click Concatenate button.
Example 3
Summary: Concatenates two data tables and retrieves listbox items in a JMP script.
Code:
dt1 = Open("data_table.jmp");
dt2 = Open("data_table.jmp");
Main Menu( "Tables:Concatenate" );
w = Window( "Concatenate" );
w[Button Box( 5 )] << Click;
lblist = w[listboxbox( 1 )] << Get Items;
Code Explanation:
- Open data table;
- Open data table;
- Access Tables:Concatenate menu.
- Open Concatenate window.
- Click OK button.
- Retrieve listbox items.
Button Box using Collapse Whitespace
Summary: Creates and modifies data table columns, including setting formulas and logging operations.
Code:
dt = Open("data_table.jmp");
testLog = Collapse Whitespace( Trim( Log Capture( dt << New Column( "bad formula", numeric, Formula( :weight + :height2 ) ) ) ) );
dt << New Column( "bad formula 2" );
testLog = Collapse Whitespace( Trim( Log Capture( Column( dt, "bad formula 2" ) << Set Formula( :weight2 + :height3 ) ) ) );
Close( dt, "nosave" );
Delete Symbols( foo );
log = "";
dt = New Table( "d", Add Rows( 10 ), New Column( "x", Set Values( 1 :: 10 ) ) );
log = Collapse Whitespace( Log Capture( Column( "X" ) << Set Formula( If( Mod( Row(), 2 ) != 0, Foo(), 0 ) ) ) );
Column( "X" ) << Set Selected( 1 );
Main Menu( "Cols:Column Info" );
colInfo = Window( "x" );
colInfo[Button Box( 6 )] << Click;
log = Collapse Whitespace( Log Capture( Column( "X" ) << Set Formula( 2 ) ) );
Column( "X" ) << Set Selected( 1 );
Main Menu( "Cols:Column Info" );
colInfo = Window( "x" );
colInfo[Button Box( 6 )] << Click;
Close( dt, "nosave" );
log = "";
dt = New Table( "d", Add Rows( 10 ), New Column( "x", Set Formula( 2 ) ) );
dt:x << Ignore Errors( 1 );
Column( "X" ) << Set Selected( 1 );
Main Menu( "Cols:Column Info" );
colInfo = Window( "x" );
colInfo[Button Box( 6 )] << Click;
log = Collapse Whitespace( Log Capture( Column( "X" ) << Set Formula( If( Mod( Row(), 2 ) != 0, Foo(), 0 ) ) ) );
dt:x << Ignore Errors( 0 );
Column( "X" ) << Set Selected( 1 );
Main Menu( "Cols:Column Info" );
colInfo = Window( "x" );
colInfo[Button Box( 6 )] << Click;
log = Collapse Whitespace( Log Capture( Column( "X" ) << Set Formula( If( Mod( Row(), 2 ) != 1, Foo(), 1 ) ) ) );
Code Explanation:
- Open data table.
- Create new column "bad formula".
- Set formula for "bad formula".
- Log creation and formula setting.
- Create another new column "bad formula 2".
- Set formula for "bad formula 2".
- Log formula setting.
- Close table without saving.
- Delete symbol "foo".
- Initialize log variable.
Button Box using Pick Directory
Summary: Filters and selects files in a directory, allowing users to search for specific file names and open or save multiple files.
Code:
Names Default To Here( 1 );
//folder = Pick Directory ("Pick a Directory", "$SAMPLE_DATA");
folder = Get Default Directory(); //search scripts in this folder
filter_items = Function( {this, searchText},
{filtered_items, i},
// only attempt to filter if there is any text
If( searchText != "",
// new list for groups that match searchText
filtered_items = {};
// Check if each group matches the given text
For Each( {i}, 1 :: N Items( lstFilteredFiles ),
// Insert to our list if it contains our search text (case insensitive)
If( Contains( Lowercase( lstFilteredFiles[i] ), Lowercase( searchText ) ),
Insert Into( filtered_items, lstFilteredFiles[i] )
)
);
,
// else show all groups
filtered_items = lstJournals
);
lb << Set Items( filtered_items );
); // end filter_items function
lstFiles = Files In Directory( folder );
lstFilteredFiles = lstFiles;
/*lstExtensions = {};
For Each( {i}, lstFiles, Insert Into( lstExtensions, Word( -1, i, "." ) ) );
lstExtensions = associative array (lstExtensions) << Get Keys;*/
nw = New Window( "Files in Folder:",
//text box ("Demo Journals: " || char(n items (lstJournals))),
H List Box (
Text Box( " Filter:" ),
teb = Text Edit Box( "", <<set width( 200 ), <<set text changed( filter_items ) ),
Button Box( "", <<set icon( "DebuggerDeleteBreakpoint" ), <<Set Script( teb << set text( "" ); filter_items (lb, "") ) ),
),
lb = List Box( lstFilteredFiles, width( 400 ) ),
H List Box(
Button Box( "Open",
lstsel = lb << Get Selected;
For Each( {i}, lstsel, Open( "$DEMOS/Scripts/" || i ) );
)
)
);
Code Explanation:
- Set default names location.
- Get default directory.
- Define filter_items function.
- Initialize filtered_items list.
- Loop through lstFilteredFiles.
- Check if file contains search text.
- Add matching files to filtered_items.
- Set ListBox items to filtered_items.
- Get list of files in directory.
- Create new window with TextBox, TextEditBox, Button, ListBox, and Buttons.