我有一个看起来像这样的表格,我想做的是在“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 ) ) );