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

If statement to define options in listbox

If statement to define options in listbox

Hi

I'm trying to make a listbox where the options are dependent on another variable in my worksheet. If my variable n.sec is smaller than 3, I want the list box to only have the option "N/A". Otherwise I would like it to display a list of options.

I'm having a hard time understanding the vb script language, and haven't been able to find a simple tutorial to get me started in using it in mathcad. I hope someone can give a solution to my problem, which I believe must be pretty simple, but I just can't crack.

Thanks in advance

Ole

Tags (2)
3 REPLIES 3

Re: If statement to define options in listbox

You might be interested in Richards fine collection

Extra Components and Controls

Re: If statement to define options in listbox

I've been looking through the collection, and tried to create the options from an input variable (which I programmed to give the different options dependent on my variable n.sec). Was not able to get this to work though.

My new approach would be to have my variable n.sec (which can only have a single value of 3, 4 or 5) as an input to my control, and then in the string input have something like this:

     If Inputs(1).Value>3

          ListBox.AddString("Option1")

          Listbox.AddString("Option2")

          etc...

     Else

          ListBox.AddString("N/A")

     End If

This doesn't work though (some wrong syntax in the Inputs(1).Value>3 part. Can the change in the listbox options be implementet in this way (with the right syntax)?

Highlighted

Re: If statement to define options in listbox

Solution found, just needed to place the code in the right place. I don't know if this is the best way, but it seems to work as intended:

Sub ListBoxEvent_Exec(Inputs,Outputs)

     If Inputs(1).Value=3 Then

          ListBox.ResetContent()

          ListBox.AddString("N/A")

          ListBox.CurSel = 0

     Else

          sel = ListBox.CurSel

          ListBox.ResetContent()

          ListBox.AddString("Solution1")

          ListBox.AddString("Solution2")

          etc...

          ListBox.CurSel = sel

     End If

Announcements