概述
有時需要對相同類型的多個物件執行相同的任務。一種方法是對每個物件重複該語句。但是,這需要您為每個物件重新鍵入語句或使用循環。
一種方便的方法是將訊息傳送到物件清單。此方法要求您僅鍵入一次訊息。下面給出兩個例子。
實施例1
假設我有兩個資料表,我想在每個表中新增相同的公式列。另外,假設我想將每個表排序到新表中並建立對新表的引用。您可以將訊息傳送到如下所示的表格列表,以及使用等號左側的名稱列表。
//Create 2 sample tables
dt1 = New Table( "Table1",
Add Rows( 10 ),
New Column( "Index", "Numeric", "Ordinal", Set Values( Index( 1, 10 ) ) )
);
dt2 = New Table( "Table2",
Add Rows( 10 ),
New Column( "Index", "Numeric", "Ordinal", Set Values( Index( 11, 20 ) ) )
);
//Add a formula column to both tables
{dt1, dt2} << New Column( "Random", Formula( Random Normal() ) );
//Sort by the new column and return a list of references to the new sorted tables
{dt1s, dt2s} = {dt1, dt2} << Sort( By( :Random ) );
實施例2
假設我有幾個文字框,我想更改所有文字框的字體顏色,並檢索文字並將資訊儲存到新變數中。如此處所示,您可以使用清單一次執行所有操作。
//Create a window containing a few TextBoxes
nw = New Window( "Example",
tb1 = Text Box( "This is text box 1" ),
tb2 = Text Box( "This is text box 2" ),
tb3 = Text Box( "This is text box 3" )
);
//Set the font color by sending the message to a list of the objects
{tb1, tb2, tb3} << Font Color( Red );
//Return a list of the text stored in each TextBox
{text1, text2, text3} = {tb1, tb2, tb3} << Get Text;
[以前的 JMP 註 50975]