Skip to main content
1-Visitor
April 22, 2014
Solved

Mathcad listbox

  • April 22, 2014
  • 6 replies
  • 3486 views

I am using listbox control for selections. It works fine except when there is a case where array contains only one element. I am new to scripting and dont know how to change the script to show only one selection value in listbox. Can you help. I have attached file for reference.

Best answer by RichardJ

Here you go.

There are a lot of examples you can look at here: Extra Components and Controls

6 replies

RichardJ19-TanzaniteAnswer
19-Tanzanite
April 22, 2014

Here you go.

There are a lot of examples you can look at here: Extra Components and Controls

1-Visitor
April 22, 2014

Thank you Richard

25-Diamond I
April 22, 2014

Hmm, thats interesting.

My first advice would have been to make Case2 a 1x1 matrix, but I saw that this doesn't help. Obviously a 1x1 matrix as input is not seen as an array (I think thats a bug). UBound will only work with arrays and so the script fails. So my workaround would be to use an if statement to look if the input is an array and if its not we construct a 1 element array from it.

Look if the attached helps

1-Visitor
April 22, 2014

Thank you Werner

25-Diamond I
April 22, 2014

You are welcome.

I just noticed another problem: If you select case1 and B and then change to case2, you get an error as the second listbox remembers the selection (second item) which now doesn't exist.

I added an additional if statement which sets the selection to zero if its greater than allowed.

I am not well versed with scripting and so unfortunately I am not sure how the component could detect that the input list has changed. It would be a better way to always change the selection to the first element whenever the list has changed.