06-26-2009 12:57 PM - edited 06-26-2009 01:04 PM
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
Solved! Go to Solution.
06-26-2009 01:07 PM
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.
06-26-2009 01:08 PM
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
06-26-2009 01:10 PM
06-26-2009 01:14 PM
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! 🙂
06-26-2009 01:53 PM
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?
06-26-2009 02:42 PM
06-26-2009 03:41 PM
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.
06-26-2009 11:02 PM
06-27-2009 01:51 PM
ctardi wrote:
Hence changing it once I realized my brain fart.
We all have "Homer Simpson" moments... DOH!