我有任意數量的列定義流程的輸入,還有一堆其他列作為輸出,對於每組輸入,都有一堆按時間鍵入的輸出行。
.jsl 是否可以創建一個新的“setid”列,該列在第 1 行中以“1”開頭,然後採用用戶選擇的列(1 個或更多列),並且只要這些列中的任何值發生變化,它就會遞增setid 列中的值——否則 setid 保持不變。我們可以假設行按集合合理排序。
這是一個你可以開始的小例子。我挖出了很多年前做過的一些舊代碼,並對其進行了修改。首先會彈出一個對話框

選擇列後,單擊“確定”,它會創建新列。
如果您還沒有閱讀腳本指南......您現在應該閱讀。為了擴展這個簡單的腳本,您需要了解 JSL 以及您可以用它做什麼。這是腳本
Clear Symbols();
Names Default To Here( 1 );
dt = Current Data Table();
allcolumnslist = dt << get column names( "string" );
nw = New Window( "Generate SETID Column",
Border Box( Left( 3 ), top( 2 ),
V List Box(
Text Box( "Create a SETID Column" ),
H List Box(
V List Box(
// Generate the master display box for the columns in the data table
Panel Box( "Select Columns",
colListData = Col List Box( width( 180 ), nLines( Min( N Cols( dt ), 15 ) ) ),
colListData << append( dt << get column names( "string" ) ),
// At startup, sselect the columns in the selection box for
// the columns that are selected in the data table
For( II = 1, II <= N Items( All Columns list ), II++,
If( Column( ii ) << get selected == 1,
colListData << set selected( II )
)
);
)
),
// Setup the selection buttons and the selection boxes
Panel Box( "Selected Columns to Create SETID from",
Lineup Box( N Col( 2 ), Spacing( 3 ),
Button Box( "Add Column(s)", colListY << Append( colListData << GetSelected ) ),
colListY = Col List Box( width( 180 ), nLines( 10 ), min col( 1 ), max col( 0 ) ),
)
),
// Setup the action buttons that control the window processing
V List Box(
Panel Box( "Action",
Lineup Box( N Col( 1 ),
Button Box( "OK",
// Check to see if the required data has been input
If( N Items( colListY << GetItems ) == 0,
Dialog( "No Y Columns Specified", Button( "OK" ) ),
// Process the Y Columns
thecols = {};
thecols = colListY << GetItems;
nw << close window;
runit();
)
),
Button Box( "Cancel", Stop() ),
Text Box( " " ),
Button Box( "Remove", colListY << RemoveSelected ),
Button Box( "Help", notImplemented )
)
)
),
)
)
)
);
// Here is the function that calculates the new column.
runit = Function( {},
If( Try( dt:SetID << get name, "" ) != "",
dt << delete columns( {"SetID"} )
);
dt << New Column( "SetID", numeric );
// Set the value for row 1
mySetID = 1;
dt:SetID[1] = mySetID;
// Loop across the remaining rows, checking for a change from the previous row
For( i = 2, i <= N Rows( dt ), i++,
thesame = "Yes";
For( k = 1, k <= N Items( thecols ), k++,
If( Column( dt, thecols[k] )[i] != Column( dt, thecols[k] )[i - 1],
thesame = "No"
)
);
// If a change is found, increase the counter
If( thesame == "No",
mySetID
++);
// Set the value of the new column
dt:SetID[i] = mySetID;
);
);