Expression Handling for Dynamic Display BoxesHi folks,
JSL expression handling makes my head hurt. I'd be grateful for some help with this.
Here's some code that works -- makes three "foo" boxes.
Names Default To Here( 1 );
dt = New Window( "Example",
Table Box(
Col Box(
"boxes",
Text Box( "Foo" ),
Text Box( "Foo" ),
Text Box( "Foo" )
)
)
);
Now I want to be able to dynamically assign the number of boxes.
I can get it to work by building out the expression as a string, then wrapping it in Eval(Parse()). But this solution is hard to maintain, doesn't scale well. I'm sure there's a way to do this using Substitute() or EvalExpr(), but I can't make it work. Grrr.
@brady_brady , @joseph_morgan ? Anyone?
Re: Expression Handling for Dynamic Display BoxesJordan,
Does this work?
Names Default To Here( 1 );
dt = New Window( "Example",
Border Box(
Top(10),Bottom(10),Left(10),Right(10),
V List Box(
H List Box(
Text Box("How many Text Boxes?: "),
nebNBoxes = Number Edit Box(0),
Button Box("Go",buildBoxes)
),
tblBox = Table Box()
)
)
);
buildBoxes = Expr(
colBox = Col Box("boxes");
nBoxes = nebNBoxes << Get;
For(i=1,i<=nBoxes,i++,
colBox << Append(Text Box("Foo " || Char(i)));
);
If(!Is Empty(tblBox << Child), (tblBox << Child) << Delete);
tblBox << Append(colBox)
);Re: Expression Handling for Dynamic Display BoxesIt does work, thank you. I’m still curious to know if there’s a way to use Substitute() or similar to build the expression though.Re: Expression Handling for Dynamic Display BoxesI think it would depend on the circumstances. In a situation where I don't know what kind of boxes I need to add, I may create a box adding function that uses Substitute to avoid writing a function for each box type. I typically find that when have to use Substitute, it can't be done more easily (or at all) any other way.
Re: Expression Handling for Dynamic Display BoxesHey Jordan, below is an example--is this what you're seeking?
Cheers,
Brady
Names Default To Here( 1 );
//assume the list below is why you need to do this dynamically
textboxList = Words( "Tom,Jerry,Bugs,Daffy,Taz", "," );
nw = New Window( "Sample", vlb = V List Box() );
addTextBoxExpr = Expr(
vlb << append( _TBX = Text Box( _TEXT ) )
);
For( i = 1, i <= N Items( textboxList ), i++,
Eval(
Substitute( Name Expr( addTextBoxExpr ),
Expr( _TBX ), Parse( Eval Insert( "tb^i^" ) ),
Expr( _TEXT ), textboxList[ i ]
)
)
);
Re: Expression Handling for Dynamic Display BoxesYes, that's what I was trying to do. Thanks much Brady.
The key insight for me is that both solutions use a series of <
Re: Expression Handling for Dynamic Display BoxesHere is another way to do it, which probably runs more quickly, but I feel is less clear. Also, I've not bound the textboxes to handles, so it would be more difficult to update the textboxes if need be.
Names Default To Here( 1 );
//assume the list below is why you need to do this dynamically
textboxList = Words( "Tom,Jerry,Bugs,Daffy,Taz", "," );
nwExpr = Expr( New Window( "Sample" ) );
vlbExpr = Expr( V List Box() );
For( i = 1, i <= N Items( textboxList ), i++,
Eval( Eval Expr(
Insert Into( vlbExpr, Text Box( Expr( textboxList[i] ) ) )
) )
);
Insert Into( nwExpr, vlbExpr );
nwExpr;
Re: Expression Handling for Dynamic Display BoxesI know it's an old thread. But is this it?
NamesDefaultToHere(1);
n = 15; // Change me
cb = ColBox("My Boxes");
for(i=1, i<=n, i++, cb << append(TextBox("Item "||Char(i))));
NewWindow("Sample", TableBox(cb));Re: Expression Handling for Dynamic Display BoxesThanks Ian, a nice solution to the question as posed.