함수의 오류 메시지와 함께 데이터 테이블 출력(JMP13)아래 내 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);
);또한 오류가 발생한 경우 함수가 사용된 코드의 추가 실행을 중지하고 오류 메시지가 포함된 대화 상자를 사용자에게 표시하는 방법은 무엇입니까?
스크립팅Re: 함수의 오류 메시지와 함께 데이터 테이블을 출력합니다(JMP13).감사 해요 @jthi , 예, JMP 13에는 File Exists()가 있습니다. 나는 그것을 시도 할 것이다.
내 쿼리를 이전에 올바르게 표현하지 않았습니다. 파일이 존재하지 않으면 함수가 대화 상자에 오류를 출력하고 더 이상의 실행을 중지하기를 원합니다.
파일이 존재하는 경우 데이터 테이블과 메시지 출력만 원합니다. 이것을 달성하는 방법?
Re: 함수의 오류 메시지와 함께 데이터 테이블을 출력합니다(JMP13).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...");
편집하다:
어떤 데이터 테이블을 오류와 함께 반환하시겠습니까? 파일을 열 수 없으면 빈 데이터 테이블을 생성하지 않는 한 반환할 데이터 테이블이 없습니다.
Re: 함수의 오류 메시지와 함께 데이터 테이블을 출력합니다(JMP13).이 기능을 사용하는 메인 코드에 대한 대화 상자는 아직 없습니다.
사용자가 잘못된 파일 이름을 전달하여 오류가 발생하면 기본 코드가 사용자에게 오류가 있는 대화 상자를 표시하고 기본 코드의 더 이상 실행을 중지하기를 원합니다. 파일 이름에 오류가 없으면 네트워크 위치에서 파일을 가져와서 기본 코드에서 사용할 수 있어야 하는 데이터 테이블로 전달합니다. 귀하의 질문에 답변이 되었기를 바랍니다. @jthi .
Re: 함수의 오류 메시지와 함께 데이터 테이블 출력(JMP13)물론, 그것으로 충분할 것입니다! 이것은 응용 프로그램(및 프로그래머/스크립터)에 따라 오류를 처리하는 방법에 따라 다릅니다.
아래 예제에는 이를 처리할 수 있는 두 가지 매우 간단한 옵션이 있습니다. JMP13이 JMP16과 유사하게 작동한다면 둘 다 괜찮을 것입니다(물론 애플리케이션에 따라 다름). 차이점은 첫 번째는 함수 내부에서 오류를 발생시키고, 두 번째는 파일 경로에 문제가 있고 결과가 함수 외부에서 처리되는 경우 문자열을 반환한다는 것입니다.
Names Default To Here(1);
open_file_with_throw = function({file_path}, {default local},
If(!File Exists(file_path), //! inverts the File Exists result
Throw(Eval Insert("^file_path^ file doesn't exist, check file path"));
);
dt = Open(file_path);
return(dt); //return datatable reference
);
open_file_with_throw("testpath");
Show("Shouldn't be executed, due to throw");
//with working file path you will get reference to opened table returned
dt = open_file_with_throw("$SAMPLE_DATA/Big Class.jmp");
open_file_with_return = function({file_path}, {default local},
If(!File Exists(file_path), //! inverts the File Exists result
return(Eval Insert("^file_path^ file doesn't exist, check file path"));
);
dt = Open(file_path);
return(dt); //return datatable reference
);
// this wont error, so you will have to handle error yourself
// one thing I don't like about this solution, is that you will have two different types of returns
// from same function
result = open_file_with_return("testpath");
If(Type(result) == "String",
//Throw(result);
//or you can build the error with modal window and stop after it is closed
//@craige_hales post has quite good template for this type of modals here: https://community.jmp.com/t5/Uncharted/Modal-Dialogs/ba-p/436177
//below is very simple one
New window("Error", << modal,
text box(result)
);
stop();
);
Show("Shouldn't be executed, due to stop");
dt = open_file_with_throw("$SAMPLE_DATA/Big Class.jmp");
Re: 함수의 오류 메시지와 함께 데이터 테이블 출력(JMP13)감사해요 @jthi . 잡는 방법 던지다 대화 상자의 메시지? 아래는 작동하지 않는 것 같습니다.
Names Default To Here(1);
open_file_with_throw = function({file_path}, {default local},
If(!File Exists(file_path), //! inverts the File Exists result
Throw(Eval Insert("^file_path^ file doesn't exist, check file path"));
);
dt = Open(file_path);
return(dt); //return datatable reference
);
result = open_file_with_throw("testpath");
Show(result);
If(Type(result) == "String",
New window("Error", << modal,
text box(result)
);
stop();
);
Re: 함수의 오류 메시지와 함께 데이터 테이블 출력(JMP13)이 경우 Throw() 대신 Return()을 사용하십시오.
Re: 함수의 오류 메시지와 함께 데이터 테이블 출력(JMP13)필요한 경우 잡을 수 있고 잡히지 않으면 JSL을 중지하기 때문에 던지기를 선호합니다.
open_file_with_throw = Function( {file_path},
{default local},
If( !File Exists( file_path ), //! inverts the File Exists result
Throw( Eval Insert( "^file_path^ file doesn't exist, check file path" ) )
);
dt = Open( file_path );
Return( dt ); //return datatable reference
);
moreJSL = Function( {dt},
Show( N Rows( dt ) );
Close( dt, nosave );
);
errorHandler = Function( {msg}, Show( msg ) );
Write( "\!ncase 1:" );
Try(
dt = open_file_with_throw( "$sample_data/big class.jmp" ),
dt = Empty();
errorHandler( exception_msg );
);
If( !Is Empty( dt ),
moreJSL( dt )
);
Write( "\!ncase 2:" );
Try(
dt = open_file_with_throw( "testpath" ),
dt = Empty();
errorHandler( exception_msg );
);
If( !Is Empty( dt ),
moreJSL( dt )
);
// or even this, but the error handler may be handling exceptions from moreJSL() as well as open_file_with_throw()
Write( "\!ncase 3:" );
Try( moreJSL( open_file_with_throw( "$sample_data/big class.jmp" ) ), errorHandler( exception_msg ) );
Write( "\!ncase 4:" );
Try( moreJSL( open_file_with_throw( "testpath" ) ), errorHandler( exception_msg ) );