将列名作为参数传递给函数 - 是否与 : 连接?下面是一个函数,我试图在其中传递列名以绘制分布,但它不起作用。 我想知道什么是正确的语法?
Names Default To Here (1);
getDistChart = Function({ColName}, {dC},
dC = Distribution( Continuous Distribution( Column( :ColName) ) );
return(dC);
);
//gt = getDistChart ("MyCol"); to test the function
我已经打开了以 MyCol 作为列名的数据表。 我想知道是否需要串联
:
与列名
ColName
如果是这样(因为与 || || 的正常连接似乎不起作用)?
数据表脚本回复:将列名作为参数传递给函数 - 是否与 : 连接?谢谢@马克贝利这行得通。
回复:将列名作为参数传递给函数 - 是否与 : 连接?是的,它非常适合我使用 JMP Pro 16.1.0。 我没有安装任何早期版本的 JMP 进行测试。 您的版本大约有 5 年历史。 JSL 在不断发展,因此我的语法可能不适用于早期版本。
您可以联系 JMP 技术支持 (支持@jmp.com ) 求助。
您也可以尝试使用表达式来完成您想要的。 自版本 4 起,它们适用于任何版本的 JMP。 查看此版本是否有效:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName, _LSL, _USL}, {distChart},
Eval(
Substitute(
Expr(
distChart = New Window( "" || ColName || " distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column( As Column( ColName ) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL( _LSL ), USL( _USL ) )
),
SendToReport(
Dispatch(
{ ccc },
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
)
);
),
Expr( ccc ), colName
)
);
Return( distChart );
);
getDistChart( "weight", 55, 185 );回复:将列名作为参数传递给函数 - 是否与 : 连接?@马克贝利谢谢。 运行你的脚本会在日志中显示以下内容
Cannot find item "ColName" in outline context {ColName}
对你起作用吗?
(我在 JMP 13 上)
回复:将列名作为参数传递给函数 - 是否与 : 连接?Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName, _LSL, _USL},
{distChart},
New Window( "" || ColName || " distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column( As Column( ColName ) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL( _LSL ), USL( _USL ) )
),
SendToReport(
Dispatch(
{colName},
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
)
);
Return( distChart );
);
getDistChart( "weight", 55, 185 );回复:将列名作为参数传递给函数 - 是否与 : 连接?@马克贝利谢谢它有效。 但是,我无法进入下一步。 我想将列名传递到脚本中的多个位置。 下面以 Big Class 为例。 我可以将 ColName 传递给新窗口但不能传递给 Dispatch
Names Default To Here (1);
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function({ColName, _LSL, _USL}, {distChart},
New Window(""||ColName||" distribution",
Distribution(
Stack( 1 ),
Continuous Distribution(
Column(As Column (ColName) ),
Horizontal Layout( 1 ),
Vertical( 0 ),
Capability Analysis( LSL(_LSL ), USL(_USL) )
),
SendToReport(
Dispatch(
{"weight"},
"Distrib Histogram",
FrameBox,
{DispatchSeg( LabelSeg( 1 ), {Font( "Segoe UI", 7, "Plain" )} ),
DispatchSeg( LabelSeg( 2 ), {Font( "Segoe UI", 7, "Plain" )} )}
)
)
);
);
return(distChart);
);
getDistChart ("weight", 55, 185);
例如这个
Dispatch( {ColName},...
或这个从这里
Dispatch( {Expr(ColName)},...
不起作用。 将字符串作为参数传递给 Dispatch 的正确语法是什么?
回复:将列名作为参数传递给函数 - 是否与 : 连接?Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
getDistChart = Function( {ColName}, {dC},
dC = Distribution( Continuous Distribution( Column( As Column( colName ) ) ) );
Return( dC );
);
gt = getDistChart ("weight");