09-23-2019 08:52 AM
Hi I have an array with two elements. And I want to read those elements using two local variables. How can I write those two elements into two local variables?
Solved! Go to Solution.
09-23-2019 09:00 AM
For what reason are you using Local Variables? The wire is the variable, so you need to have a very good reason for bringing in local variables.
Note: I am mostly stating this since the question screams "Newbie" and newbies tend to WAY over use local variables and then get burned by race conditions and memory issues.
09-23-2019 09:03 AM - edited 09-23-2019 09:04 AM
So I have an 1D array with two elements. Now I want to use those two elements in the next sequence as a selector of switch case. How can i do that? And yes I am new to labview.
09-23-2019 09:10 AM
I see you are a New Member, and I guess you just started learning LabVIEW. The "best" answer to your question of how to take the data in the wire and express it as two local variables would be "Don't do that!".
One of the most basic Principles of LabVIEW is the Principle of Data Flow, which says that data controls the timing, sequencing, and execution of Structures and Functions (including user-written VIs). Local Variables "break" this Principle -- you cannot tell where (or, equally important, when, or even if) the data were written or read previously (or subsequently).
Without seeing your code and knowing what you want to do (that's a hint -- when you post to the Forum, attaching your VIs really helps us to help you), the way I would do this is to take the Array wire and run it into an Index Array function. By itself, this gives you Element 0, and if you wire a "1" into the Index input, it gives you Element 1.
You can also use Index Array to get both elements, but I urge you to resist the temptation to wire them to two Local Variables!
Bob Schor
09-23-2019 09:10 AM
@bmand1993 wrote:
So I have an 1D array with two elements. Now I want to use those two elements in the next sequence as a selector of switch case. How can i do that? And yes I am new to labview.
Index Array is used to get elements from arrays.
/Y
09-23-2019 11:12 AM
Thats exactly what I was searching for. Thank you
09-23-2019 11:24 AM
@bmand1993 wrote:
So I have an 1D array with two elements. Now I want to use those two elements in the next sequence as a selector of switch case. How can i do that? And yes I am new to labview.
You just use a plain wire to the next place where it is used. Dataflow fully determines execution order, so you can remove that sequence. It just clutters the diagram.
Also, an array cannot be used as a selector for a case structure (if that's what you mean by "switch case"), but there are many possible solutions, but they really depend what the cases are and how they depend on the input(s).
It would be best if you can show us your code so we can guide you in the right direction. At this stage of learning if will help tremendously to navigate around common beginner mistakes and shorten the learning curve.