turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Dialog and column formula scripting problems

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 27, 2016 9:09 AM
(2258 views)

I am working on scripting a repetitive analysis process. Part of this process will require the user to input a series of weights for different samples. To do this I want to use a dialog window since the weights change every time we run the process.

For example lets say I have the following data set (Image on the right). I need to the standardize my Y measurements to the sample weights that the user inputs. So I wrote the following script to get the weights from the user and unload the values from the dialog box. Now I want to create a new column where the value in Y is divided by the appropriate sample weight. So I want the first six columns (Sample A1) to all be divided by the weight A1 from the dialog window but I am stuck trying to figure out how to script this. I'm fairly new to scripting so suggestions would be really helpful.

dlg = Dialog**(**

** **"Enter Sample Weights",

Lineup**(** **1**,

"A1",

a1 = edit number**(** **12** **)**,

"A2",

a2 = edit number**(** **12** **)**,

"B1",

b1 = edit number**(** **12** **)**,

"B2",

b2 = edit number**(** **12** **)**,

"C1",

c1 = edit number**(** **12** **)**,

"C2",

c2 = edit number**(** **12** **)**,

Button**(** "OK" **)**,

Button**(** "Cancel" **)**

** **** **;

a1 = dlg**[**"a1"**]**;

a2 = dlg**[**"a2"**]**;

b1 = dlg**[**"b1"**]**;

b2 = dlg**[**"b2"**]**;

c1 = dlg**[**"c1"**]**;

c2 = dlg**[**"c2"**]**;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 27, 2016 10:55 AM
(4326 views)

Solution

This should do the trick. I'm using New Window instead of Dialog, as Phil suggested. Rather than a column formula I'm simply looping over the table rows. If you need a formula let us know.

dt = New Table**(** "Sample Weights", Add Rows**(** **7** **)**,

New Column**(** "Sample", Character, "Nominal",

Set Values**(** **{**"A1", "A1", "A2", "B1", "B2", "C1", "C2"**}** **)**

**)**,

New Column**(** "Y", Numeric, "Continuous", Format**(** "Best", **12** **)**,

Set Values**(** **[****1.3**, **3.2321**, **1.005**, **3.2321**, **4.1221**, **2.931**, **1.32]** **)**

**)**

**)**;

nw = New Window**(**"Sample Weights", << **modal()**,

panelbox**(**"Enter Sample Weights",

lineup box**(**ncol**(2)**,

textbox**(**"A1"**)**, a1_neb = numbereditbox**(12)**,

textbox**(**"A2"**)**, a2_neb = numbereditbox**(12)**,

textbox**(**"B1"**)**, b1_neb = numbereditbox**(12)**,

textbox**(**"B2"**)**, b2_neb = numbereditbox**(12)**,

textbox**(**"C1"**)**, c1_neb = numbereditbox**(12)**,

textbox**(**"C2"**)**, c2_neb = numbereditbox**(12)**,

**)**,

**)**,

panelbox**(**"Actions",

hlistbox**(**

button box**(**"OK",

keep_going = **1**;

a1 = a1_neb << **get**;

a2 = a1_neb << **get**;

b1 = a1_neb << **get**;

b2 = a1_neb << **get**;

c1 = a1_neb << **get**;

c2 = a1_neb << **get**;

**)**,

button box**(**"Cancel", keep_going = **0**;**)**,

**)**,

**)**

**)**;

dt << **new column(**"Y Div", numeric, continuous**)**;

// EDIT: Forgot to use the keep going flag

if **(**keep_going,

// Create a new column with the dialog box results

for **(**i = **1**, i <= nrows**(**dt**)**, i++,

one_sample = dt:sample**[**i**]**;

if **(**one_sample == "A1", dt:ydiv**[**i**]** = dt:y**[**i**]** / a1;,

one_sample == "A2", dt:ydiv**[**i**]** = dt:y**[**i**]** / a2;,

one_sample == "B1", dt:ydiv**[**i**]** = dt:y**[**i**]** / b1;,

one_sample == "B2", dt:ydiv**[**i**]** = dt:y**[**i**]** / b2;,

one_sample == "C1", dt:ydiv**[**i**]** = dt:y**[**i**]** / c1;,

one_sample == "C2", dt:ydiv**[**i**]** = dt:y**[**i**]** / c2;

**)**

**)**;

**)**;

4 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 27, 2016 10:50 AM
(2163 views)

What version of JMP are you using? Dialog has been deprecated for some time now. I would suggest using **New Window()** instead of Dialog and **NumberEditBox()** instead of EditNumber.

PDB

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 28, 2016 8:32 AM
(2163 views)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 27, 2016 10:55 AM
(4327 views)

This should do the trick. I'm using New Window instead of Dialog, as Phil suggested. Rather than a column formula I'm simply looping over the table rows. If you need a formula let us know.

dt = New Table**(** "Sample Weights", Add Rows**(** **7** **)**,

New Column**(** "Sample", Character, "Nominal",

Set Values**(** **{**"A1", "A1", "A2", "B1", "B2", "C1", "C2"**}** **)**

**)**,

New Column**(** "Y", Numeric, "Continuous", Format**(** "Best", **12** **)**,

Set Values**(** **[****1.3**, **3.2321**, **1.005**, **3.2321**, **4.1221**, **2.931**, **1.32]** **)**

**)**

**)**;

nw = New Window**(**"Sample Weights", << **modal()**,

panelbox**(**"Enter Sample Weights",

lineup box**(**ncol**(2)**,

textbox**(**"A1"**)**, a1_neb = numbereditbox**(12)**,

textbox**(**"A2"**)**, a2_neb = numbereditbox**(12)**,

textbox**(**"B1"**)**, b1_neb = numbereditbox**(12)**,

textbox**(**"B2"**)**, b2_neb = numbereditbox**(12)**,

textbox**(**"C1"**)**, c1_neb = numbereditbox**(12)**,

textbox**(**"C2"**)**, c2_neb = numbereditbox**(12)**,

**)**,

**)**,

panelbox**(**"Actions",

hlistbox**(**

button box**(**"OK",

keep_going = **1**;

a1 = a1_neb << **get**;

a2 = a1_neb << **get**;

b1 = a1_neb << **get**;

b2 = a1_neb << **get**;

c1 = a1_neb << **get**;

c2 = a1_neb << **get**;

**)**,

button box**(**"Cancel", keep_going = **0**;**)**,

**)**,

**)**

**)**;

dt << **new column(**"Y Div", numeric, continuous**)**;

// EDIT: Forgot to use the keep going flag

if **(**keep_going,

// Create a new column with the dialog box results

for **(**i = **1**, i <= nrows**(**dt**)**, i++,

one_sample = dt:sample**[**i**]**;

if **(**one_sample == "A1", dt:ydiv**[**i**]** = dt:y**[**i**]** / a1;,

one_sample == "A2", dt:ydiv**[**i**]** = dt:y**[**i**]** / a2;,

one_sample == "B1", dt:ydiv**[**i**]** = dt:y**[**i**]** / b1;,

one_sample == "B2", dt:ydiv**[**i**]** = dt:y**[**i**]** / b2;,

one_sample == "C1", dt:ydiv**[**i**]** = dt:y**[**i**]** / c1;,

one_sample == "C2", dt:ydiv**[**i**]** = dt:y**[**i**]** / c2;

**)**

**)**;

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Sep 28, 2016 8:33 AM
(2163 views)