下面我的 JSL 函數腳本從網絡文件夾中提取文件並將其輸出到數據文件中以供其他地方使用。 如何輸出錯誤消息“此限製文件不存在! 檢查文件名”連同數據文件。 我在 JMP13 上。
Names Default To Here( 1 );
getLimitsFile = Function({LimFileName}, {dtspk},
dtspk = Try(
Open(
"\\gbshyt-ppor-334e\DBX\XPD\System\Limits\"||LimFileName||".txt",
columns(
New Column( "ParameterName", Character, "Nominal" ),
New Column( "ColumnLSL", Character, "Nominal" ),
New Column( "ColumnUSL", Character, "Nominal" ),
New Column( "ColumnUnits", Character, "Nominal" ),
New Column( "ColumnSymb", Character, "Nominal" ),
New Column( "ColumnComm", Character, "Nominal" )
),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( Tab, Comma, CSV( 1 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 1 ),
Column Names Start( 1 ),
Data Starts( 2 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
//,invisible)
),"This limit file does not exist! Check file name");
return(dtspk);
);此外,在發生錯誤的情況下,如何停止使用該函數的代碼的進一步執行並向用戶顯示帶有錯誤消息的對話框?
如果 JMP13 提供 File Exists() 函數,您可以將它與 if 語句一起使用。 然後決定返回什麼/如何停止程序。 您可以使用例如 Throw() 或 Stop()
Names Default To Here(1);
getLimitsFile = Function({LimFileName}, {dtspk},
If(!File Exists("\\gbshyt-ppor-334e\DBX\XPD\System\Limits\"||LimFileName||".txt"),
Throw("This limit file does not exist! Check file name");
//or use return and throw outside function
);
//Open...
return(dtspk);
);
getLimitsFile("");
Show("continue...");
編輯:
您想返回哪個數據表並返回錯誤? 如果您無法打開文件,則除非您創建一個空的,否則沒有要返回的數據表。
謝謝@jthi , 是的,JMP 13 確實有 File Exists ()。 我會試試看。
我之前沒有正確表達我的查詢。 當文件不存在時,我只想讓函數在對話框中輸出錯誤並停止進一步執行。
當文件存在時,我只想要數據表和消息輸出。 如何做到這一點?
您是否在要填充錯誤消息的函數之外有一個對話框? 對於數據表,您想用數據表返回消息輸出嗎?