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

JSL Cookbook - Archived

Building blocks of JSL code to reduce your coding workload.
Choose Language Hide Translation Bar

Latest Posts

  • Loops

    Problem You need to execute some JSL more than once. Solution Use a for(...) or while(...) or one of the more exotic variations.
    The for loop is the most common way to repeat some statements. Cars = {"Ford", "Chevy", "Tesla"}; // a list
    nCars = N Items( Cars );
    // notice loop starts at one and <= counts to the end
    For( iCar = 1, iCar <= nCars, iCar += 1,
    car = Cars[iCar]; // JSL lists are 1-based
    ...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    May 9, 2024 7:09 AM
    26890 views | 2 replies
  • Select rows that match any value in a list

    Problem Suppose you prompt a user to make a selection. When you retrieve the values from the user, typically they are stored in a list.  Now you need to select the data that matches the values in the list. Solution The following example demonstrates how you can select rows in a data table that contain any value stored in a JSL list. Lists containing either numeric values or character strings ca...

    Wendy_Murphrey Wendy_Murphrey
    JSL Cookbook - Archived |
    Dec 16, 2023 6:38 AM
    8270 views | 5 replies
  • Set and get credentials in the Credential Manager via PowerShell on Windows

    Access usernames and passwords without saving them in your script or code.

    ih ih
    JSL Cookbook - Archived |
    May 3, 2023 9:29 AM
    20596 views | 1 replies
  • Using Slider Boxes

    Problem You want to use a Slider Box to set a continuous value, and you want to see the current value as you move the slider. Solution Make a Slider Box and a Number Edit Box. Add a script to the Slider Box to update the Number Edit Box. Add a script to the Number Edit Box to update the Slider Box. Eggs = 50; Bacon = 50; New Window( "Slider Display", Border Box( Left( 10 ), Right( 10 ), top...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Jun 24, 2022 2:57 PM
    6872 views | 4 replies
  • Custom Table Calculator

    Problem You need to build a custom calculator that displays a table of numbers based on several input values. Solution Use Number Edit Boxes to get the values and use the Set Function method to attach JSL to the Number Edit Boxes to recalculate the table when the values are changed. Use a Table Box to hold columns of numbers. Rebuild the columns of numbers when the values change. Payment table ...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    May 17, 2022 9:25 PM
    2646 views | 3 replies
  • The All New JSL Cookbook II - Soliciting Input

    We are in the process of revamping the JSL Cookbook to give it broader appeal, make it better organized, and easier to use. The focus will be on short projects (recipes) to help you improve your JSL. The recipes will include step-by-step instructions, completed code and a demonstration video. The first recipes will focus will be on less than obvious aspects of common tasks. Later we will develop ...

    DonMcCormack DonMcCormack
    JSL Cookbook - Archived |
    May 5, 2022 9:04 AM
    2871 views | 10 replies
  • Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute

    Insert variables or expressions into other expressions.  This is a brief introduction to Eval(), Eval Expr(), Substitute(), Parse(), and Eval Insert().

    ih ih
    JSL Cookbook - Archived |
    Dec 20, 2021 7:52 AM
    17156 views | 10 replies
  • Looping through an Associative Array's elements

    ProblemYou need to look at every element in an Associative ArraySolutionuse the <<First and <<Next messages
    // load a table of elements dt = Open( "https://en.wikipedia.org/wiki/List_of_chemical_elements", HTML Table( 4, Column Names( 2 ), Data Starts( 5 ) ) ); // make an associative array using "H" to lookup "Hydrogen" and some of its properties map_Symbol_To_Data = Associative Array( dt[1 :: 118,...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Nov 28, 2021 11:10 AM
    5387 views | 5 replies
  • Select rows from the currently selected rows

    Problem Suppose your data table has a set of rows selected.  Now, you want to select rows from that selection that meet an additional condition. Solution The Select Where() message for the Data Table object offers an option that allows you to specify to select from the current selection. The following example demonstrates how to use the Current Selection() option to restrict the new selection t...

    Wendy_Murphrey Wendy_Murphrey
    JSL Cookbook - Archived |
    Jul 20, 2021 6:22 PM
    4148 views | 2 replies
  • Write Your Own Functions

    Problem You have some code that you want to call from more than one place, maybe with different arguments. Solution Use a user written function, with parameters, local variables to keep them away from other code, and a return statement to send back an answer. // this example shows how to write a user written function to roll // ndice with nsides // a user written function is created with an a...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Apr 20, 2021 10:54 AM
    14886 views | 3 replies
  • Convert Matrix to Data Table and Back

    Problem You have data in a Matrix and need a Data Table, or the other way 'round Data table or matrix? Solution There is a function, AsTable(), that makes a new data table from a matrix, and a data table method, GetAsMatrix(), that makes a matrix from the numeric columns in a table. There is also a way to index data tables directly with data table subscripting.
    // make a matrix of 5 rows, 3 col...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Mar 4, 2021 4:49 AM
    6340 views | 2 replies
  • Concatenate data tables

    Problem Concatenate data tables using Files in Directory, without using Multiple File Import   Solution Use Files in Directory to make a list and Concatenate to put them together.   // make a test directory dt = New Table( "Untitled", Add Rows( 1 ), New Column( "a" ), New Column( "b" ) ); path = "$TEMP/test/"; Delete Directory( path ); // Be careful! This will delete your files! Create Director...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Oct 30, 2020 9:29 AM
    6764 views | 4 replies
  • The stack mole

    Problem APIs and other machine generated code often delivers very complicated data structures. I found it helpful to have a tool that analyzes these structures and make them more accessible. Ideally, it would show the result as a graph. Solution So, I made this little script that crawls through stacked data collections reveals their hierarchy and shows it as a diagram. See my blog post for a mo...

    bernd_heinen bernd_heinen
    JSL Cookbook - Archived |
    Sep 8, 2020 12:45 AM
    1342 views | 0 replies
  • The Crude MapQuest Call

    Get the code to submit a call to MapQuest REST APIs

    bernd_heinen bernd_heinen
    JSL Cookbook - Archived |
    Sep 8, 2020 12:08 AM
    871 views | 0 replies
  • A Geo-coding function

    Get geo-codes from MapQuest without the need to care about details of the interface.

    bernd_heinen bernd_heinen
    JSL Cookbook - Archived |
    Sep 7, 2020 11:47 PM
    941 views | 0 replies
  • A routing function

    Get routing information from MapQuest without the need to care about details of the interface.

    bernd_heinen bernd_heinen
    JSL Cookbook - Archived |
    Sep 7, 2020 11:12 PM
    1009 views | 0 replies
  • Using Loc with a 2D Matrix

    Problem You have a 2D matrix. You used the Loc function to locate interesting elements, but Loc returned indexes for a 1D matrix. How can you convert the 1D indexes back to 2D indexes? Solution You'll need to use the Floor and Mod functions and you'll need to know the number of columns in your 2D matrix. Here's the three lines, buried in the commented example below. pixmat is a 2D matrix, Loc i...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Jun 9, 2020 3:26 AM
    3571 views | 1 replies
  • Vertical Normal Distribution Polygon Shape (Graphics Scripting)

    ProblemI wanted to create this figure for a publication SolutionTo create the vertically oriented shaded/filled and truncated normal curves, I utilized the Polygon() graphics function.  The challenge was to easily and repeated be able to create that polygon that was scaled and located appropriately on a graph.    I did this using this function func_VNormalShape = Function( // create a polygon that...

    MathStatChem MathStatChem
    JSL Cookbook - Archived |
    Jun 3, 2020 3:28 AM
    1392 views | 0 replies
  • C++ Programmer's Guide to JSL

    Problem You know some C++ and have some idea what a C++ object is and need the 20 minute intro to JMP's scripting language.   Solution There is a JMP scripting index on the Help menu. It describes, together or separately, Functions, DisplayBoxes, and Objects. As you dig deeper, use the search it provides.JSL does not have typed variables; there is not a way to declare a double, float, int, or bo...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Feb 21, 2020 7:55 AM
    5092 views | 2 replies
  • Open a file in the operating system default program

    Problem If you need to open a file in an external program, typically the JSL Open() function will work for you. However, if you want to open a file type that JMP knows how to import, you will probably end up with the file imported instead of opened in the external program. Opening an Excel file is a common use case for this. Solution To do this, we can use the JSL RunProgram() function. Windows...

    Justin_Chilton Justin_Chilton
    JSL Cookbook - Archived |
    Feb 5, 2020 10:17 AM
    1940 views | 0 replies
  • Detecting macOS Dark Mode and Windows High Contrast Mode

    Problem When creating user interfaces in JMP, you may want to add some background or foreground colors to your displays. However, with JMP 15's new support for macOS Dark Mode and Windows High Contrast Mode, you need a way to detect if the user is in a dark or light appearance mode in order to have legible content. For example, you wouldn't want to set a light color as a background color or a dar...

    Justin_Chilton Justin_Chilton
    JSL Cookbook - Archived |
    Feb 5, 2020 10:10 AM
    1937 views | 0 replies
  • Sorting Lists

    ProblemYou have data in one or more lists or matrix vectors that you need to sort.SolutionUse Sort List() or Sort List Into(), Rank(), or put the lists and vectors in a data table and sort it. // Sort List example (makes new list) names = {"fred", "Andy", "Rory", "bess", "susy", "perl"}; sname = Sort List( names ); Show( names, sname );names = {"fred", "Andy", "Rory", "bess", "susy", "perl"}; // u...

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Jan 17, 2020 9:06 AM
    4212 views | 0 replies
  • Select rows based upon multiple conditions

    Problem Suppose you wish to select rows in a data table that meet more than one condition. Or, maybe you want to select the rows that meet one of a few conditions.   Solution The following examples demonstrate how you can use the logical AND (&) and OR (|) operators with the Select Where message to select rows that meet multiple conditions.  See the embedded comments for details.    /* Open a s...

    Wendy_Murphrey Wendy_Murphrey
    JSL Cookbook - Archived |
    Aug 13, 2019 1:43 PM
    6535 views | 2 replies
  • Get a list of the unique values in a column, matrix, or list

    ProblemProblem 1:  I need to get a list of the unique values in a data table column.Problem 2:  I need to get a list of the unique values in a JSL data structure (list or matrix)SolutionFor problem 1:Solution 1:  Use summary tables.  The JSL below shows how to use Summary() to get a table that will have a row with each unique value in a single column.   You can then do further JSL table commands t...

    MathStatChem MathStatChem
    JSL Cookbook - Archived |
    Aug 8, 2019 1:55 AM
    11806 views | 1 replies
  • Use Summary to Automatically Add Reference Lines to Graph Builder

    reference lines automatically added using JSL

    Craige_Hales Craige_Hales
    JSL Cookbook - Archived |
    Jan 4, 2019 3:30 AM
    5461 views | 1 replies
JSL Cookbook

If you’re looking for a code snippet or design pattern that performs a common task for your JSL project, the JSL Cookbook is for you.

This knowledge base contains building blocks of JSL code that you can use to reduce the amount of coding you have to do yourself.

It's also a great place to learn from the experts how to use JSL in new ways, with best practices.