我有一個看起來像這樣的表格,我想做的是在“Cup Color”列中搜索唯一值,然後有一個彈出窗口供用戶為每種獨特的杯子顏色輸入相應的口味。 .
| 杯子顏色 | 卡路里 | 品嚐 | 排行 | 測試員 |
| 藍色的 | 140 | 4個 | 2個 | 1個 |
| 綠色的 | 80 | 7 | 1個 | 4個 |
| 黃色的 | 200 | 2個 | 3個 | 6個 |
| 紫色的 | 130 | 3個 | 6個 | 4個 |
| 藍色的 | 140 | 3個 | 5個 | 2個 |
| 藍色的 | 140 | 4個 | 4個 | 3個 |
| 黃色的 | 200 | 5個 | 7 | 1個 |
一旦我們為每種杯子顏色設置了口味,我想添加一個新列,該列根據我們從用戶那裡獲得的輸入進行填充。
| 杯子顏色 | 卡路里 | 品嚐 | 排行 | 測試員 | 味道 |
| 藍色的 | 140 | 4個 | 2個 | 1個 | 櫻桃 |
| 綠色的 | 80 | 7 | 1個 | 4個 | 覆盆子 |
| 黃色的 | 200 | 2個 | 3個 | 6個 | 巧克力 |
| 紫色的 | 130 | 3個 | 6個 | 4個 | 真的很薄荷 |
| 藍色的 | 140 | 3個 | 5個 | 2個 | 櫻桃 |
| 藍色的 | 140 | 4個 | 4個 | 3個 | 櫻桃 |
| 黃色的 | 200 | 5個 | 7 | 1個 | 巧克力 |
我對 JSL 還是很陌生,過去幾個小時一直在論壇上尋找一些指導,但似乎無法將其拼湊在一起,我將不勝感激。
使用模態窗口是一種非常獨特的窗口類型。您必須遵守幾條規則。其中之一涉及帶有“確定”文本的按鈕框。它在模態窗口中具有特殊功能。所以你可以使用它們,但你需要研究它們,並用它們做一些練習。
我的偏好是不使用模態窗口,而是使用 Functions() 或 Expr() 元素來封裝代碼,使其在腳本指示應該運行之前不被執行。下面是一個如何做到這一點的簡單示例。
Names Default To Here( 1 );
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
//<< Modal,
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
runAdditionalCodePlease;
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );
runAdditionalCodePlease = Expr(
Dialog("This represents the kind of things that",
"you may want to run after the data entry.",
"By placing the code inside an Expr() or in",
"a Function(). The code will be run only",
"when executed within the code."
)
);我實際上需要我的腳本在進行之前等待用戶輸入。
我在腳本指南中發現我可以通過使用模態消息來做到這一點,並認為我已經正確添加了它,但是當我運行腳本時我現在表沒有更新 - 日誌顯示“名稱未解析:訪問中的按鈕或評估 'Button' , Button( 1 ) /*###*/"
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
<< Modal,
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );歡迎來到社區。
首先,我有一個關於如何加快你學習 JSL 的建議。
閱讀腳本指南!!!!
它可以在
幫助==>書籍==>腳本指南
下面是一個準系統腳本來完成你所要求的。
Names Default To Here( 1 );
dt = New Table( "Untitled 2",
Add Rows( 7 ),
New Column( "Cup Color",
Character,
"Nominal",
Set Selected,
Set Values( {"blue", "green", "yellow", "purple", "blue", "blue", "yellow"} )
),
New Column( "Calories",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [140, 80, 200, 130, 140, 140, 200] )
),
New Column( "Taste",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [4, 7, 2, 3, 3, 4, 5] )
),
New Column( "Ranking",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [2, 1, 3, 6, 5, 4, 7] )
),
New Column( "Tester",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 6, 4, 2, 3, 1] )
)
);
// Get the list of unique colors
Summarize( dt, colorList = by( :Cup Color ) );
// Initialize the flavor list and make it the same
// length as the colorList
flavorList = {};
For( i = 1, i <= N Items( colorList ), i++,
Insert Into( flavorList, "" )
);
// Create the display window
nw = New Window( "Select Flavors",
Text Box( "Enter in Flavors for each Color" ),
tb = Table Box(
String Col Box( "Colors", colorList ),
scb = String Col Edit Box( "Flavors", flavorList )
),
Button Box( "OK",
nw << close window;
// Create the flavor table and update it to
// the original table
dt2 = New Table( "combined",
New Column( "Cup Color", character, set values( colorList ) ),
New Column( "Flavors", character, set values( flavorList ) )
);
dt << Update( With( dt2 ), Match Columns( :Cup Color = :Cup Color ) );
close( dt2, nosave );
)
);
// Set the String Col Edit Box action
scb << Set Function( Function( {this, which}, flavorList[which] = scb << get( which ) ) );