title: accessing non static variables from another project reference (C# and VB)
body: <p>This is my first post on stack overflow so please excuse anything I've done wrong.
  I have two projects under the same solution in visual studio, a form in VB and a simulation using a monogame game engine in c#. The VB form is being used as a data display where I am showing a line graph of data. I have referenced the c# simulation in the VB form so I can get the data across from one to the other but it is only allowing me to view static variables, is there any way that I can view lists and other variables that are dynamically changing from another project.</p>
  
  <p>Here is the code for the form in vb.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Imports System.IO
  Imports System.Windows.Forms.DataVisualization.Charting
  Imports Evolution_Simulator
  
  Public Class Form1
      Public meanGenerationDistances As New Series
  
      'sets a variable to the number of lines
      Dim numOfVariables As Integer = Evolution_Simulator.Game1.distances.Count
      Dim testNumberOfVars As Integer
  
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
          'list for data
          Dim ListOfMeansOfEachGeneration As New List(Of Integer)
          Dim counter As Integer = 0
  
  
          'changes the title of chart
          Chart1.Titles.Add("Creature Distances")
  
          'creates a new line on the graph
          meanGenerationDistances.Name = "Mean Distances of each generation"
          'sets it as a line graph
          meanGenerationDistances.ChartType = SeriesChartType.Line
  
          'removes series1 lable from graph
          Chart1.Series.Clear()
  
          Chart1.Series.Add(meanGenerationDistances)
  
          'starts the timer
          Timer1.Start()
  
      End Sub
  
      'sub to add to the graph
      Sub addToGraph(ByVal toAdd As Integer)
          meanGenerationDistances.Points.Add(toAdd)
      End Sub
  
  
      Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  
          Console.WriteLine("NUM                                                  " &amp; numOfVariables)
          Console.WriteLine("EVOL                                                 " &amp; Evolution_Simulator.Game1.distances.Count)
  
          addToGraph(1)
  
          'checks to see if a new item has been added to the list
          If Evolution_Simulator.Game1.distances.Count &gt; numOfVariables Then
              numOfVariables = Evolution_Simulator.Game1.distances.Count
              addToGraph(Game1.distances(numOfVariables))
          End If
  
      End Sub
  End Class
  </code></pre>
  
  <p>Here is the code for the class that is being referenced, it is in another project but under the same solution</p>
  
  <pre class="lang-cs prettyprint-override"><code>using Evolution_Simulator.Sprites;
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Microsoft.Xna.Framework.Input;
  using System;
  using System.IO;
  using System.Diagnostics;
  using System.Collections.Generic;
  
  namespace Evolution_Simulator
  {     
  
      public class Game1 : Game
      {
  
  
          GraphicsDeviceManager graphics;
          SpriteBatch spriteBatch;
  
          #region variables
  
          //used for pre-set values of screen width and height
          public static int screenHeight;
          public static int screenWidth;
  
          //allows the game to make a random value
          public static Random random;
  
          //gametimer for generating new things
          private double _timer;
  
          //bool for stating whether or not a game has started
          private bool _hasStarted = false;           
  
          //variable for the test creature I will be using until i generate 1000 of them
          public Creature creature;
  
          //creates an array which stores the results of all the creatures
          public Creature[] creatureArray = new Creature[50];
  
          //counter for adding to array
          int counter = 0;
  
          //could use a queue later for more a-level content
          //static list of all distances of the creatures 
          public static List&lt;double&gt; distances = new List&lt;double&gt;();
  
          #endregion
  
  
  
          public Game1()
          {
              graphics = new GraphicsDeviceManager(this);
              Content.RootDirectory = "Content";
  
              //initialises the random object
              random = new Random();            
  
              //sets the size of the window
              screenWidth = graphics.PreferredBackBufferWidth;
              screenHeight = graphics.PreferredBackBufferHeight;
          }
  
          protected override void Initialize()        {
  
  
              base.Initialize();
          }
  
  
          protected override void LoadContent()
          {
              // Create a new SpriteBatch, which can be used to draw textures.
              spriteBatch = new SpriteBatch(GraphicsDevice);
  
              //sets the texture for the node
              var nodeTexture = Content.Load&lt;Texture2D&gt;("node");
  
  
              //instantiates the creature, assigning it a nodeTexture
              creature = new Creature(nodeTexture);
  
              //loops through each node that has been generated
              creature.createNodes(nodeTexture);           
  
          }
  
  
          protected override void UnloadContent()
          {
  
          }
  
  
          protected override void Update(GameTime gameTime)
          {
              //starts the sim if space is pressed
              if (Keyboard.GetState().IsKeyDown(Keys.Space))
              {
                  _hasStarted = true;
              }
  
              //makes sure nothing happens when space is pressed
              if (!_hasStarted)
              {
                  return;
              }
  
  
              //incriments the timer
              _timer = _timer + gameTime.ElapsedGameTime.TotalSeconds;
  
              //lets a creature run for 15 seconds
              if (_timer &lt;= 15)
              {
                  //updates all of the creatures logic
                  //such as node positions, muscle contractions etc...
                  creature.Update(gameTime);
              }
              else if(_timer &gt; 15)
              {
                  if (counter &gt; creatureArray.Length - 1)
                  {
                      return;
                  }
                  else
                  {
                      //resets timer
                      _timer = 0;
                      //adds creature to array, will be sorted later
                      creatureArray[counter] = creature;
  
                      //loops through each node to get mean distance travelled
                      foreach (var node in creature.nodes)
                      {
                          creature.distanceTravelled = creature.distanceTravelled + node.position.X;
                      }
                      creature.distanceTravelled = creature.distanceTravelled / creature.numberOfnodes;
  
                      //incriment the counter
                      counter++;
  
                      //adds the distance travelled by the creature to the list
                      distances.Add(creature.distanceTravelled);
  
                      Console.WriteLine("DISTANCES                                                    " + distances.Count.ToString());
  
                      LoadContent();
                  }
  
              }          
  
              base.Update(gameTime);
          }
  
  
          private void FileWrite(float toWrite, int counter)
          {      
  
              //writes to a file called "data"
              //file is cleared in the windows form so not needed here
              using (StreamWriter writer = new StreamWriter((@"E:\Cameron Duff Computer Science NEA\Windows Form Data Display\Data display for project\Data display for project\bin\Debug\data.txt"), true))
              {
                  writer.WriteLine(toWrite);
              }
  
          }
  
          protected override void Draw(GameTime gameTime)
          {
              GraphicsDevice.Clear(Color.DarkBlue);
              spriteBatch.Begin();
  
  
              //draws all of the sprites, i.e. nodes
              creature.Draw(spriteBatch);
  
  
              spriteBatch.End();
              base.Draw(gameTime);
          }        
      }
  }
  
  </code></pre>