Subscribe Bookmark RSS Feed

How can I identify the type of DisplayBox?

Hi - this is probably a very easy one.  If I have a list of DisplayBoxes, how can I identify the type of DisplayBox each one is?  The following code fragment illustrates the problem, in which I've put a ButtonBox, a NumberColBox and a StringColBox into a list as the 1st, 2nd and 3rd elements respectively.  I now want to feed that list into a function that will work through the list, identifying each element in turn and performing some operations on it, depending on what type of DisplayBox it is.  The code below simply tells me that each one is a DisplayBox - so it's not quite what I want.

The reason I need to know is that I want to write a function that will work through all the columns in a TableBox - for which I need to know which columns are numeric and which are character.  Can it be done without resorting to trying to perform an operation on it that will only work if it is of a particular type (e.g. << get as matrix)?  Here's the code:

DisplayBoxList = {};

insert into(DisplayBoxList, ButtonBox("AAA"));

insert into(DisplayBoxList, NumberColBox("BBB", [1, 2, 3]));

insert into(DisplayBoxList, StringColBox("CCC", {"a", "b", "c"}));

for(i=1, i<=nItems(DisplayBoxList), i++, show(type(DisplayBoxList[i])));

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Try << class name:

DisplayBoxList = {};

insert into(DisplayBoxList, ButtonBox("AAA"));

insert into(DisplayBoxList, NumberColBox("BBB", [1, 2, 3]));

insert into(DisplayBoxList, StringColBox("CCC", {"a", "b", "c"}));

for(i=1, i<=nItems(DisplayBoxList), i++,

      print(DisplayBoxList[i] << class name());

);


"ButtonBox"

"NumberColBox"

"StringColBox"

3 REPLIES
Solution

Try << class name:

DisplayBoxList = {};

insert into(DisplayBoxList, ButtonBox("AAA"));

insert into(DisplayBoxList, NumberColBox("BBB", [1, 2, 3]));

insert into(DisplayBoxList, StringColBox("CCC", {"a", "b", "c"}));

for(i=1, i<=nItems(DisplayBoxList), i++,

      print(DisplayBoxList[i] << class name());

);


"ButtonBox"

"NumberColBox"

"StringColBox"

Perfect.  Yet another property of which I hadn't known the purpose until now.

Many thanks!

pmroz

Super User

Joined:

Jun 23, 2011

You're welcome.  I poked around in Help > Scripting Index > Display Box until I found a suitable candidate.  Got lucky!

That feature is very helpful because of the many examples, btw.