Hello,
As a new .jsl user I've attempted to learn by producing a small script to pull data out of the big class sample data table given a user input.
For most of the problems I've encountered the solutions could be found on these discussion boards but I have an few extra things I'd like to add that I can't find any information on.
- If the user enters an incorrect name (i.e. if no matching rows are found) how would I script an alert window to pop-up and inform the user of this?
- Instead of opening a subset data table, is it possible to print the returned cell value to the UI window itself (below the search and cancel buttons)? or if not, to a new window similar to the alert window described above.
- Could any optimisations be made or general improvements to the script?
Thanks in advance for any help,
No7
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp", "Invisible" );
dt << Clear Selected;
cols = dt << getColumnNames( "String" );
delcols = {"name"};
For( i = 1, i <= N Items( delcols ), i++,
Remove From( cols, As List( Loc( cols, delcols[i] ) ) )
);
lookup_script = Expr(
myName = Uppercase( name1 << get text );
If( myName != "",
match_rows = dt << get rows where( :name == myName )
);
dt << subset( columns( cols[cb << get] ), rows( match_rows ) );
);
UIwin = New Window( "Big Class Age/Height Lookup",
Show Menu( 0 ),
Show Toolbars( 0 ),
//<<Modal,
H List Box(
Spacer Box( size( 10, 10 ) ),
V List Box(
Panel Box( "",
V List Box(
Spacer Box( size( 250, 5 ) ),
H Center Box( Text Box( "Enter a Name:", <<Set Font Size( 12 ) ) ),
Spacer Box( size( 5, 15 ) ),
name1 = H Center Box( Text Edit Box( "", Hint( "e.g. Elizabeth" ), <<set width( 100 ) ) ),
Spacer Box( size( 2, 25 ) ),
H Center Box( Text Box( "Select a Column to Look Up:", <<Set Font Size( 12 ), ) ),
Spacer Box( size( 5, 15 ) ),
H Center Box( cb = Combo Box( cols ) ),
Spacer Box( size( 5, 35 ) ),
H Center Box(
H List Box(
Button Box( "Search", lookup_script ),
Spacer Box( size( 20, 1 ) ),
Button Box( "Cancel", UIwin << Close Window )
)
),
Spacer Box( size( 5, 150 ) ),
),
),
Spacer Box( size( 5, 20 ) ),
),
Spacer Box( size( 10, 10 ) ),
),
);