I implemented a windows form application controlling a robot. One of the classes there (IRO) contains all the variables concerning the robot (i.e. battery power, sensors readings, etc..) and I would like to write it in a different file. I use VS08 for this.
What I did was adding a new item-->class, copy the IRO class from the Form1.cs (which contains all the methods for the app to work) into it. I took care to put it in the same namespace as the rest of the code, Iro_Prog and added a using directive :
using Iro_Prog
When i try to compile, it gives me the following error:
Error 1 The type or namespace name 'Iro_prog' could not be found (are you missing a using directive or an assembly reference?) \\CONTROL19\eranroi\Iro_gui\Iro_ver_1\Iro_ver_1\Form1.cs 13 7 Iro_ver_1
After looking through the "Professional C# 2008" book trying to find the reason for my problem, as well as going over this forum's topics (I found this :http://www.dreamincode.net/forums/topic/176297-how-do-i-compile-2-c%23-source-files-together-on-win7/ vut it's not quite the same problem...) I decided to ask for help. Any insight about where I went wrong would be appreciated,
Here are the relevant code snippets (I didn't put all of the code here, because it is really long, and i don't think it is relevant. If you think it will help you to better help me I will of course post all of it):
The Original file:
# region Using Directives
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;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Diagnostics;
using Iro_prog.IRO;
# endregion
namespace Iro_Prog
{
public partial class Form1 : Form
{
public IRO _iro; //<-- Here is where I create an object representing the robot as a global var
public Form1()
{
InitializeComponent();
_iro = new IRO();
}
private void Form1_Load(object sender, EventArgs e)
{
}
// Read the robot stream
private void background_Iro_data_stream_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_Iro_data_stream_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
// check logic --> if bump --> stop
private void background_Logic_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_Logic_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void startstream_Click(object sender, EventArgs e)
{
}
private void stopstream_Click(object sender, EventArgs e)
{
}
private void startrobot_Click(object sender, EventArgs e)
{
}
// manual controls Tab:
private void B_drive_manual_Click(object sender, EventArgs e)
{
}
private void B_stop_manual_Click(object sender, EventArgs e)
{
}
private void safe_mode_Click(object sender, EventArgs e)
{
}
private void full_mode_Click(object sender, EventArgs e)
{
}
public Boolean check_checksum(Byte[] temp)
{
}
public IRO extract_raw_data(Byte[] _temp, IRO a, int missmatch_count)
{
}
public void update_labels(int ProgressPercentage)
{
}
// Manual Control Buttons
private void button_driveforward_Click(object sender, EventArgs e)
{
}
private void button_drivebackward_Click(object sender, EventArgs e)
{
}
private void button_stop_Click(object sender, EventArgs e)
{
}
private void button_turnleft_Click(object sender, EventArgs e)
{
}
private void button_turnright_Click(object sender, EventArgs e)
{
}
private void button_commends_Click(object sender, EventArgs e)
{
}
private void background_External_Sensors_stream_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_External_Sensors_stream_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
/////////////////////////////////////////////////////////////////////////////////////////////////
}
public class IRO
{
different variables of the robot
}
}
and here is how I want it to be:
first file (Form1.cs:)
# region Using Directives
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;
using System.IO.Ports;
using System.Text.RegularExpressions;
using System.Diagnostics;
using Iro_prog.IRO;
# endregion
namespace Iro_Prog
{
public partial class Form1 : Form
{
public IRO _iro; //<-- Here is where I create an object representing the robot as a global var
public Form1()
{
InitializeComponent();
_iro = new IRO();
}
private void Form1_Load(object sender, EventArgs e)
{
}
// Read the robot stream
private void background_Iro_data_stream_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_Iro_data_stream_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
// check logic --> if bump --> stop
private void background_Logic_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_Logic_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void startstream_Click(object sender, EventArgs e)
{
}
private void stopstream_Click(object sender, EventArgs e)
{
}
private void startrobot_Click(object sender, EventArgs e)
{
}
// manual controls Tab:
private void B_drive_manual_Click(object sender, EventArgs e)
{
}
private void B_stop_manual_Click(object sender, EventArgs e)
{
}
private void safe_mode_Click(object sender, EventArgs e)
{
}
private void full_mode_Click(object sender, EventArgs e)
{
}
public Boolean check_checksum(Byte[] temp)
{
}
public IRO extract_raw_data(Byte[] _temp, IRO a, int missmatch_count)
{
}
public void update_labels(int ProgressPercentage)
{
}
// Manual Control Buttons
private void button_driveforward_Click(object sender, EventArgs e)
{
}
private void button_drivebackward_Click(object sender, EventArgs e)
{
}
private void button_stop_Click(object sender, EventArgs e)
{
}
private void button_turnleft_Click(object sender, EventArgs e)
{
}
private void button_turnright_Click(object sender, EventArgs e)
{
}
private void button_commends_Click(object sender, EventArgs e)
{
}
private void background_External_Sensors_stream_DoWork(object sender, DoWorkEventArgs e)
{
}
private void background_External_Sensors_stream_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
}
Second file (Class1.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Iro_Prog
{
public class IRO
{
}
}
Yarok
This post has been edited by yarok: 08 August 2010 - 03:44 AM

New Topic/Question
Reply




MultiQuote





|