检查列名称是否存在你好,
我有一个列名列表,我需要从表中检查它是否存在。
如何检查表中的每一列,如果不存在则提示错误并停止程序运行?
col_list = {"Col1", "Col2", "Col3", "Col4", "Col5" };
//checks column if exist<BR /><BR /> //..code continue running<BR />
//if column doesn't exist<BR />
//..code will stop script & error prompt
大规模定制回复:检查列名称是否存在这是我之前发布的脚本的修改。
我强烈建议您花时间阅读 JMP 文档库中“帮助”下拉菜单下的脚本指南,以便您能够获取此示例代码并使用它来解决您自己的脚本需求。
animals = Open( "$SAMPLE_DATA\Animals.jmp" );
dt_animals = Data Table( "Animals" );
col_list = {"species", "subject", "miles", "season", "name"};
notFound = {};
For( i = 1, i <= N Items( col_list ), i++,
If( Try( Column( col_list[i] ) << get name, "" ) == "",
Insert Into( notFound, col_list[i] )
)
);
If( N Items( notFound ),
nf = New Window( "Error:",
V List Box(
Text Box( "The following columns are required" ),
Text Box( "but were not found in the data table" ),
List Box( notFound )
)
);
throw();
);回复:检查列名称是否存在提示将告诉您缺少哪一列回复:检查列名称是否存在是什么不起作用?我运行了你的代码,当它到达名为“name”的列时,代码停止了。
变量“i”的值最终为 5,因为它在第 5 个循环时停止处理。如果它已完成处理,则变量“i”将为 6。
如果有超出这段代码的代码,则不会被处理。
回复:检查列名称是否存在animals = Open( "C:\Animals.jmp" );
dt_animals = Data Table( "Animals" );
col_list = {"species", "subject", "miles", "season", "name"};
For( i = 1, i <= N Items( col_list ), i++,
If( Try( Column( col_list[i] ) << get name, "" ) == "",
Throw()
)
);
我确信我错过了一些东西,它对我不起作用
回复:检查列名称是否存在我使用的方法是
col_list = {"col1", "col2", "col3"};
for(i=1,i<=N Items(col_list),i++,
if(try(column(col_list[i])<<GET name=""></GET>