cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need to share some code when posting a question or reply? Make sure to use the "Insert code sample" menu option. Learn more! X

Mathcad listbox

yogeshdeshpande
1-Newbie

Mathcad listbox

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.

1 ACCEPTED SOLUTION

Accepted Solutions

Here you go.

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

View solution in original post

6 REPLIES 6

Here you go.

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

Thank you Richard

Just gave it a try and the dynamically listbox in your truly fine collection fails for the very same reason if the ListBoxOptions is a 1x1 matrix. A Mathcad 1x1 matrix seems not to be handed over as single variable if used as input to a component. Think that shouldn't be that way.

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

Thank you Werner

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.

Top Tags