user25974: I have 2 .ino files (2 tabs) for one Arduino project/sketch: MySketch_File1.ino and MySketch_File2.ino.
I declared in MySketch_File2 variables and functions which I want to use in MySketch_File1, but I get this error massage: 

error: 'a' was not declared in this scope

//MySketch_File1.ino
void setup(){
Serial.begin(9600);
Serial.println(String(a));
}

void loop(){

}

Second file:
//MySketch_File2.ino
int a;

How can I declare variables and functions one time in one .ino file and use it across multiple .ino files?

user15180: In Arduino the sketch.ino is the main (and only) program, which runs on the processor. 
If you upload another sketch to HW, then the previous one is overwritten and does not longer exist on the HW. So there is no way, they can share variables, as they never are run at the same time.
(You can store some values to EEPROM or to external devices, but it is other thing).
What you probabely want to do is use the second file as a library, which is collection of variables and functions, that more then one program can use. Anyway what is used is the text of the library, not the values assigned to variables in one sketch.ino - so other sketch.ino using the same library would have the functions and variables of the same name accessible, but as it is compiled to othe program, the values assigned in one sketch would not be visible in other sketch.
Can you specify, why you want to use variables and functions accross multiple .ino files?
If it is just to not have type it again and again and fix found bugs in each aned every copy separately, then you are looking for libraries.
If you want to share also values (like read and compute value in one .ino then upload another .ino and use the result) you are looking for persistent storages (EEPROM on the chip, SD card via some reader or something like that.
If you want have more Arduinos running at the same time and sharing some values, you are looking for networks, like I2C, Serial communication, Ethernet and such.
If you want run mor programs on one arduino at the same time, you are looking for multitasking where each program is interrupted repeatedly and other one is continued, fast enought to user not notice, or for creatinig more functions and call them from loop() one after one to eg. read sensors, then light LEDs then run motors. State automats can make your way here easier.

user52996: It is simplest to put only one .ino file in a directory with the filename. Why does an `.ino` file have to be in a folder of the same name? 
Option 1 (cleanest option): Create a user library.
Option 2  (workaround): Relative paths for #include aren't supported but you can use a symlink to make it appear that there is the same header file in every directory:
sketch1/
  sketch1.ino
  mylib.h
sketch2/
  sketch2.ino
  mylib.h (this is a symlink to sketch1/mylib.h) 

Option 3: Avoid Arduino IDE entirely and build using avr-gcc. Example: http://thinkingonthinking.com/an-arduino-sketch-from-scratch/ and Will a .ino Arduino Sketch compile directly on GCC-AVR? This is much more complicated, but supports bigger projects using Makefiles.

user4143: When you compile multiple files in the Arduno IDE the files first get concatenated together.
It happens in alphabetical order, except the main INO file (the one named the same as the folder it's in) is placed first.
In C the order in which things appear in the file matters. Basically you have to make sure that things (like variables, functions, etc) are defined before they are used.
This gets more complex when you have a hidden thing like file concatenation messing things up.
The Arduino IDE tries to hide some of it from you too by making function prototypes, so it doesn't matter what order you define functions in - however that "helpfulness" means you don't learn about the proper structure of a C program.
So what can you do? Well, simply make sure that all your global variables are defined in the main file, unless you know they are only going to be used within the file they are defined in.

25974: <p>I have 2 .ino files (2 tabs) for one Arduino project/sketch: MySketch_File1.ino and MySketch_File2.ino.</p>

<p>I declared in MySketch_File2 variables and functions which I want to use in MySketch_File1, but I get this error massage: </p>

<blockquote>
  <p>error: 'a' was not declared in this scope</p>
</blockquote>

<pre><code>//MySketch_File1.ino
void setup(){
Serial.begin(9600);
Serial.println(String(a));
}

void loop(){

}
</code></pre>

<p>Second file:</p>

<pre><code>//MySketch_File2.ino
int a;
</code></pre>

<p>How can I declare variables and functions one time in one .ino file and use it across multiple .ino files?</p>
 15180: <p>In Arduino the <code>sketch.ino</code> is the main (and only) program, which runs on the processor. </p>

<p>If you upload another sketch to HW, then the previous one is overwritten and does not longer exist on the HW. So there is no way, they can share variables, as they never are run at the same time.
(You can store some values to EEPROM or to external devices, but it is other thing).</p>

<p>What you probabely want to do is use the second file as a <code>library</code>, which is collection of variables and functions, that more then one program can use. Anyway what is used is the text of the library, not the values assigned to variables in one <code>sketch.ino</code> - so other <code>sketch.ino</code> using the same library would have the functions and variables of the same name accessible, but as it is compiled to othe program, the values assigned in one sketch would not be visible in other sketch.</p>

<p>Can you specify, why you want to use variables and functions accross multiple .ino files?</p>

<p>If it is just to not have type it again and again and fix found bugs in each aned every copy separately, then you are looking for <code>libraries</code>.</p>

<p>If you want to share also values (like read and compute value in one .ino then upload another .ino and use the result) you are looking for <code>persistent storages</code> (EEPROM on the chip, SD card via some reader or something like that.</p>

<p>If you want have more Arduinos running at the same time and sharing some values, you are looking for <code>networks</code>, like I2C, Serial communication, Ethernet and such.</p>

<p>If you want run mor programs on one arduino at the same time, you are looking for <code>multitasking</code> where each program is interrupted repeatedly and other one is continued, fast enought to user not notice, or for creatinig more functions and call them from loop() one after one to eg. read sensors, then light LEDs then run motors. <code>State automats</code> can make your way here easier.</p>
 52996: <p>It is simplest to put only one .ino file in a directory with the filename. <a href="https://arduino.stackexchange.com/questions/32619/why-does-an-ino-file-have-to-be-in-a-folder-of-the-same-name">Why does an `.ino` file have to be in a folder of the same name?</a> </p>

<p><strong>Option 1 (cleanest option):</strong> <a href="https://www.arduino.cc/en/guide/libraries#toc5" rel="nofollow noreferrer">Create a user library</a>.</p>

<p><strong>Option 2  (workaround):</strong> <a href="https://forum.arduino.cc/index.php?topic=110950.0" rel="nofollow noreferrer">Relative paths for #include aren't supported</a> but you can use a symlink to make it appear that there is the same header file in every directory:</p>

<pre><code>sketch1/
  sketch1.ino
  mylib.h
sketch2/
  sketch2.ino
  mylib.h (this is a symlink to sketch1/mylib.h) 
</code></pre>

<p><strong>Option 3:</strong> Avoid Arduino IDE entirely and build using avr-gcc. Example: <a href="http://thinkingonthinking.com/an-arduino-sketch-from-scratch/" rel="nofollow noreferrer">http://thinkingonthinking.com/an-arduino-sketch-from-scratch/</a> and <a href="https://arduino.stackexchange.com/questions/21492/will-a-ino-arduino-sketch-compile-directly-on-gcc-avr/21515">Will a .ino Arduino Sketch compile directly on GCC-AVR?</a> This is much more complicated, but supports bigger projects using Makefiles.</p>
 4143: <p>When you compile multiple files in the Arduno IDE the files first get concatenated together.</p>

<p>It happens in alphabetical order, <em>except</em> the main INO file (the one named the same as the folder it's in) is placed first.</p>

<p>In C the order in which things appear in the file matters. Basically you have to make sure that things (like variables, functions, etc) are defined <em>before</em> they are used.</p>

<p>This gets more complex when you have a hidden thing like file concatenation messing things up.</p>

<p>The Arduino IDE tries to hide some of it from you too by making <em>function prototypes</em>, so it doesn't matter what order you define functions in - however that "helpfulness" means you don't learn about the proper structure of a C program.</p>

<p>So what can you do? Well, simply make sure that all your global variables are defined in the <em>main</em> file, unless you know they are only going to be used within the file they are defined in.</p>
