數據表的選擇問題你好,
我希望你過得很好。
這是一個非常長且未優化的代碼,用於執行來自兩個不同數據集(“CL 和 Spec”和“數據集”)的 2 個子集。 有一個文本框可以根據數據集的級別選擇要選擇的行。
但是,問題是在執行第一個數據表的子集(名為“CL and Spec”的數據集)之後,第二個數據集的子集(名為“Data set”)無法正常工作,並且沒有任何錯誤消息。 只是沒有執行子集。 我的理解是,我為子集選擇數據集的方式存在問題。 或者我沒有正確使用“當前數據表”功能。
這是我的代碼:
dt2 = Data Table( "CL and Spec" );
Current Data Table( dt2 );
// get unique values from the strength column
Summarize( dt2, levels = by( :Product ) );
// construct a window containing checkboxes
New Window( "Selection",
modal,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box(
Text Box( "Select values:" ),
here:cb = Check Box( levels ),
Spacer Box( size( 0, 20 ) ),
Button Box( "Create Subset", doSubset() )
)
)
);
// define function to perform when button is cliccked
doSubset = Function( {},
{default local},
dt2 = Current Data Table();
dt2 << clear select;
// get user selections
selected = here:cb << get selected;
// iterate over each of the selected values
// and select the associated rows
For( i = 1, i <= N Items( selected ), i++,
rows = dt2 << select where( :Product == selected[i], current selection( "extend" ) )
);
// create a subset table
dt2 << subset( selected rows( 1 ), selected columns only( 0 ) );
dt2 << clear select;
);
// Define the control and specification limits
LSL = dt2:LSL[1];
USL = dt2:USL[1];
dt = Data Table( "Data Set" );
Current Data Table( dt );
// get unique values from the strength column
Summarize( dt, levels = by( :Strength ) );
// construct a window containing checkboxes
New Window( "Selection",
modal,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box(
Text Box( "Select values:" ),
here:cb = Check Box( levels ),
Spacer Box( size( 0, 20 ) ),
Button Box( "Create Subset", doSubset() )
)
)
);
// define function to perform when button is cliccked
doSubset = Function( {},
{default local},
dt = Data Table( "Data Set" );
Current Data Table( dt );
dt << clear select;
// get user selections
selected = here:cb << get selected;
// iterate over each of the selected values
// and select the associated rows
For( i = 1, i <= N Items( selected ), i++,
rows = dt << select where( :Strength == selected[i], current selection( "extend" ) )
);
// create a subset table
dt << subset( selected rows( 1 ), selected columns only( 0 ) );
dt << clear select;
);我希望我的問題和問題得到明確表達;)
非常感謝您的幫助,祝您有愉快的一天!
讓
腳本回复:數據表的選擇問題我沒有你的表格,但這是我處理類似問題的方式:
Names Default to Here( 1 );
dt2 = Data Table( "CL and Spec" );
// get unique values from the strength column
levels = Associative Array( dt2:product ) << Get Keys;
// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
<<MODAL></MODAL>
回复:數據表的選擇問題事實上,我擔心的是我想打開 2 個不同的數據集並使用第一個數據集,然後切換到下一個數據集。
我在執行子集之前使用了“當前數據表”功能。
代碼的第一部分是加載“CL and Spec”數據集,打開一個文本框,對“CL and Spec”數據集的一行進行子集化,並將參數“LSL”和“USL”存儲在 LSL 中和 USL 變量。 然後不再使用“CL and Spec”數據集。
Names Default to Here( 1 );
dt2 = Data Table( "CL and Spec" );
// get unique values from the strength column
levels = Associative Array( dt2:product ) << Get Keys;
// construct a window containing checkboxes
continue = 0;
New Window( "Selection",
<<MODAL></MODAL>
然後代碼的第二部分是加載“Data set”數據集,打開一個文本框,並對“Data set”數據集的行進行子集化。
dt = Data Table( "Data Set" );
Current Data Table( dt );
// get unique values from the strength column
Summarize( dt, levels = by( :Strength ) );
// construct a window containing checkboxes
New Window( "Selection",
modal,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ),
V List Box(
Text Box( "Select values:" ),
here:cb = Check Box( levels ),
Spacer Box( size( 0, 20 ) ),
Button Box( "Create Subset", doSubset() )
)
)
);
// define function to perform when button is cliccked
doSubset = Function( {},
{default local},
dt = Data Table( "Data Set" );
Current Data Table( dt );
dt << clear select;
// get user selections
selected = here:cb << get selected;
// iterate over each of the selected values
// and select the associated rows
For( i = 1, i <= N Items( selected ), i++,
rows = dt << select where( :Strength == selected[i], current selection( "extend" ) )
);
// create a subset table
dt << subset( selected rows( 1 ), selected columns only( 0 ) );
dt << clear select;
);但是,第二個數據未加載或沒有行的子集......
非常感謝您的幫助!