cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Using the Script Window, Next Steps

This recipe will demonstrate some of the lesser known but handy Script Editor features. Whether you’re new to JSL or have been scripting for a while, you may not be familiar with some of these features. We will use a modified version of the Extract Values from Report script found in the sample script directory that comes with JMP.


Ingredients:
  • Script Editor Window

Sample Script – Attached Below

Difficulty – Easy

Video Length – 3:50

Steps:
      1. Open the JSL script attached to this recipe.
      2. Reformat the script. Position the cursor inside the Script Editor window. Right click and select Reformat Script.
      3. Run the script. You’ll get an error message saying that a display box can't be subscripted.DonMcCormack_0-1648828080059.png

         

        The same details are written at the bottom of the log.

        DonMcCormack_1-1648828080061.png

        The mark /*###*/ is used to show where the error occurs. In most cases, a line number is also given.

      4. On line 18, StringBox is not colored blue because it isn’t recognized by JSL as a function or object. Position the cursor between String and Box and simultaneously press the CTRL and Space keys (Option+Esc on the Mac). This displays the Autocomplete window using the string to the left of the cursor. Select String Col Box and delete the second Box.

         

        Auto Complete needs at least one letter to the left of the cursor. Once the window is open, you can continue typing or scroll through the list.

      5. If we try running the script again, we will get the same error on line 18. Select the word StringBox and press CTRL-F (Command-F on the Mac) or select Edit > Search > Find. Find and Replace will let us do a global replace of this phrase with the correct one. One of the more powerful features of Find and Replace is the ability to use regular expressions. For example, the expression below would replace any occurrence of the consecutive words String and Box regardless of the amount of white between them. This is helpful if both StringBox and String Box appear in the script.DonMcCormack_2-1648828080062.png
      6. Brackets, parentheses, and braces all appear in pairs. The general term for these structures is fences. When fences become unbalanced, that is if one of the pair is missing, it may be difficult to locate exactly where the problem occurs.
        1. Delete the close parenthesis on line 45 and run the script. The error message identifies the missing fence as the problem but indicates the last line of the script as its location. DonMcCormack_3-1648828080063.png

           

          DonMcCormack_4-1648828080063.png
        2. Position the cursor between the close parenthesis and semicolon on line 46.  The open parenthesis on line 26 is identified as its match. DonMcCormack_5-1648828080067.png
        3. On line 25 position the cursor between the final “w” in Window and the open parenthesis. It is highlighted pink because there is no matching close parenthesis. DonMcCormack_6-1648828080068.png
        4. Double click the open parenthesis on line 26. Everything between it and its closing match is highlighted

          DonMcCormack_0-1648828885158.png

        5. Move the cursor to the end of line 28 and press CTRL and the right square bracket at the same time. Use Command and B on the Mac. Everything between the first opening parenthesis to the left of the cursor and its closing fence is highlighted.

          DonMcCormack_1-1648829154674.png

      7. Finally, its sometimes handy to split the script window so code in different parts of the script can be compared. To do this, right click and select Split > Horizontal or Split > Vertical.

DonMcCormack_0-1648828255636.png

 

DonMcCormack_1-1648828255651.png

 

 

Hints for Success

  • White space, particularly indentation, can make a script easier to read and debug. Use Reformat Script (right click in the script window) if the script is hard to read.
  • The Log window will identify the error and, in cases not involving unbalanced fences, the line on which it is located.
  • There are several tools for matching fences. Double clicking a fence and CTRL click (Command B on the Mac) inside fences mark the fenced area.
  • Regular expressions can be used with Search and Replace.
  • CTRL-space (Option-ESC on the Mac) launches the Autocomplete window.
  • You can split a script window horizontally or vertically from the right click menu.

 

Comments
BigBook

Hi, it seems that the key combination used for autocomplete conflict with other software's key combination setting, and nothing works when I try to use ctrl+space.

Is there any way to set other key combination to achieve code auto-completion?

Thanks!