LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

global variable subvi

Hi,

I have 2 subVIs...each subVI is inserted in an event structure.

In the subVI1 I created a variable and made it global variable.

The problem is that when i read this global variable in subVI2 I find it emptySmiley Surprised

Could u tell me why ? and where is the problem ?
Thx,
Samer,
0 Kudos
Message 1 of 8
(3,688 Views)
And we're supposed to guess without seeing any code?

OK. My guess: race condition.
0 Kudos
Message 2 of 8
(3,686 Views)


samerham1 wrote:
In the subVI1 I created a variable and made it global variable.

You cannot "create a variable" and make it global, but you can make a global variable. (Depending on your LabVIEW version, you can also make a shared variable.)
 
Please clarify what you did and attach some code if possible.
 
Most likely you read the global before other parts of the code have a chance to write to it.
Message 3 of 8
(3,680 Views)
There are the VI and the 2 subVIs

the name of the global variable is "Tableau info base de donnée"

my code is not complicated, i don't understand how this global variable is affected by race conditionSmiley Surprised
Thx,
Samer,
0 Kudos
Message 4 of 8
(3,672 Views)
Hi Samer,

I can only find one occurence of the global variable, so I cannot follow your question...

Btw. what's the size/resolution of your screen? Your block diagrams are huge (and waste a lot of real estate spaceSmiley Wink)!
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 8
(3,659 Views)
You are never actually writing a value to the global variable. In your "subVI_database_general" you are populating a control on the front panel of this VI. This information is not "magically" written to the global variable just because it has the same name. The value that you set to the control also has to be written to the global variable.

That said, you have a few other problems. Here's some additional comments/questions:
  • In your subVI_database_general:
    • Why is "Tableau info base de donnée" a control? There seems to be no reason for this, as the user does not directly change this.
    • The "nouvelle base de donnée" hidden control should probably be a typedef.
    • Why use a separate free-floating label for the big red "OK/Cancel"? Just make the caption visible for the button and modify the text style as needed.
    • If you set the VI Properties so that the Window Appearance is "Show front panel when called" and "Close afterwards if originally closed" then you do not need to explicitly set the Panel State to "Closed".
  • In your subVI_process_general:
    • Same comments regarding the "OK/Cancel" button and the VI Properties
    • You are populating the menu ring when the user presses the "Create the Process" button, but you are dependent on the selected item from the menu ring in there. You have to populate the ring first! This means you have to do it when this subVI starts up.
    • Why do you have a separate "Liste Process créés" control and indicator? (more on this later)
  • In your main VI:
    • Same comments regarding the free-floating label for the buttons.
    • You seem to be using an integer array output from the subVI_process_general VI and assuming that this corresponds to the listbox, so you try to access the item names from that. This will not work. The output of the subVI is just an array of numbers. It's not a listbox. If you want to modify the Final Process List names then you have to either:
      • pass out a string of names from the subVI that you append to your list
      • pass in a reference for the Final Process List to the subVI so the subVI can append to the list.
Whew! That's enough for now.
Message 6 of 8
(3,653 Views)
"I can only find one occurence of the global variable, so I cannot follow your question..."

I forgot to attach the global variable vi file
"global_subvi_1"...here it is...

the variable "Tableau info base de donnée" is used in "suvi_database_general" and i put it in the global variable vi "global_subvi_1"

Then i used this global variable as input in the subvi
"suvi_process_general"...

When i create a database in
"suvi_database_general" the variable is filled but i use "suvi_process_general" i find the global variable empty Smiley Surprised

I don't see where is the problem or the mistake that i made...could u help me ?
Samer,
0 Kudos
Message 7 of 8
(3,629 Views)
Hi samer,

have you read smercurios message?
You only access this global variable once! And is a read access, you never write to that global. Just making a copy of your control (local in subvi1) into "global_subvi" doesn't create a connection between them! You just created a global using the same name with NO connection to that (local) control...

Either use this global in each subvi or use inputs/outputs in each subvi and a shift register in the main vi...
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 8 of 8
(3,624 Views)