LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically make an array control row "active" when added

Solved!
Go to solution

Apologies if this topic has been covered before, but I've been unable to find anything that might help me.

 

I'd like to allow my user to create a list of commands from a series of arrays mostly of enumerated controls. The user can add or remove rows, however each new row enumeration is blank/"inactive" when the new row is added; the user has to select an option from the drop box to activate that row. (see image)

Front.PNG

 

I would prefer to give each new row a default value so that the user doesn't save the command list with blank entries mixed in. See my most recent attempt to do this below.

 

Rear.PNG

 

Unfortunately this approach still does not "activate" the new rows. Is anyone aware of a solution to this issue? I've attached my .vi code as well.

0 Kudos
Message 1 of 3
(2,786 Views)
Solution
Accepted by topic author amichael

Hi amichael,

 

You'll want to use the Build Array function to append new values to each array, rather than Replace Subset. Currently, you are increasing the number of visible, but not necessarily instantiated, rows in the front panel and then replacing values that don't actually exist. I was able to achieve functionality similar to what you want by simply substituting Build Array for Replace Subset.

 

As an addendum, I would recommend a few coding practices. First, you should make sure to typedef all of your enums. This will allow you to more easily edit the enums while programming. Right now you would have to change every enum individually if you wanted to add a value. With typedefs, you only have to change the typedef and they will all adjust automatically! Second, I would recommend trying out a table to store your user input, instead of arrays. Your current implementation is basically using a set of arrays to make a table. Alternatively, you could try representing each command as a cluster from the start and use a single cluster array to store commands. You can then arrange the cluster controls vertically for ease of use.

 

I would also recommend creating a subVI whenever you find yourself duplicating code this much. For example, you could bundle all of the property node manipulations for a single array during the "Add Subcommand button" event and create a subVI that takes only a reference. Then, this subVI can be called for each individual array (command property). Not only will this save you time since you don't have to rewrite code, it will also make your code more readable and easier to debug! (You could even go further and pass the subVI an array of references that is fed into a for loop to support a variable number of command properties.)

 

Duncan W.

 

P.S. Please remember to upload your most recent code to the forums. It would have been nice to have the code that you posted a screenshot of to speed up debugging.

0 Kudos
Message 2 of 3
(2,751 Views)

Duncan, 

 

I really appreciate your quick and thorough reply. There's a lot of good advice in here; I'll try implementing your methods when I get back at it tomorrow. Thanks!

0 Kudos
Message 3 of 3
(2,747 Views)