創建一個循環我想使用以下腳本將包含行號的列新增到多個資料表:
dt<<NEW column=""></NEW>
我對腳本編寫還是新手。 如何自動處理我的所有資料表? 我有這行資訊可以工作,但似乎定位「數據表」有問題...
Names Default To Here( 1 );
// Create a list of data tables to be updated
dtList = {"Table1", "Table2", etc...};
// Loop through each of the data tables and add the column
For( i = 1, i <= N Items( dtList ), i++,
dt = Data Table( dtList[i] );
回覆:建立一個循環非常感謝傑夫。 那很完美。
我絕對必須抽出時間來仔細閱讀腳本指南。 它會幫助我。回覆:建立一個循環你有很多問題。
你已經迷茫了迪爾路徑和全部文件並在您的程式碼中錯誤地使用了它們。 的結果選擇目錄() ,迪爾路徑,將是一個字串,它是使用者選擇的目錄的路徑。 您已嘗試在下面的 For() 循環的索引中使用它,就好像它具有文件列表一樣。
的結果目錄中的檔案() ,全部文件,將是目錄中的檔案清單。 這就是你應該循環的內容。
你需要打開()資料表,然後才能新增列。
自從全部文件列表只是檔案名,您需要連接目錄,迪爾路徑,在 Open() 的參數中。
最後,您應該透過檢查檔案的副檔名來確保您只是嘗試開啟 JMP 資料表。 在下面的範例程式碼中,我使用單字()功能。 -1 參數詢問字串中的最後一個單字。
dirpath = Pick Directory();
allfiles = Files In Directory( dirpath );
// Loop through each of the files and add the column
Show( allfiles );
For( i = 1, i <= N Items( allfiles ), i++,
If( Word( -1, allfiles[i], "." ) == "jmp",
dt = Open( dirpath || allfiles[i] );
dt << New Column( "Sequence", numeric, formula( Row() ) );
)
);
查看開始使用的部分數據表的章節腳本指南了解如何使用數據表。
回覆:建立一個循環我在複製腳本時在訊息中犯了一個錯誤,但我使用了正確的版本,但仍然有一條帶有「偵錯」選項的錯誤訊息:
意想不到的「為了」。 也許缺少一個 ;或 。
回覆:建立一個循環你的循環中有「dispath」。將其更改為“dirpath”
回覆:建立一個循環顯然。 現在還不太對勁。 “For”行有問題嗎?
<SPAN class="token comment">dirpath = Pick Directory();<BR />allfiles = Files in Directory (dirpath);<BR />all files<BR /><BR />// Loop through each of the files and add the column</SPAN>
<SPAN class="token function">For</SPAN><SPAN class="token punctuation">(</SPAN> i <SPAN class="token operator">=</SPAN> <SPAN class="token number">1</SPAN><SPAN class="token punctuation">,</SPAN> i <SPAN class="token operator"><=</SPAN> <SPAN class="token function">N Items</SPAN><SPAN class="token punctuation">(</SPAN> dirpath <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">,</SPAN> i<SPAN class="token operator">++</SPAN><SPAN class="token punctuation">,</SPAN>
dt <SPAN class="token operator">=</SPAN> <SPAN class="token function">Data Table</SPAN><SPAN class="token punctuation">(</SPAN> dispath<SPAN class="token punctuation">[</SPAN>i<SPAN class="token punctuation">]</SPAN> <SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
dt<SPAN class="token operator"><</SPAN><SPAN class="token operator"><</SPAN><SPAN class="token function">new column</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token string">"Sequence"</SPAN><SPAN class="token punctuation">,</SPAN> numeric<SPAN class="token punctuation">,</SPAN> formula<SPAN class="token punctuation">(</SPAN><SPAN class="token function">Row</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
<SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
回覆:建立一個循環有一些命令可以選擇一個目錄並列出該目錄中的所有檔案。
我建議檢查每個文件是否是 JMP 文件(例如,通過檢查文件結尾)。
dirpath = Pick Directory();
allfiles = Files in Directory(dirpath);
allfiles
回覆:建立一個循環呀!效果很好!
是否可以在腳本開始時請求打開資料夾中的所有資料表,以便此後運行腳本? 是否應該在“listoftables”中逐一指明每個文件的標題? 這需要很多時間…你建議我如何進行?
先致謝
回覆:建立一個循環以下腳本對我有用。 如果不適合您,發布您的日誌內容(主選單 => 視窗 => 日誌)和您正在使用的 JMP 版本會很有幫助。
listoftables = {"Untitled 5", "Untitled 4", "Untitled 3"};
// Loop through each of the data tables and add the column
For( i = 1, i <= N Items( listoftables ), i++,
dt = Data Table( listoftables[i] );
dt<<NEW column=""></NEW>