From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Global variable are not assigned to other files

Hello

 

I have defined & assigning some values to Global files in one of the project files, But the same i am not able to read in other files of the same project.

 

 

i have defined as  'extern int  x ' in one file  & also called in other file by defining 'extern int  x'

 

let me know if you more info needed

 

Hussain

0 Kudos
Message 1 of 6
(4,842 Views)

Hello HussainHTS,

 

I'm not sure I understand your problem. From my understanding, you've defined a variable x as extern in two files, without actually defining it somewhere?

Basically you should define int x in one file and declare it as extern in another file (extern int x). 

Does that make sense?

 

Best regards,

= Nelu F. || National Instruments.

Message 2 of 6
(4,832 Views)

Hello Nelu F

 

Thanks for you valuable inputs, it helped me alot.

 

if we are using same Global variables in 2 diffrent files do we need to define in both files mentioning  exten int x ? or else mentioning in one file is enough? 

0 Kudos
Message 3 of 6
(4,821 Views)

Hello HussainHTS,

 

Basically, you have to define your variable in one file, using int x;. Then, in your other files, doesn't matter how many, if you want to access that variable, you have to declare the variable as extern, extern int x. You should declare the variable extern in all the files you use it. One declaration per file is enough, if that's what you were wondering about.

 

Best regards,

= Nelu F. || National Instruments.

Message 4 of 6
(4,812 Views)

Hello Nelu F

 

Yeah, I was looking for this solution. I have got one more query, can we use any data type like visa data types for declaring variables? i am using ViInt32 not int for declaring variables 

0 Kudos
Message 5 of 6
(4,808 Views)

Hello

 

I am trying to implement this in my program .. but assigning the Global variable is not working 

 

NOTE: I am using LABWINDOWS CVI 5. (Old version)

 

/////***Test 1 contents****///

 

extern ViInt32 A= 0;   // Assigning  ‘0’  to Global variables 
extern ViInt32 B= 0;
extern ViInt32 C= 0;
extern ViInt32 D= 0;

 

if (revision = =1)

{

A=Confirm Popup (“Verifiy”,"Does this unit also have hardware A”);

}

///*** end of Test 1 ***//

 

If I am trying the access above global variable to Test 5 or some other test program within same project

/////***Test 5 contents****///

 

If (A)

{

printf (“the Hardware mod is REV A”);

}

Else

{

Printf(“NO Hardware mod find”);

}

//*** end of Test 5 ***//

 

Now the query is whichever option (YES OR NO) in the confirm POPUP in Test 1. I am getting the output: “NO Hardware mod find”

The reason is the Global Variable is not passing.  

0 Kudos
Message 6 of 6
(4,756 Views)