LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

determine index of array within event structure

I am doing some testing with dynamically registered events.  For these testing purposes, I have 2 separate arrays of boolean references hooked up to the dynamic input terminal.  The event structure is executing like I expect it to.  The only problem is that I want to know the index within the array for the event that triggered the value change event.  I would have thought I could use the CtlRef node to determine this, but instead it returns a reference to the actual boolean control that triggered the event.

 

I could write a subroutine that searches for the label of the boolean that triggered the event within the arrays, but that is not efficient or good practice.

 

So for instance, if I click on Boolean 2, I'd want the event structure to know it was array #1, index 1.  If I click on Boolean 6, I'd want the event structure to know it was array #2, index 2.

 

Is this possible?

dynamic_es.png

0 Kudos
Message 1 of 6
(2,502 Views)

The CtrlRef node will give you the reference to the array that triggered the event.  You can use a property of that to determine which array it was.

 

If you compare the OldValue with the NewValue node, you'll get an array of booleans.  Find the first value in that array that is False.  That will be the value that is no longer equal to what it was.

0 Kudos
Message 2 of 6
(2,487 Views)

The CtrlRef node is a boolean though....I too would have thought it should be a reference to an array, but it's not.  When I drop down a Visa Property node and hook it up to CtlRef, you can see it is a Bool:

dynamic_es.png

0 Kudos
Message 3 of 6
(2,481 Views)

It looks like when you created the array of boolean references and registered them, it actually created events based on each boolean individually.  Pick a name or label property node and put an indicator on that.  See what the indicator shows.

 

I'm not sure, but it may have been a recent change to LabVIEW that you can wire arrays of references to the RegEvents node to register multiple controls at once, rather than having to iterate through the array of references to register each one individually.

0 Kudos
Message 4 of 6
(2,475 Views)

yeah, if I choose Label.Text property and connect it to a string indicator, as I click on the various booleans, the indicator displays the label of the boolean that I click.

 

Perhaps what I can do instead is give the boolean controls themselves a name that indicates their position in the array, and use the caption property of the boolean to display the text I want the user to see.  So If I have 100 booleans, they are named Bool0, Bool1,...,Bool99.  Then I can just parse the text of the label to get an index into the array.

 

0 Kudos
Message 5 of 6
(2,468 Views)

That is a very good idea.  The caption is good to use for the label you show to the user.  You can change it to show different things, even programmatically, such as if you need to make your application more international and have it display controls in different languages to different users.  It lets you use longer or more descriptive names, without having those long names eat up block diagram space.

 

Another thing I've done is take the control reference and search for it among the array of control ireference.  Search 1-D array will give you the index of the control within the array.  Then I can use that index and apply it to a different array and index out a value from that.  It could be a name, or perhaps a numeric value I use as a multiplier or something like that.  Just make sure there is a one to one correlation between the references in the array and whatever is the other array you are getting additional data from.  For what you have drawn now, it could be a little bit complicated because you actually have two different 1-D arrays of references.  But if you concatenated those arrays together, you'd have a single 1-D array you can search.

0 Kudos
Message 6 of 6
(2,461 Views)