UI Interest Group Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

programmatically add slider ?

I'm looking for a way to programatically add a slider to the standard LV slider.  This is easy in edit mode, you just right click on the slider and the in the context menu there is an add slider option.  Is there a way to get this functionality while the vi is running?  I don't see a way to specify the number of sliders in the property node.  Any ideas?

Thanks

0 Kudos
Message 1 of 7
(7,017 Views)

It is not possible to add a slider programmatically at run time.

Whenever you add a slider the data type of the slider changes.

1 slider -> scalar numeric

2 sliders -> cluster of two scalar numerics

3 sliders -> cluster of three scalar numerics

If you have a certain range of the number of sliders that you would allow, you could try setting the control at edit time to have the maximum number of sliders and then setting the sliders that you do not want to show to have a transparent FillColor and a transparent Slider. That way they will not show.

0 Kudos
Message 2 of 7
(3,844 Views)

You know I would hate to have to do this myself but just an idea.

You could keep a slider hidden and then move it and show it when

every you needed it. You could scale it and everything during run time. Just a thought.

Tim
GHSP
0 Kudos
Message 3 of 7
(3,844 Views)

This is technically possible with VI Scripting available on NILabs. In fact there is a whole group that works on things like this in the LabVIEW APIs group. The reason why you would have to use something like scripting instead of a simple property node can be seen when you think about what that slider will be controlling. WIll you also need new code to hook the numeric from that slider to some piece of your program?

I do not know your applicaiton but it seems like the suggestions of an invisible (or offscreen) slider is the best route. This way you can hook that slider up to something in your code as well. You can also use an array of sliders to get different numbers of sliders to appear and dissappear programatically for more scalable approach.

0 Kudos
Message 4 of 7
(3,844 Views)

VI Scripting won't help you much if you need to change the slider at run-time.  VI Scripting does allow you to programmatically edit a VI but once the VI is running the code cannot be changed without first stopping the VI.

hfettig's suggestion would be a good solution if you only need one such slider.  A more scalable approach would be to create an XControl which encapsulates the behavior you want.  The XControl datatype would be an array of scalars and then you could make a decision in the XControl logic to either hide/make visible sliders or even entire slide controls.  The LabVIEW help entry for XControls is a good place to start if you have never used them -- they let you make "smart" controls that require logic and/or multiple elements into one control which can be used throughout your application.

Good luck, sounds like an interesting application.

0 Kudos
Message 5 of 7
(3,844 Views)

Actually, you can do this with scripting in a fairly straightforward fashion, provided you are comfortable with subpanel use.  Here are the steps:

  1. Create a subpanel to host your control
  2. Create the appropriate interface.  Since the subpanel will be running as a top-level VI you need to create a way to get data into and out of it as needed.  I usually use queues or events.  You can find an example here.
  3. Create a template VI with one slider which uses the interface you created.  I would recommend using the Cluster to Array primitive on the output of the slider so your data type remains constant in your running code.  You can do this with multiple events or queue elements, as well.
  4. When you want to change the number of sliders, open the template (which will create a new VI) and modify the control using scripting (use the Add Slider method).
  5. Copy the data from the existing control to the new one (yes, the data will need to be cached.  A functional global works well for this).
  6. Unload the old VI from the subpanel and load the new one.  This is usually so fast the user will not notice.
  7. Close the old VI to get back memory.

I have done this with tab controls, which suffer from the same issue, and it works well.  However, in the case of tab controls, there is almost always a better way.

As an alternate, it may be easier to use the same subpanel approach and simply create a series of VI which have the numbers of sliders you are likely to use on them.  No scripting necessary.  This would also allow you to standardize on some other type of data structure than an array for output.

0 Kudos
Message 6 of 7
(3,844 Views)

Wow, thanks for all the replies.  I go away for a long weekend and come back to solutions.  Gotta love it.  Anyway, I think I'll go with the predefined number of transparent sliders and programmatically make them visible/enabled.  The reason for all this is to populate an array, but to give the user a visual of the values chosen and how they relate to each other and the max and min available (they are amplifier output levels). I envisioned the slider type control (kinda like the sliders available in a lot of color bar options in various programs, including LabVIEW) as being a good realization of this.  Typically there would be up to 10 elements in the array, but in principal there is no bound.  A drawback to the predefined # of sliders is that I would be artificially setting a limit on this for no good reason, and thus possibly preventing the user from doing exactly what they wanted with an arbitrary cap.  As I am one of the end users, at least I can go back and change this if I see it happening, but we also have customers who wouldn't have that ability, and more restricting would also be running from a compiled exe without the ability to change anything.

Again, thanks.

0 Kudos
Message 7 of 7
(3,844 Views)