해결책
숫자 편집 상자를 사용하여 값을 가져오고 함수 설정 방법을 사용하여 숫자 편집 상자에 JSL을 연결하여 값이 변경될 때 테이블을 다시 계산합니다. 테이블 상자를 사용하여 숫자 열을 보관합니다. 값이 변경되면 숫자 열을 다시 작성하십시오.
Payment table built in a Table BoxTable Box에 내장된 결제 테이블if( jmpversion()<"13", Open Log(1); throw("requires JMP 13 or greater"));
// need default values to set up the edit boxes
borrow = 1e5;
years = 2;
apr = 15;
cur = "USD"; // "EUR"
New Window( "table demo",
Border Box( Left( 5 ), Right( 5 ), bottom( 5 ), // this box extends the pale green a few pixels
V List Box( // border boxes need a single child, like a vlist, to hold everything
Border Box( Left( 20 ), Right( 20 ), top( 10 ), bottom( 10 ), // the data entry border
H List Box( // separate the data entry fields from "Interesting" title
V List Box( // the three vertical entry fields and their labels
H List Box( // a field and its label
Number Edit Box( // a field
borrow,
<<setformat( 13, "Currency", cur ), // JMP 14 sets the formatM
<<Set Function( // a callback function for responding when the
Function( {this}, // entry fields change
borrow = this << get; // get the current value
freshen(); // run the common code
)
)
),
Text Box( " amount" ) // label the entry field, space it over a bit
),
H List Box( // ditto
Number Edit Box(
years,
<<setformat( 13, "Best" ),
<<Set Function(
Function( {this},
years = this << get;
freshen();
)
)
),
Text Box( " years" )
),
H List Box( // ditto
Number Edit Box(
apr,
<<setformat( 13, "Best" ),
<<Set Function(
Function( {this},
apr = this << get;
freshen();
)
)
),
Text Box( " apr" )
)
),
Border Box( Left( 100 ), Text Box( "Interesting", <<setfontsize( 40 ) ) ) // label
)
),
Spacer Box( size( 10, 10 ), color( "dark green" ), <<setAutoStretching( 1, 0 ), <<setMaxSize( 1e5, 10 ) ),
tb = Table Box( // here's the table box. You could put columns here, but
// the freshen function will do that in a second, using "tb".
<<setShadeAlternateRows( 1 ), // set the table properties to make a green-bar report
<<setShadeHeadings( 0 ),
<<setHeadingColumnBorders( 0 ),
<<setUnderlineHeadings( 1 ),
<<setColumnBorders( 0 ),
<<setRowBorders( 0 ),
<<setShadeCells( 0 )
)
),
<<backgroundcolor( RGB Color( 245, 255, 245 ) ) // pale green
)
);
freshen = Function( {},
{// local variables
rate = (apr / 100) / 12, day = Min( 28, Day( Today() ) ), month = Month( Today() ), year = Year( Today() ), dates = J( 1 + years * 12, 1, 0 ), i,
payment = Payment( rate, 12 * years, borrow ), interest = -Interest Payment( rate, 0 :: 12 * years, 12 * years, borrow ), principal =
-Principal Payment( rate, 0 :: 12 * years, 12 * years, borrow ), payment2 = interest + principal, balance =
Present Value( rate, 12 * years :: 0, payment, 0 ), CumulativeInterest = Cumulative Sum( interest )},
For( i = 1, i <= N Rows( dates ), i++,
If( month > 12,
month -= 12;
year += 1;
);
dates[i] = Date DMY( day, month, year );
month += 1;
);
While( !Is Empty( tb << child ), (tb << child) << delete ); // remove previous data, if any
// add the new columns to the table
tb << append( Number Col Box( "Due Date", dates, <<setformat( 11, "yyyy-mm-dd" ) ) );
tb << append( Number Col Box( "Payment to Principal", principal, <<setformat( 13, "Currency", cur ) ) );
tb << append( Number Col Box( "Payment to Interest", interest, <<setformat( 13, "Currency", cur ) ) );
tb << append( Number Col Box( "Cumulative Interest", CumulativeInterest, <<setformat( 13, "Currency", cur ) ) );
tb << append( Number Col Box( "Monthly Payment", payment2, <<setformat( 13, "Currency", cur ) ) );
tb << append( Number Col Box( "Outstanding Balance", balance, <<setformat( 13, "Currency", cur ) ) );
0;// return nothing
);
freshen();