12-18-2018 08:58 AM
This is an old problem and I'm ..stuck.
A control is displaying an empty array of clusters.
I can detect when there's a left-click on an array element; LabVIEW "creates" elements up to and including the one clicked on and trips an array-changed event. Please find attached an admittedly-poor example of my trying to initialize the float to 1.0 .
Things go haywire when changing an element with 1.0 to something else then attempting an insert.
The only way I can think of finding an insertion is by running a second loop and try to find the point after the insertion, where OldVal[I] == NewVal[j].
LabVIEW, somewhere inside, must know what elements it created and where it created them... but in my spelunking, I haven't found something that returns an array of indexes of new elements.
Does this exist?
Thanks.
12-18-2018 09:31 AM
I dont understand what youre trying to do - can you elaborate on your end goal a bit more? Do you just want the indexes of new elements added when you insert a new array element?
12-18-2018 09:56 AM
I'm guessing a bit, but are you talking about the right click- Insert Element behavior? It sounds like you want to know where that new element was inserted, but if it's a default value you can't tell where it is, right?
I'm personally not aware of a way to determine where the new element went, BUT, a simple way to handle this would be to add another boolean to the typedef and set it to Hidden. Its default value would be False, and when it gets inserted you can simply loop through the array until you see the uninitialized one, then you know the index of the new element. After you find it, set the Initialized flag to True so you don't see it next time.
12-18-2018 10:39 AM
OK, I don't really get it. Can you explain the use case and purpose of all that? Can't you just make a correctly sized array the default and not worry about any resizing?
Can you explain step-by-step how the operator uses this VI and, for all steps, explain what happens and what you expect to happen instead.
(Yes, your code is highly flawed and makes little sense. I would keep the array in a shift register and eliminate all value properties. Comparing two autoindexing array in a FOR loop will stop after the shorter array runs out of elements. Prepending and appending elements to both arrays to be compared does not give additional information, just clutters the code. I am not familiar with terms such as "laminated" in this context. You need an event for the stop button. You don't need the timeout event)
12-18-2018 09:41 PM
My apologies.. I was dead tired after being up all night messing around with this.
Yes, I was thinking of both left-click at the end of an array control *and* of the right-click delete/insert behaviors. Left-clicking on an array control creates elements in the array. Right-clicking on an element allows deleting it or inserting an element before it.
What I'm trying to do is make it easier to enter state data into a PLC-type program. Left-click on an empty spot in the array control and each element of a cluster is initialized to the most common value. That part works fine.
Right-clicking-to-delete-previous works fine.
Right-clicking-to-insert malfunctions in my bad example code.
The default values to an inserted cluster just *happen* to represent a valid data set. So that loop doesn't always work properly.
Speaking to that loop... It stops two ways: (1) Two elements at the same index aren't equal (an insertion) or (2) the shorter index ends the loop (appending to the end). Yeah. If the inserted cluster had the same (default) contents as the element before then, well, "oops".
My first cut at adding a hidden flag broke a load of VIs... something about references.
======
I was looking at the array and wondering about a shift register. But the on-screen display is already "holding" the array... and the data pops out in the event handler and is sent back to the display. There are references pointing at the screen control and semaphores to control access. There could be hundreds of array elements.
I don't know enough about how LV manages memory. If there were 10K elements then does a shift register, in this context, waste memory?
=========
A "parallel" array with the hidden flag. I like it. Wonder how much of a performance hit there would be with 10K or 20K elements having to be copied.