07-26-2019 08:16 AM - edited 07-26-2019 08:17 AM
Hi Chythanya,
still no code, but just images…
Your "simple" way is "complicated" because you hide relevant information in this ArrayToCluster node.
The "complicated" way is much simpler once you resize the IndexArray node and forget about wiring the index inputs!
And that "no loops" requirement most often is non-sense…
07-26-2019 08:17 AM
@Chythanya wrote:
You can expand the Index Array for as many elements of the array as you need - no need to have one for each index.
07-26-2019 08:27 AM - edited 07-26-2019 08:59 AM
No. The complicated way is the correct way, and not even that complicated.
Put in Index Array. Drag the bottom border downward. Don't mess with putting in the 0, 1, 2, 3, constants. Now you've got every element of the array with a single node.
Also, what is wrong with using a loop? That would be the correct way of doing this.
An array is a collection of like elements, and it can have a variable number of those elements. The problem with your "simple way", is it fixed to however many elements you bundle out. It also has a hidden limit built into that Array to cluster node that defaults to 9. If you tried to work with 10 or more elements in the array, your code will break until you also change that hidden property.
The problem with this and also the "complicated way" you show is that anytime you decide to work with more elements in the array, you have to modify your code. It is completely inflexible to the number of elements in the array. And since you don't show what you do with any of the values after you have extracted them, (you must be doing something!) there is more code that has to be created than what you've shown here.
A loop will run as many times as needed.
Loops are the correct way!
I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
Learn LabVIEW
07-26-2019 08:27 AM
I am not asking for the use cases. Normally I will use the index array for doing the same operation.
My question is What's the problem between Initializing shift register and array of cluster conversion.
It has to work same in both cases but it isn't.
When I initialized Shift register outside it is fine and when I do it inside the loop it is not working as expected.
07-26-2019 08:51 AM
If you insist on doing it the complicated way then the workaround is to do all elements and then do the individual elements. I don't know why the behavior is different. People aren't giving you other "use cases." They're giving you advise on how to better structure your program for your use case.
07-26-2019 08:57 AM - edited 07-26-2019 08:58 AM
It is working exactly as you have it coded. I am going off of your first screen capture.
The first While Loop you initialize your shift register OUTSIDE THE LOOP so you have all the elements there (in this case they are blank as they are grayed out so you'd see no values when you try to access the data) and you only run it once because you have a true constant in the conditional terminal.
In the second loop, you have a Uninitialized Shift Register and, again, your running it only once because you have a true constant in the conditional terminal. It's blank too because there is nothing feeding it from the outside into the While Loop. While you do have your cluster wired to the right hand side of the While Loop, you only do one iteration so you don't see the data on the next iteration.
07-26-2019 09:08 AM - edited 07-26-2019 09:15 AM
@Chythanya wrote:
My question is What's the problem between Initializing shift register and array of cluster conversion.
It has to work same in both cases but it isn't.
When I initialized Shift register outside it is fine and when I do it inside the loop it is not working as expected.
As I said in my earlier message, it is probably something within the way LabVIEW is compiling the code and analyzing the data types. Something deep down. I bet AristosQueue would have an explanation if he sees this thread. It might even be a bug in the underlying LabVIEW code.
It is definitely an interesting question you have here. I'm curious to find out the answer. But it is purely an academic question because what you are trying to do isn't the correct way to solve your programming objective.
If you want to experiment, try throwing in some Always Copy primitive in those wires. That tends to make the compiler behave differently and helps force things a certain way when the default compilation is not behaving the way you expect.
EDIT: For everyone who is talking about the way the two examples have different execution. That is not the point of Chythanya's question. As I said in message 8, the effective result of the data between both the way it is programmed is the same. The question is about the way the VI wires up in development environment before you ever worry about hitting the Run button. The cluster out of the "Array to Cluster" is different. It is hard to see how different because we still haven't been given an actual .vi file we can poke at.
One thing I was going to say in message 13 and forgot was that the array being worked with here is a bit more complicated than a normal array where there is an array of a simple datatype. This is an array of clusters, so what the output of the array to cluster function would be would certainly be more complicated. And for whatever reason hidden under the surface, LabVIEW is creating a different cluster between the two methods even though it appears on the surface of the block diagram the results would be identical.
But a real VI we can poke at would sure be nice ..........
07-26-2019 09:36 AM
The point the OP was trying to make is that the UBN cluster only shows up as array[0] regardless of what element is selected when the shift register is un-initialized (compared to when the cluster is outside the loop)
07-26-2019 09:45 AM - edited 07-26-2019 09:49 AM
@Frozen wrote:
The point the OP was trying to make is that the UBN cluster only shows up as array[0] regardless of what element is selected when the shift register is un-initialized (compared to when the cluster is outside the loop)
SpoilerI also agree with everyone else that this programming method is flawed
It is even weirder than that. If you select all elements instead of Name then it will show up with the correct array element.