從組合框中選擇某些內容後如何繼續? //fruit is a row in my table
nw = New window ("Select fruit",
cb = combo box ("apple", "Mango", "Banana")
cb << Set Selected,
<< Set Width (20),
//Here I select apple
Button Box ("OK",
table1 << SelectWhere(:fruit!=apple) << Delete Rows;
) )如何僅選擇與「apple」對應的資料來進行分析
這是我想要從這段程式碼中得到的:
1.我先製作一個組合框
2. 從組合方塊中選擇蘋果
3.單擊“確定”後,我應該刪除其他行,只留下帶有蘋果的行。
基礎資料分析與建模視窗回覆:從組合方塊中選擇某些內容後如何繼續?你可以做這樣的事情。
table1 = New Table( "Kind of Fruity",
Add Rows( 6 ),
New Column( "fruit", Character, "Nominal", Set Values( {"Apple", "Banana", "Mango", "Apple", "Apple", "Banana"} ) ),
New Column( "Condiment",
Character,
"Nominal",
Set Values( {"Peanut Butter", "Ketchup", "Cayenne Pepper", "Chocolate Fudge", "Caramel", "Salt"} )
)
);
nw = New Window( "Select fruit",
cb = Combo Box( {"Apple", "Mango", "Banana"} ),
Button Box( "OK",
table1 << Delete Rows( table1 << Get Rows Where( :fruit != (cb << Get Selected) ) );
nw << Close Window;
)
);回覆:從組合方塊中選擇某些內容後如何繼續?您需要對腳本進行輕微修改:
- 您需要使用清單將值輸入到組合框
- 您應該使用 << get selected 來取得使用者選擇的值(通常在「確定」按鈕內)
- 您應該根據 SelectWhere 語句中的使用者選擇動態執行檢查
@mmarchandTSI答案已經有了這些問題的答案,所以我提供了一個有點不同的解決方案,您可以根據組合框的水果列獲取值,演示如何設置特定水果並使用 << get rows where 而不是 select where
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(5),
Compress File When Saved(1),
New Column("fruit",
Character,
"Nominal",
Set Values({"apple", "Mango", "Banana", "apple", "Banana", "Kiwi"})
)
);
Summarize(dt, fruits = By(:fruit));
nw = New Window("Select fruit",
cb_fruits = Combo Box(fruits),
Button Box("OK",
sel_fruit = cb_fruits << get selected;
nok_fruit_rows = dt << Get Rows Where(:fruit != sel_fruit);
dt << Delete Rows(nok_fruit_rows); // note that fruits variable isn't updated
nw << Close Window;
),
cb_fruits << Set(Contains(fruits, "Kiwi"));
);