My JSL function script below pulls a file from a network folder and outputs it in a data file for use elsewhere. How do I output the error message "This limit file does not exist! Check file name" together with the datafile. I am on 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);
);Also, in the case of an error, how to stop further execution of the code where the function is used and show the user a dialog box with the error message?
If JMP13 provides File Exists() function you could use it with if statement. Then it is a decision what to return / how to stop program. You can use for example Throw() or 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...");
Edit:
Which datatable would you like to return with the error? If you cannot open the file, there is no datatable to return unless you create empty one.
Thanks @jthi, Yes, JMP 13 does have File Exists (). I will try it.
I did not phrase my query correctly earlier. When the file does not exist, I just want the function to just output the error in a dialog box and stop further execution.
When the file exists, I only want the data table only and message output. How to achieve this?
Do you have a dialog box outside the function which you want to fill with the message of error? And with datatable you want to return message output with the datatable?