From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array to local variable.

Solved!
Go to solution

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?

0 Kudos
Message 1 of 7
(3,928 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 7
(3,917 Views)

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.

0 Kudos
Message 3 of 7
(3,911 Views)
Solution
Accepted by topic author bmand1993

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

0 Kudos
Message 4 of 7
(3,900 Views)

@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

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 7
(3,900 Views)

Thats exactly what I was searching for. Thank you

0 Kudos
Message 6 of 7
(3,856 Views)

@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.

0 Kudos
Message 7 of 7
(3,848 Views)