LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Having Trouble Copy and Pasteing Local Variable in LabVIEW 2010

I am Having Trouble Copy and Pasteing Local Variable in LabVIEW 2010 in s subVI.

 

I have a VI that has a Local Variable called "Node Addr". I can select it OK, and it appears to Copy OK, But when I go to paste it, nothing appears. It doesn't matter if I use Cntrl-C Cntrl-V or the Copy and Paste from the Edit menu, I get the same results. I tried many times and got the same results. I made sure that I had click a paste location. I can insert the Local Variable if I use the Data Communication panel.

 

On one of the Paste, I got an error in the error list that said that a Local Variable was not connected to anything. When I clicked on the error, it took me to an insible item in the lower right corner of the block diagram that had nothing but a select box around it. I couldn't select the invisible item, but I could delete it.

 

Why does the copy and paste of this local variable not work?

 

Why does the paste cause the insertion of an invisible item?

0 Kudos
Message 1 of 43
(5,037 Views)

Local variables are scoped within a VI only.

 

If you want to use variables in multiple VIs, then have a look at global variables or single-process shared variable.

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 43
(5,030 Views)

Some notes in addition to Adnans reply:

 

- Using variables is often considered to be bad programming style. This is because variables tend to create situations of "Race Conditions" where the code does not exectue as expected. Those are hard to debug and therefore to be prevented as soon as possible. So leaving possible sources of race conditions out of the code is good programming style.

 

- A local variable refers to a frontpanel element of the very VI. If you copy a local variable (in the block diagram) and insert it in another VI (also block diagram), the variable should be copied properly. Since it refers to a control, LV has to create a new control for the variable (e.g. Numeric => Numeric 2). This works as expected on my machine.

 

- Due to the focus of local variables (as mentioned by Adnan), copying a local from VI 1 to VI 2 makes no sense.

 

- I am not familiar with the term "Data Communication panel". What is this?

 

- If you are talking about invisible controls: Are they hidden (property) or just in a place outside the displayed panel bounds?

 

hope this helps,

Norbert

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 3 of 43
(5,019 Views)

@Norbert B wrote:

Some notes in addition to Adnans reply:

 

- Using variables is often considered to be bad programming style. This is because variables tend to create situations of "Race Conditions" where the code does not execute as expected. Those are hard to debug and therefore to be prevented as soon as possible. So leaving possible sources of race conditions out of the code is good programming style.

 

- A local variable refers to a frontpanel element of the very VI. If you copy a local variable (in the block diagram) and insert it in another VI (also block diagram), the variable should be copied properly. Since it refers to a control, LV has to create a new control for the variable (e.g. Numeric => Numeric 2). This works as expected on my machine.

 

- Due to the focus of local variables (as mentioned by Adnan), copying a local from VI 1 to VI 2 makes no sense.

 

- I am not familiar with the term "Data Communication panel". What is this?

 

- If you are talking about invisible controls: Are they hidden (property) or just in a place outside the displayed panel bounds?

 

hope this helps,

Norbert


  1.  My VI is fairly complicated. In several places in the VI, I am either reading or writing to this variable which is an numeric Indicator on the Front Panel. Using local variables seems to be the best way to handle this situation rather that using wiring all over the VI. Since the VI is mainly a State Machine and there are only 2 Writes to the local variable, I am not afraid of race conditions in this case.
  2. I am not copying the Local Variable from one VI to another.
  3. I am not copying the Local Variable from one VI to another.
  4. The Data Communication panel is one of the panels that shows up in the Functions pop up list when editing the Block Diagram. It is the panel that includes the Local Variable function.
  5. I don't know if the invisible item that was inserted in my block diagram was hidden or not. All I know is that the Errors List said that it was a Local Variable and that it was not connected to anything. I couldn't select it to get more information. All I could do was delete it.

You did not address my questions about why the Copy and Paste does not work properly for my Local Variable.

0 Kudos
Message 4 of 43
(5,005 Views)

@adnan Z wrote:

Local variables are scoped within a VI only.

 

If you want to use variables in multiple VIs, then have a look at global variables or single-process shared variable.


I am not using the Loca Variable in multiple VIs.

0 Kudos
Message 5 of 43
(5,002 Views)

You are right that i did not answer the question why your copy and paste does not work. All i said is that i cannot reproduce this behavior and on my machine it works as expected:

Inserting the copy, it will create a new variable including a new control.

 

Maybe you should post the VI where you encounter this odd behavior in order to let us see the issue with our own eyes.

 

 


@dbaechtel wrote:
[...]The Data Communication panel is one of the panels that shows up in the Functions pop up list when editing the Block Diagram. It is the panel that includes the Local Variable function.[...]

Ah, i see what you are talking about. What you call "panel" here is commonly referred as "palette". If you drop a local from there, you have to select the control you want the local to refer to. If you don't, you will get a black variable box which represents: Undefined datatype.

 

 

So i suggest you not to copy a local variable, but to drop new ones from the palette and bind them to the same control.

 

hope this helps,

Norbert

 

PS: Reading and writing to the same elements using variables will most probably lead to race conditions. So you should consider to switch to functional global variables (FGV, aka "Action Engine") or use queues/single element queue for storage.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Message 6 of 43
(4,989 Views)

 


@dbaechtel wrote:
  1.  My VI is fairly complicated. In several places in the VI, I am either reading or writing to this variable which is an numeric Indicator on the Front Panel. Using local variables seems to be the best way to handle this situation rather that using wiring all over the VI. Since the VI is mainly a State Machine and there are only 2 Writes to the local variable, I am not afraid of race conditions in this case.  NO!! While you may think that using Locals is your solution to wiring, it is not!  The fact that you are writing and reading, most likely from several places, will most definitely contribute to a race condition.  Depending on your implemetation, you should ALWAYS use wires.  The wires are the variable.  If you are using a loop (While, For), then using shift registers are appropriate means for routing values so that they are used by other sections of the code, later.  One thing you must respect with LabVIEW is the dataflow.  That's where Locals often fail.
  2. I am not copying the Local Variable from one VI to another.
  3. I am not copying the Local Variable from one VI to another.
  4. The Data Communication panel is one of the panels that shows up in the Functions pop up list when editing the Block Diagram. It is the panel that includes the Local Variable function.
  5. I don't know if the invisible item that was inserted in my block diagram was hidden or not. All I know is that the Errors List said that it was a Local Variable and that it was not connected to anything. I couldn't select it to get more information. All I could do was delete it.

You did not address my questions about why the Copy and Paste does not work properly for my Local Variable.  Maybe it's a sign from the Software Gods not to use them 😉 LOL!.. 😄

So if I understand correctly, you are trying to copy & paste the Local Variable from within the same VI.  How large is your block diagram?  Did you try right-click on the variable and select "Find > Local Variables"?  If it's a block diagram larger than 1 single screen (which it shouldn't), then it is possible that the Local is hiding beyond the screen.  You should find it as I described earlier.


See my comments in red above.

 

Message 7 of 43
(4,987 Views)

I had a race conditions with your replies  🙂

 

Listen to Norbert's advice.  Use a Functional Global if you trully need it.  Wires is the appropriate way to go as they ensure dataflow.

0 Kudos
Message 8 of 43
(4,983 Views)

What is the difference between reading from a Local Variable which contains the Value of a Front Panel Numeric Indicator and reading from a Variable Property Node that reads the Value of the same Front Panl Indicator?

 

Why does one tend to give you a race condition and the other does not?

 

 

0 Kudos
Message 9 of 43
(4,959 Views)

I can not use a Global Variable or FGV because this is a reentrant VI and the method used must be Local to the Instance of the VI.

0 Kudos
Message 10 of 43
(4,957 Views)