09-05-2012 11:05 AM - edited 09-05-2012 11:08 AM
I have attached a snippet of a subVI I'm using to initialize the items and set the values of comboboxes in an array. I modified it slightly so the array being referenced is on this block diagram, not a top level diagram. It took me a while to come to this solution; before I had the combobox part in a for loop and was trying to loop through each array element, get a reference to that element, and set the strings[] and value properties but it was acting all wacky. Then I changed it to the way below and it automatically populates all the comboboxes with the correct values, and then sets their values each to be different (which is what I want!) My question is, why does it work this way? I understand all elements in an array need to be the same (although I did find a work around here.), but the part about setting the values to each be different I was trying to do manually with a property node and a value property, when I realized the combobox just handles it all itself. Is this just a feature of a combobox in an array I need to note for future reference?
edit: I noticed the testers array reference label changed, so hopefully it's still referencing the same control. You may need to relink it.
09-05-2012 11:20 AM
To make sure I'm understanding your question: are you asking why you can set the value for the entire array at once, but not set the value of an individual element in it?
You cannot get a reference to an individual element in an array control. The ArrayElem reference will always refer to the same control regardless of what array index is visible. This isn't specific to a combo-box, every array works like this.
09-05-2012 11:30 AM
@nathand wrote:
To make sure I'm understanding your question: are you asking why you can set the value for the entire array at once, but not set the value of an individual element in it?
You cannot get a reference to an individual element in an array control. The ArrayElem reference will always refer to the same control regardless of what array index is visible. This isn't specific to a combo-box, every array works like this.
I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.
This image
from the "How to Index the Array" section just barely shows the arry index being manipulated.
The code is included in that Nugget if you want to see it for yourself. I can not speak to the fact if it still works in modern versions of LV.
Ben
09-05-2012 12:19 PM
@Ben wrote:
@nathand wrote:
You cannot get a reference to an individual element in an array control. The ArrayElem reference will always refer to the same control regardless of what array index is visible. This isn't specific to a combo-box, every array works like this.
I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.
The ArrayElem property always returns the same reference no matter which element of the array is in the top-left corner, as demonstrated by the code below (screenshot instead of snippet to avoid mangled references and property nodes).
09-05-2012 12:27 PM
@nathand wrote:
@Ben wrote:
@nathand wrote:
You cannot get a reference to an individual element in an array control. The ArrayElem reference will always refer to the same control regardless of what array index is visible. This isn't specific to a combo-box, every array works like this.
I have not tested it lately but as of the time of this Nugget I found that it will point to the top left visable array element.
The ArrayElem property always returns the same reference no matter which element of the array is in the top-left corner, as demonstrated by the code below (screenshot instead of snippet to avoid mangled references and property nodes).
Yes that is true but the value returned when using a property node >>> value will return the top left displayed value. In the code included in that Nugget, I set the size of the control such that it only shows a single element then by manipulating the index control I can raed each element in the array.
At least that is how it behaved back in the day of that nugget.
Yes, my wife left me home alone with a case of beer and LV to find that tidbit. I suspect that feature will one day disapear without anyone noticing.
Ben
09-05-2012 12:39 PM - edited 09-05-2012 12:40 PM
Just to illustrate Ben's point...
09-05-2012 12:43 PM - edited 09-05-2012 12:44 PM
Initially I was trying to loop through the indices of the array by first changing the "index val" to 0,1,2...n, then getting the array element reference to try and get the references to the individual controls within the array. That's when I realized I was having all sorts of issues and this wasn't how references to individual elements in an array worked.
09-05-2012 12:51 PM - edited 09-05-2012 12:52 PM
Now I'm SUPER confused. I originally had it how crossrulz shows (or so I thought I did) and it was acting really strange. That's what prompted me to ask the question I just set it back to be the way I had thought I had it, and I can't reproduce the problem! I wonder if a wire was hiding or I had some referenced wired up wrong and didn't realize it. Ugh, I wish I had just diagram disabled.
09-05-2012 01:01 PM - edited 09-05-2012 01:04 PM
Just so I can pummel this thread and keep it at the top of the list today, I realized what's going on. The screenshot below shows how I had it before. Basically, when I wire an empty array for the "value" up to the array first, it's not fully clearing the array if some combobox elements are still hanging around. Why isn't this emptying the array? See the attached VI if you want code that reproduced the problem.
09-05-2012 01:20 PM
I think all I can do at this point is encorage you "Go Greg, Go Greg Go!" and point out I never attempted to mess with a combo box so you maybe discvering a new behaviour never seen or reported previously.
If you figure it out, please let us know what you find.
Ben