LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

clear/populate ComboBox in a SubVI?

Solved!
Go to solution

I'm building an app with 6-8 pulldown ComboBoxes, and each one will be first cleared and then populated based on a file.  I've written a small vi to do exactly what I want, but I can't figure out how to pass the PropertyNode:StringsAndValues[] from each ComboBox to the subvi?  I'd really hate to have to reproduce this code 6-8 times in my main VI.

 

The first thing I noticed is that my original small VI used the Flat Sequence Structure to make sure that I first Clear out the ComboBox and then populate it -- LabView wouldn't even accept this as a subvi when I tried to add it to my main VI, so I'm breaking the Clearing out into 1 subvi and the populating into another.  I tried to setup the Clearing VI first which is when I noticed that I had found no means of referencing the original ComboBox in my subvi.

 

Anyone with some ideas?

 

Steve

0 Kudos
Message 1 of 8
(5,503 Views)

Just a thought, control reference and property nodes

 

 comboBoxPopulate.png


Paul
0 Kudos
Message 2 of 8
(5,497 Views)
Solution
Accepted by topic author Steve257

Create a reference from one of the combobox terminals, then create a control from that reference.  cut/paste the control into the subVI and use it as a control to pass the reference into the subVI.

 

are you using create->property node->(property)?  That's less useful: Look on the application control pane for the regular property node primitive 

 

here's what these look like:

 

 

  cbox_refs.png

 

once your subVI accepts a comboBox ref, you can put your 6-8 combobox refs into an array and then call your subVIs in a for loop.

 

 

-B

Message Edited by blawson on 11-23-2009 03:49 PM
-Barrett
CLD
Message 3 of 8
(5,495 Views)
Thanks, I'll give it a shot...I'm not real proficient at LV programming, so it'll probably take me a while to get it going -- I'll let you know if I get it working.
0 Kudos
Message 4 of 8
(5,482 Views)

Ah Ha!!!

 

It took me a few tries, but I finally realized that I had to pass the ComboBox REF to my subVI (which is exactly what you said;)), and not the StringsAndValues[] property.  Like I said, I'm still learning LV after many many years of C programming, and it's a lot for my old brain to absorb.  Thanks for expanding my understanding of LV.

Message Edited by Steve257 on 11-24-2009 08:28 AM
0 Kudos
Message 5 of 8
(5,445 Views)

glad I could help!

 

Say, how are you clearing the comboboxes?  Couldn't you just overwrite existing values?

 

If you are going to build this application into an executable, don't depend on the strings[] or stringsandvalues[] lists to be retained between executions.  (it sounds like you're doing the right thing though)

-Barrett
CLD
0 Kudos
Message 6 of 8
(5,427 Views)

I'm planning for the possibility of re-populating my list while the VI is running, and during development, I noticed that the control gives an error if identical elements are entered (I ran into this when re-populating it with the same strings), so to avoid that, I thought the easiest was was to clear it out competely first...Here's how I did it in my new subvi...

Clear ComboBox Array.png

Thats an 'Array Size' vi on the bottom, and a 'Delete fromArray' above and to the right of it.

And, yes, this is a compiled executable, with different ComboBox lists so I have to be able to populate the list 'on the fly'.

Message Edited by Steve257 on 11-24-2009 04:47 PM
0 Kudos
Message 7 of 8
(5,419 Views)

ah, ok.  that works, and it's kind of clever.  but it's just deleting the whole array, so you could just wire a null array constant to the write property node and eliminate the read PN. 

 

note the right hand error case of PJS's code is a routine for  adding one item to the combobox's list (checking first to see if it exists).

 

It's also a good habit to use the error wires

-Barrett
CLD
0 Kudos
Message 8 of 8
(5,404 Views)