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

Set the default value for a parameter with a selection menu

yhuang-3
1-Newbie

Set the default value for a parameter with a selection menu

Hi All, I have a variable with selection menu in the middle of a worksheet. Ideally, the default initial selected value should come from the calculation of a previously calculated number (which depends on the previous calculation).

Would anyone teach me how can I add a button or do some operation to set up the initialization of the selection table? Thank you!

initialization of a selection table.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
Werner_E
24-Ruby IV
(To:yhuang-3)

> (1) If I have several options of R11, how can I edit the script? Right now I see (options default setdef), but am not sure how to modify this code when I have more than 3 values in the list box.

You mean if there are more options to chose from? You don't have to change anything in the script. The vector "Options" simply would have more entries. I had chosen this convenient way to provide the captions for the options rather than hardcode them in the script (the code to do so is from Richards collection).

The three input parameters for the list box are

1) "options"; This is a vector of stringvalues representing the captions of the various entries of the list box. Being a Mathcad vector they can easily be editited and you may hide the definition of that vector in a collapsed region if you want. If you have more than three options you would have to resize the component and maybe its a good idea to turn on scrolling if you have a large list. (Right click -> Mathsoft Listbox Control Object -> Properties -> Vertical Scroll) see attached file

2) "default" This variable is the number of the item which should be the default entry and depends upon previous calculations (I simply assigned a value). Counting begins with 1 (which is the reason a had to subtract 1 in the script because VB begins numbering with 0).

If this variable has an invalid value (too large or too low; decimals values are rounded) the last selection remains in place. Exception is when default=0. Then the list box return the (invalid) value 0.

The script ensures that whenever the value of the input variable "default" changes a new default is selected.

3) "setdef" This variable is the output value of the "Reset to default" button (which simply counts it up by every click). Similar to "deafult" - whenever this value changes the listbox selects its default. Thats the reason the button works (as long as it changes its output value by every click).

So you see the three input variables do NOT correspond to the number of values you may select from.

> (2) If I can several listbox, say R11, R22, R33..., and I can calculate R1, R2, R3...., is it possible to use one button to set all the values in the listbox to its default values?

Yes, as long as all the listboxes share the same third parameter (the output value of the button. See attached file.

View solution in original post

9 REPLIES 9
-MFra-
21-Topaz I
(To:yhuang-3)

Hi, yhuang-3,

radio buttons group 0.jpg

radio buttons group.jpg

Werner_E
24-Ruby IV
(To:-MFra-)

You show how to make different calculations based in the user selection of the radio buttons ("index").

From what yhuang-3 wrote I guess he knows how to do that but what he is asking for is a way to set a default value for "index" based on the value of R1 while the user still should be able to select a different index by clicking on the appropriate radio button.

I was only able to provide a way where the default value is properly selected based on the previous calculation right after loading the worksheet.

Changing the calculation would unfortunately not result in a new default value. Obviously we need scripted controls but I don't know how to reset a listbox or a set of radio buttons back into a "virgin" state as it is when the worksheet starts.

Werner_E
24-Ruby IV
(To:yhuang-3)

As I understand your question you know how to setup listboxes or radio buttons to choose values but want to know how to control the (first) default selection via a previously calculated variable.

What you demand needs scripted controls, Unfortunately you can't use the easier (and better looking) web controls. Because the scripts in those controls can do damage you are asked when you open a sheet containing that kind of controls if you want to disable those objects. Obviously you will have to click on "no".

Attached is a file containing a listbox and a set of radio buttons which do what you demand - but only just when you open that worksheet. If the variable which should control the default selection is changed later, the previous selection remains. The default selection behaves like somebody has manually selected it. Once the user selects an option it must stay valid until he changes that options.

Consider that a user selects an option different to the default and a calculation below forces a recalculation of the worksheet. There would be quite some confusion if the selected option would then change without the user being aware of.

The scripted components basically were taken from Richards fine collection of various controls and components which you can find here:

Extra Components and Controls

RichardJ
19-Tanzanite
(To:Werner_E)

The scripted components basically were taken from Richards fine collection of various controls and components which you can find here:

Extra Components and Controls

. The reason I didn't reply sooner to this is that I thought I didn't have an off the shelf solution. That and the fact that I am ridiculously busy right now (which is why I have kind of dropped out of sight recently; just no time for it). I assume you at least modified the scripts (I have not checked).

I really need to update that worksheet. Too many of the controls do not work under Win 10, and I have replacements for some that do work. I need more hours in the day though

Werner_E
24-Ruby IV
(To:RichardJ)

Yes, I already missed your contributions!

The scripts were modified slightly to fit the situation given but I wonder if its possible that a set of radio buttons or a listbox is set to a new default value when a specific variable in the Mathcad sheet which determines the default is changed. I guess that its such a behavior which yhunag-3 would need.

Werner_E
24-Ruby IV
(To:yhuang-3)

OK, here is a solution with a list box.

Whenever the variable "default" is changed, the listbox is set to this value as default, but the user can change a different option.

After the user changed the option, the only way to obtain the default is to change the value of the variable "default".

Werner_E
24-Ruby IV
(To:Werner_E)

Here is an enhancement.

I added a button to reset to the deafult (without having to change the variable "default").

Thank you Werner! I have additional questions regarding your solution:

(1) If I have several options of R11, how can I edit the script? Right now I see (options default setdef), but am not sure how to modify this code when I have more than 3 values in the list box.

(2) If I can several listbox, say R11, R22, R33..., and I can calculate R1, R2, R3...., is it possible to use one button to set all the values in the listbox to its default values?

Thank you!

Werner_E
24-Ruby IV
(To:yhuang-3)

> (1) If I have several options of R11, how can I edit the script? Right now I see (options default setdef), but am not sure how to modify this code when I have more than 3 values in the list box.

You mean if there are more options to chose from? You don't have to change anything in the script. The vector "Options" simply would have more entries. I had chosen this convenient way to provide the captions for the options rather than hardcode them in the script (the code to do so is from Richards collection).

The three input parameters for the list box are

1) "options"; This is a vector of stringvalues representing the captions of the various entries of the list box. Being a Mathcad vector they can easily be editited and you may hide the definition of that vector in a collapsed region if you want. If you have more than three options you would have to resize the component and maybe its a good idea to turn on scrolling if you have a large list. (Right click -> Mathsoft Listbox Control Object -> Properties -> Vertical Scroll) see attached file

2) "default" This variable is the number of the item which should be the default entry and depends upon previous calculations (I simply assigned a value). Counting begins with 1 (which is the reason a had to subtract 1 in the script because VB begins numbering with 0).

If this variable has an invalid value (too large or too low; decimals values are rounded) the last selection remains in place. Exception is when default=0. Then the list box return the (invalid) value 0.

The script ensures that whenever the value of the input variable "default" changes a new default is selected.

3) "setdef" This variable is the output value of the "Reset to default" button (which simply counts it up by every click). Similar to "deafult" - whenever this value changes the listbox selects its default. Thats the reason the button works (as long as it changes its output value by every click).

So you see the three input variables do NOT correspond to the number of values you may select from.

> (2) If I can several listbox, say R11, R22, R33..., and I can calculate R1, R2, R3...., is it possible to use one button to set all the values in the listbox to its default values?

Yes, as long as all the listboxes share the same third parameter (the output value of the button. See attached file.

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."