2 Replies - 945 Views - Last Post: 08 August 2010 - 05:05 AM Rate Topic: -----

#1 yarok  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 12
  • Joined: 11-January 10

adding and compiling multi files project

Posted 08 August 2010 - 03:41 AM

Hi all,
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


Is This A Good Question/Topic? 0
  • +

Replies To: adding and compiling multi files project

#2 Charles:)  Icon User is offline

  • D.I.C Regular

Reputation: 142
  • View blog
  • Posts: 347
  • Joined: 26-November 09

Re: adding and compiling multi files project

Posted 08 August 2010 - 03:55 AM

It's probably because your namespace is 'Iro_Prog' but your using directive is 'using Iro_prog' - C# is case sensitive so you need to change it to 'using Iro_Prog'

This post has been edited by Charles:): 08 August 2010 - 03:56 AM

Was This Post Helpful? 1
  • +
  • -

#3 yarok  Icon User is offline

  • New D.I.C Head

Reputation: 4
  • View blog
  • Posts: 12
  • Joined: 11-January 10

Re: adding and compiling multi files project

Posted 08 August 2010 - 05:05 AM

View PostCharles:), on 08 August 2010 - 02:55 AM, said:

It's probably because your namespace is 'Iro_Prog' but your using directive is 'using Iro_prog' - C# is case sensitive so you need to change it to 'using Iro_Prog'


Hey there, thanks for the answer.
actually the Iro_prog was a typo here, and not on the source code.
What you said made me think maybe i needed to add the using directive to the class file, so I added the same using directive in the Class1.cs and voila! :)

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1