LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Array Index

Solved!
Go to solution

Short: I want to dynamically set an array element to 0.

I have a UI, one control is an array of data.  The user may select any of the elements in the array and that element will be displayed in a separate indicator.  The user may select other operations which will change the array elements and sort out certain types of data.  This reloads the data array.  When this happens I want to set the array element back to 0 and display that element.  However, once the user clicks on an array element that element becomes the active element and when ever I try to reset/reload/reinitialize the array the element value is always the last clicked element.  All these functions are done dynamically using the array reference in sub VIs. I know that setting the array index is not possible.  Does anyone have an idea of how to accomplish this?  

Thanks in advance.

0 Kudos
Message 1 of 15
(7,724 Views)

None of your descriptions make much sense. Maybe you could show us some code instead.

0 Kudos
Message 2 of 15
(7,694 Views)

In particular:

  • How is the element "selected" by the user?
  • What is the meaning of "dynamically"?
  • What is "sort out certain types"?
  • What's the meaning of "reload"?
  • What is not possible?
  • Accomplish what, exactly?

Show us the wrong code and tell us how to operate it, and how it should react instead.

0 Kudos
Message 3 of 15
(7,683 Views)

@PhoenixCall wrote:

Does anyone have an idea of how to accomplish this?  


Get the value with a local, change the element with a replace array element, set the value with a local. Optionally, replace the locals with a Value or Value (signaling) property node.

 

Race conditions alert! If you do this in parallel of other dynamic array changes, you will run into problems. Value changes will get lost!

 

I agree with Altenbach, some code would result in better advice.

 

What you are trying to accomplish sounds like a pretty complex scheme. I wouldn't want all that logic in my main VI. So I'd try to properly separating it (in a class, QControl, XControl or subpanel) as much as possible.

 

 

0 Kudos
Message 4 of 15
(7,643 Views)

I'm sorry for the confusion and frustration with my original post.  I can not give many details due to the nature of the work.  I have made a very simplified example and attached it here. (LabVIEW 2014)

 

Overall goal is to be able to set the active index of the array.  The example uses the array reference because most of the code will be in sub VIs.  There are some steps explaining what I'm doing on the front panel.

I appreciate your feedback.

0 Kudos
Message 5 of 15
(7,608 Views)

I'm not sure if I understand the problem fully, but if you just want to get the first element of the array, use the "index array" function. I put it into the VI you posted and it seems to work just fine for what you say you want on the front panel (see attached).

0 Kudos
Message 6 of 15
(7,604 Views)

Prettypwnie,

Thanks for the reply.

This is a large application that performs most functions in subVIs (already created) which use the reference and the active element to determine what data to work with.  When the user clicks on an element in the data array the front panel is updated with the selected data and that data is manipulated and placed into database tables.  All the other functions are already in place.  If I use the index array function, I will be able to update the front panel, but all the other operations happening with the data and database are going to be using the data array active element (making wrong data in the database).

 

Again, I can use the index array, it would mean rewriting a lot of the code, which I was trying to avoid. 

If you have any other ideas I'm open to hearing them. 

Thank you for taking time to consider my issue.

0 Kudos
Message 7 of 15
(7,596 Views)

So I think this should be approximately possible using a combination of the following posts:

How do I get the index of the selected array element? 

Re: how to highlight a specific element of an array (note, this uses a collection of Windows API calls, and so might help you but could cause problems too)

 

You could use the methods of the first post (and its follow-up posts) to determine the mouse location of the 0th element (you can actually consider doing this more directly if you only ever want the 0th element in this case, using the properties of the array (position) and the size of the element (bounds probably) and calculating the location of that element, then use the second post (or similar) to generate a mouse-down event in that position, and reset the mouse location afterwards... 

 

There doesn't appear to be a way to set which ArrayElem is the ArrayElem programatically...

 

As an alternative, I might suggest the following:

  • Store an index value with the array (or array reference) and pass those together to your functions (as needed)
  • When generating "New Data" (or whichever steps you really have in which you want to do this) set the index to 0
  • When clicking on the array, calculate the index of the element under the mouse (using the above discussed methods, or more practically something like Array index from mouse position)
  • Optional extra - if possible, pass the actual array (or specific elements) rather than references (but I read you have a large app, and so this is probably a non-trivial refactoring...)

GCentral
0 Kudos
Message 8 of 15
(7,588 Views)

@PhoenixCall wrote:

I'm sorry for the confusion and frustration with my original post.  I can not give many details due to the nature of the work.  I have made a very simplified example and attached it here. (LabVIEW 2014)

 

Overall goal is to be able to set the active index of the array.  The example uses the array reference because most of the code will be in sub VIs.  There are some steps explaining what I'm doing on the front panel.

I appreciate your feedback.


I'd use mouse down, not mouse up. Mouse up didn't work for me, as I tend to click and move my mouse out of the value, then release. A mouse down would work.

 

Or, make mouse down set a select value, that becomes active on a mouse up of the VI. The mouse up is only triggered when actually releasing the mouse when hovering the control.

 


@PhoenixCall wrote (in the VI):

5. Notice Selected Value shows the element value of the previously selected index.  *I want it to show the element value of index 0.


So, if you always want the value of element 0, why not get the value (an array) and use index array to get the 1st value?

 

It would be hard to recommend a solution without knowing the complete situation...

0 Kudos
Message 9 of 15
(7,576 Views)
Solution
Accepted by topic author PhoenixCall

Okay, I think I see what you're wanting. I don't think it's a good idea to have your program dependent on the array element focus like that, but I guess if the code's already written, maybe you don't have budget to change it.

I tried hacking around and here's something that might work for you:

prettypwnie_1-1581015811338.png

Maybe defer front panel updates if it flashes (though I didn't see any when I tried it)

Message 10 of 15
(7,541 Views)