LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Local Variable Does NOT get Updated?

Solved!
Go to solution

Hi all,

 

Please see the attached picture for the problem I am facing. Basically, I want to open up several files in one folder, and use the file names to derive other file names in a different folder and plot the data in all the files.

 

Here is what I am doing:

1. Use File Dialog to select files

2. Create a local variable of "selected files" - see below

3. Derive new files "new files" using the "selected files" and make a local variable of the "new files"

4. Plot data from "selected files"

5. Plot data from the "new files"

 

The reason for making local variables is that I will be accessing the original files and derived files from many places in my VI and I want to avoid uncessary wiring or opening up the File Dialog multiple times (less clicking - my index figure hurts :))

 

Problem: Data from "selected files" get plotted. However, data from "new files" is NOT data from the "new files" of the existing run, but data from a previous run. Apparently, the local variable "new files" does not get UPDATED

with the "new files" from the current run. I have to run my VI twice. Why is this? How can I fix it?

 

 

 

files.jpg

0 Kudos
Message 1 of 27
(4,401 Views)

Is it safe to assume that the sequence exists in your real code?  The problem is a lot more interesting if the sequence is actually there. 

 

If it's not there then the local is being read before the for loop finishes, therefore returning the previous runs value.  This is your classic race condition, and the main reason to avoid locals to begin with.

--
Tim Elsey
Certified LabVIEW Architect
Message 2 of 27
(4,387 Views)

Yes, my code has the flat sequence, and that is why I am a little baffled.

 

I also wanted to add the following: I use the file names to derive the legend for my plots. Could it be that the plots are updated but the legend is stuck from the old run?

0 Kudos
Message 3 of 27
(4,375 Views)

Are you using the sequence structure as you have shown?  This sounds like a classic race condition (the main reason for not using locals).

 

Nevermind.  That's what I get for getting distrcted for a few minutes.


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 4 of 27
(4,373 Views)

@murchak wrote:

Problem: Data from "selected files" get plotted. However, data from "new files" is NOT data from the "new files" of the existing run, but data from a previous run. Apparently, the local variable "new files" does not get UPDATED

with the "new files" from the current run. I have to run my VI twice. Why is this? How can I fix it?


This definitely does not sound right. Can you attach the actual code?

 

0 Kudos
Message 5 of 27
(4,364 Views)

@crossrulz wrote:

Are you using the sequence structure as you have shown?  This sounds like a classic race condition (the main reason for not using locals).

 

Nevermind.  That's what I get for getting distrcted for a few minutes.


Wow, that was almost word for word. 

 

 


@murchak wrote:
I also wanted to add the following: I use the file names to derive the legend for my plots. Could it be that the plots are updated but the legend is stuck from the old run?

If the legend is being updated outside the sequence then it's likely still a race condition, where its getting updated using the old value rather than the new.  Of course it'd be much easier to tell if you attached your actual code.
The only other possible thing I could think of just going off your image is that there is an indicator somewhere else with the same label that your local is tied to, rather than the one in the first frame of the sequence.
Edit: Wow formatting with multiple quotes is a little tough in this editor.



--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 6 of 27
(4,362 Views)

You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.

 

My code is of course more complicated than above in the sense that it takes a lot more to derive the new file names from the selected files, which initially I had created as a subvi which would take in

the selected files as input and spit out new file paths. Initially I had only created a local variable out of the selected paths and feed that into my subvi whereever it was called in my code if I needed to access the new files.

I thought it was my subvi that was remembering the "new files" from an older run, and not the current run, so I took my subvi and stuck in the first frame of the sequence, and created locals of the "new files" to be used in the code.

0 Kudos
Message 7 of 27
(4,360 Views)

@murchak wrote:

You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.


Your sequences and locals take up way more screen pixels than a few wires ever would.


murchak wrote:

My code is of course more complicated than above in the sense that it takes a lot more to derive the new file names from the selected files, which initially I had created as a subvi which would take in

the selected files as input and spit out new file paths. Initially I had only created a local variable out of the selected paths and feed that into my subvi whereever it was called in my code if I needed to access the new files.

I thought it was my subvi that was remembering the "new files" from an older run, and not the current run, so I took my subvi and stuck in the first frame of the sequence, and created locals of the "new files" to be used in the code.



All I can see is gibberish. Show us some code instead!

0 Kudos
Message 8 of 27
(4,348 Views)

@murchak wrote:

You guys have to pardon my ignorance, but this seems like a good instance for using local variables to avoid cluttering up my code wires running from one frame of the sequence to another.


That's the beauty of using a wire though.  In all likelihood you don't even need the sequence if you use the wires.

--
Tim Elsey
Certified LabVIEW Architect
0 Kudos
Message 9 of 27
(4,347 Views)

elset191 wrote:Wow, that was almost word for word.

Great minds think alike.Smiley Tongue


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 10 of 27
(4,338 Views)