LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can gloal vairables can be shared in subvi?

Solved!
Go to solution

I have a question about global variables. no found answer in Forum. 😞

 

i want to share some global variables in different subvi: Starting first subvi from main,

 

and set variables,then in second vi, use these variables.

 

In my test, if i run it from labview , everything is ok. If build  an exe file, the first subvi

 

 cannot be exited. If exit, the value of global variabels are cleared.  I don't know why?

 

Can i use like this? please help me.

 

Thanks.

 

attached my main app. For subvi exit, just call FP.Close.

0 Kudos
Message 1 of 8
(3,498 Views)
I cannot find any global variables in your attached code. Can you show us the rest of the project?
0 Kudos
Message 2 of 8
(3,493 Views)
What happens if you would also place an instance of the global variable in the main VI?
0 Kudos
Message 3 of 8
(3,488 Views)

hi,

 

If read global variables in main vi, it seem to be ok. For example, i must read this global variables firstly in main vi,

 

then they can be seen in another subvi. But i don't knwo why?

 

thanks.

0 Kudos
Message 4 of 8
(3,467 Views)

HI, altenbach

 

Should i update global variable in main vi? There are many setting and  I don't want to display them.

 

is it possible that global variable don't be loaded into memory?

 

Thanks.

0 Kudos
Message 5 of 8
(3,465 Views)

I opened your VI and I do not see either a Global Variable or a subVI.

Since this value is being used between a VI and subVI, why dont you just pass it in and out of the subVI's terminals?

Cory K
Message 6 of 8
(3,441 Views)
Solution
Accepted by topic author mmm2006

The way I underrstand the problem:

 

There is a main VI (main.vi) which successively runs two different VIs via a VI reference.

Let's call them A.vi and B.vi. Both access the same global variable.

 

The main VI does not know about the global variable.

 

First A is runs, then quits. Later B runs and is expected to access the global variable with data left by A earlier. I have not explored this, but I guess that once A quits, the global variable also leaves memory, forgetting everything

 

My suggestion was to place an instance of the global variable in the main VI, forcing it to remain in memory as long as the main VI is running. Apparenlty, this solves the problem.


mmm2006 wrote:

Should i update global variable in main vi? There are many setting and  I don't want to display them.


I would guess it will be sufficient to place the global variable in the main VI to keep it in memory. There is no need to read it or display it's content. Another solution might be to specify the global variable as "startup VI"? I have not tried this.

 

 

These are just speculations, because I virtually never use globals so my experience is limited. I probably would have A.vi write the data to a file which B.vi later can access, for example.

Message Edited by altenbach on 12-26-2009 09:47 AM
0 Kudos
Message 7 of 8
(3,435 Views)

hi, all.

 

thanks all your help. basicaly understanding the root cause. thanks.

0 Kudos
Message 8 of 8
(3,416 Views)