Dear all,
I'm new to this forum, and fairly new to C#. So I have a lot to learn, and this one is the first real problem for me. I'm building a tool that is getting information from a GUI, does a number of actions on that data and then gives an output back to that GUI. So far the theory.
Now for my problem: I create a class in a separate file, instantiate its object in the program.cs file. Then getting data from the GUI I use the form.cs
I'm using Visual Studio Pro 2010 on Win7 and .NET v4.
Indicator.cs snippet:
The program.cs file has the following code:Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace CompatibilityDeterminator { class Indicator { // Accuracy classes according to OIML R76 internal enum R76_Class {I, II, III, IIII}; // Load cell interface definition internal enum LC_Interface {FOURWIRE, SIXWIRE}; private string Mfr; // Manufacturer of the indicator private string Type; // Indicator type designation ... ... // Properties concerning general information of the indicator public string Manufacturer { get { return Mfr; } set { Mfr = value; } } ...
Haven't come any further than this because of my problemCode:using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace CompatibilityDeterminator { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); //Initialize all objects needed in the program Indicator IndicatorObj = new Indicator(); LoadCell LoadCellObj = new LoadCell(); LoadReceptor LoadReceptorObj = new LoadReceptor(); Instrument InstrumentObj = new Instrument(); } } }
The form.cs looks like this:
The IndicatorObj. does not get recognized by VS2010; if I compile it says "The name 'IndicatorObj' does not exist in the current context". I thought that using the namespace mechanism ("namespace CompatibilityDeterminator") would ensure that throughout the project, in all the involved files, the object from the program.cs files would be visible.Code:using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace CompatibilityDeterminator { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ... ... private void textBox3_TextChanged(object sender, EventArgs e) { IndicatorObj.Manufacturer = textBox3.Text; } ... ...
What did I miss? I hope my description of the problem is clear? If not then just let me know.
Thanks in advance for any help on the matter,
Martin.





Reply With Quote
