LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Weird IndexVal bug - Code, that shouldn't work

Hi volks,

 

I have a weird indexvals bug (see vi). The Array is typeof cluster with some elements in it. It is intended as a menu and by now only a proof of concept.

 

I stumbled upon the isse that indexval should return the reference to the topmost array element but does give the reference with an offset that is equal to the index the array was clicked on. 

 

In the deactivation structure you can switch to the code where it does not set the indexval property and if I do so, the correct reference is returned even though labview should not have any clue about what index I want to receive.

 

This makes no sense to me in any possible way as this is a behaviour that is not documented and I have no idea, if it is relieable.

0 Kudos
Message 1 of 13
(221 Views)

I forgot the screenshot:

2025-11-12_09-52.png

To explain the code a little more:
Array is a type of a cluster and I like to know, where it was clicked on. As the list can be scrolled, it calcluates the click position and thus the index. s? t:f return the correct index every time.

 

The lower part reads the reference of the array element and also points to the cluster that was clicked on. IMHO this should never return anything else than the Text.Text value of the topmost array element (index 0). But it does always return the element I clicked on. 

 

If I do the documented way (as stated in the lv help) I have to set the IndexVals value to get the top visible element to get the reference:

 

Nils_Thomsen_0-1762938045653.png

But if I do so, it will always point to the wrong element.

 

For example if I click on the 2nd element and write 1 to the indexval property, ArrElem will point to the 3rd element (as Index 1 + Index 1 = Index 2) what can be seen in the Text.Text element:

Nils_Thomsen_1-1762938166156.png

 

Is there any explaination for this behaviour?

0 Kudos
Message 2 of 13
(147 Views)

"ArrayElem" returns the "active" array element. If no element is actively selected, it returns the topmost visible element.

 

This is just how it works. Always has. I wrote code back in LabVIEW 6 which used this same concept on purpose. To get a specific array element, I set the "IndexVals" to the required value and then read "ArrayElem" before setting the "IndexVals" back to its original value.

 

It's a bit goofy, and it would maybe help if the "ArrayElem" was names "ActiveArrayElem".

 

To do this in your code, you need to se the Index BEFORE reading "ArrayElem".

0 Kudos
Message 3 of 13
(136 Views)

If you see the last screenshot in the deactivation structure and this is where the code fails.

0 Kudos
Message 4 of 13
(131 Views)

In the code you showed where you read the text, you set the Index, but only AFTER you have accessed the array element. This means that the index you provide is not neccessarily corresponding to the array element you have retrieved.  The reference for the Array element remains locked to the index at the time of reading even if you change the index of the array afterwards.

0 Kudos
Message 5 of 13
(126 Views)

Please help me out with my confusion: I thought property nodes are handled top to bottom so setting the indexval happens prior to reading the reference? 

 

However: Changing the order does not affect the result.

0 Kudos
Message 6 of 13
(124 Views)

Well, yes, but the image you privided had the property node with the setting of the index before the element disabled....

If your code is different than what was shown, there's no way I can know that....

0 Kudos
Message 7 of 13
(105 Views)

Just to be clear: First screenshot shows the code working but I was not sure, why. As far as you answered ArrElement is more like a ActiveArrElement and the click on it activated it. So this might (or not) be a relieable behavior.

 

The second screenshot where you can see the disabled deactivation structure is the way NI intended and is not working. In this second screenshot you can see I first set indexval and then read arrelement and this is the non-working version where it weirdly calculates an index based on the offset.

 

Even though the method from the first screenshot seems to work I'd prefer to use the "official" way because it's totally clear what should happen. I don't know all the circumstances when an element inside an array gets "active".

0 Kudos
Message 8 of 13
(98 Views)

There is no specific relationship between the IndexVals property and which element is referenced by the ArrElem property.

The ArrElem property refers to whichever element most recently had text focus.

Message 9 of 13
(74 Views)

Oh I think I got my mistake. I read Indexval instead of indexarray

Nils_Thomsen_1-1763026038104.png

 

Thank you!

0 Kudos
Message 10 of 13
(39 Views)