LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

passing string out of for loop of a sub_vi

Hi, all I am relatively new to programming.  It seems like an easy problem but I am having a difficult time around it.  I wrote a vi that have a different string in each cycle of it's for loop.  While running the vi itself, I can simply hook up a string indicator to display that string.  So with each cycle, the front panel would display the string for that cycle.  I then hook the string indicator up to one of the terminal.  Now, when I try to run that vi as an sub_vi in another program, the terminal would only output the string at the end of the for loop.  I would like is so that I am able to output the string and be able to display the string within each cycle inside the sub_vi.  Is there a simple way to implment this?  Thanks for the help  
0 Kudos
Message 1 of 5
(2,936 Views)

The reason you don't see an update is due to data flow.  No data appears at any output terminal until the loop has finished executing.  That is a data flow rule.  So naturally when the loop is done and data is sent out, you only see the last string generated.

In order to see the updates for each subvi loop iteration in a main vi, you need to access the subvi indicator by reference.  The attached llb contains a main and a sub vi.  This will show you how to access the subvi's indicator and display the value in main as it is being changed in the subvi.

 

- tbob

Inventor of the WORM Global
Message 2 of 5
(2,927 Views)
Thanks for the response.  I am playing around with your vi's hopefully I will figure out how it all works.  Thank you so much. 
0 Kudos
Message 3 of 5
(2,911 Views)

Here is a bit more explanation to help you understand.

If you have a variable in a vi, this variable's value is stored in a particular memory location on the computer.  If you pass this variable to a subvi, the subvi will create a new memory location for the value.  If the value changes in the subvi, memory location 2 is changed but not memory location 1.

Now if you create a reference to the variable in the main vi, you are capturing the "address" of the memory location of the variable.  That's what a reference is, an address of where the value is stored.  If you pass the reference to the subvi, then any changes in the subvi will be written to the address of memory location of the variable being referenced.  So now changes in the subvi will be recognized by the main because the value is being stored at the same memory location.  Another way to put it is that a reference is like a pointer in C.

Is this clear?

- tbob

Inventor of the WORM Global
0 Kudos
Message 4 of 5
(2,906 Views)
Yeah. the explanation makes perfect sense.  I am having problem implmenting it because I am new to labview and doesn't know where to find the right function, assigning right cast type etc.  I need to spend more time reading help files.     
0 Kudos
Message 5 of 5
(2,902 Views)