LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

incorrect parsing on first run

Solved!
Go to solution

I have the attached VI to parse command line arguments of a program I have written.

 

The arguments are pre populated as they would be in the real running envyronment, though I can not always depend on the PN parameter being in the 1nth element of the array.  I am attempting to get the value of the PN parameter.

 

The first time I run the vi, it does not find the value, but every run after that finds the value.

 

 

Any suggestions?

 

Edited to add: If I change a value in the array to a different spot in the array and then run, the first time it will not find the PN, but every time after it will.

 

Edited again: adding parse string.vi to attachments

Message Edited by ctardi on 06-26-2009 11:04 AM
Download All
0 Kudos
Message 1 of 10
(3,598 Views)
Solution
Accepted by ctardi

Race condition!

 

Why are you using a local variable of Index instead of the wire located in the For loop?

 

When your program is first run, the indicator index has a value of zero in it.  That index array uses that value because the local variable gets read before the For Loop has finished running to write a new value to that indicator.  Next time around (assuming you haven't changed any data) the value in the indicator is correct because it is there from the previous run of the VI.

Message 2 of 10
(3,588 Views)

Pesky local variable!

you have a race condition where the variable "Index" is read and passed to the wire into index array before the value of "Index" is updated inside the for loop.

 

Solution is attached


"Should be" isn't "Is" -Jay
Message 3 of 10
(3,586 Views)
@Jeff: The user has 8.5, so they cannot open a VI in 8.6.
0 Kudos
Message 4 of 10
(3,583 Views)

Just figured out the race condition as you guys said it...I had originally used the local variable as I was going to pass the value back to the program calling it, but now I wire it through and write to a variable at the end of the program.

 

Thanks guys! 🙂

0 Kudos
Message 5 of 10
(3,579 Views)

ctardi wrote:

I had originally used the local variable as I was going to pass the value back to the program calling it,


That makes no sense. Can you explain once more?

0 Kudos
Message 6 of 10
(3,563 Views)
This is used as a sub-vi...I initially thought that I was going to want to pass that value to the VI that was calling the sub-vi, so I was putting the value into a variable in order to allow me to do that.
0 Kudos
Message 7 of 10
(3,556 Views)

ctardi wrote:
This is used as a sub-vi...I initially thought that I was going to want to pass that value to the VI that was calling the sub-vi, so I was putting the value into a variable in order to allow me to do that.

You can still do that.  You just connect the connector pane to that particular indicator.  The local variable has nothing to do with the calling VI.  The local variable's context is completely within this VI.

0 Kudos
Message 8 of 10
(3,547 Views)
Hence changing it once I realized my brain fart. Smiley Happy
Message 9 of 10
(3,534 Views)

ctardi wrote:
Hence changing it once I realized my brain fart. Smiley Happy

We all have "Homer Simpson" moments... DOH!


"Should be" isn't "Is" -Jay
0 Kudos
Message 10 of 10
(3,495 Views)