cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Have your say in shaping JMP's future by participating in the new JMP Wish List Prioritization Survey
Choose Language Hide Translation Bar
Djtjhin
Level IV

Error when using Try() on Collistbox()

Basically I'm building a custom interactive window which includes different display boxes and I'm trying to simplify the selection input with a for loop. For instance, I have both a combobox & a collistbox and I'm trying to get input for both using a loop statement. But when I did this, I got an error instead. Am I writing the expression incorrectly ? (error log attached)

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "Col List Box Example",
	vlistbox(
		var1 = combobox({"one", "two", "three"}),
		hlistbox(Col List Box( all, width( 250 ), maxSelected( 1 ) ),
			var2 = Col List Box()	
		)	
	)
);

var2 << append("height");

AA = {"",""};

for(i=1,i<=2,i++,
	temp1 = "var"||char(i);
	eval(
		substitute(
			expr(try(AA[i] = expr.temp1 << get, AA[i] = expr.temp1 << get items)), //try to use get, if error, use get items
			expr(expr.temp1),parse(temp1)
		)
	)
);

show(AA);

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Error when using Try() on Collistbox()

I think your Try doesn't work because << Get doesn't rise an error when used with ListBoxBox (just a message to log). If you want to get values this way, you could for example use << Class Name:

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
New Window("Col List Box Example",
	V List Box(
		var1 = Combo Box({"one", "two", "three"}),
		H List Box(Col List Box(all, width(250), maxSelected(1)), var2 = Col List Box())
	)
);

var2 << append("height");

AA = {"", ""};
For(i = 1, i <= 2, i++,
	temp1 = "var" || Char(i);
	Eval(
		Substitute(
				Expr(
					If(expr.temp1 << class name == "ComboBox",
						AA[i] = expr.temp1 << get
					,
						AA[i] = expr.temp1 << get items					
					)
				), //try to use get, if error, use get items
			Expr(expr.temp1), Parse(temp1)
		)
	);
);

Show(AA); //AA = {1, {"height"}};

 

I would usually suggest not getting the values like this and try to figure some other way than dynamically creating variable names (storing references to list or associative array for example).

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: Error when using Try() on Collistbox()

I think your Try doesn't work because << Get doesn't rise an error when used with ListBoxBox (just a message to log). If you want to get values this way, you could for example use << Class Name:

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");
New Window("Col List Box Example",
	V List Box(
		var1 = Combo Box({"one", "two", "three"}),
		H List Box(Col List Box(all, width(250), maxSelected(1)), var2 = Col List Box())
	)
);

var2 << append("height");

AA = {"", ""};
For(i = 1, i <= 2, i++,
	temp1 = "var" || Char(i);
	Eval(
		Substitute(
				Expr(
					If(expr.temp1 << class name == "ComboBox",
						AA[i] = expr.temp1 << get
					,
						AA[i] = expr.temp1 << get items					
					)
				), //try to use get, if error, use get items
			Expr(expr.temp1), Parse(temp1)
		)
	);
);

Show(AA); //AA = {1, {"height"}};

 

I would usually suggest not getting the values like this and try to figure some other way than dynamically creating variable names (storing references to list or associative array for example).

-Jarmo