Click here to Skip to main content
15,886,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got two libraries
- The first one is the GUI library
- The second one is the Audio Library.

My question is how can i call a method of a class in the Audio Library from the click of a button in The GUI library?

I already reference the GUI library, i added the using namespace an i already declare and create an object like it is below

C#
private Recorder anAudioRecorder;
       public RecordingWindow()
       {
           InitializeComponent();
           anAudioRecorder = new Recorder();
       }


The name of my class in the Audio Library is call Recording and the method is Rec()

Thanks in advance guys
Posted
Comments
Uwe Keim 15-Nov-10 11:26am    
Which errors do you see?
Chirry 15-Nov-10 11:36am    
Im not sure if im calling the method right im calling it like this

NameOfClass.Method()

Iam getting the following errors
Error 1 'Julian.Audio.Utilities.Recorder' does not contain a definition for 'Rec'
Error 2 'Julian.Audio.Utilities.Recorder' does not contain a definition for 'Rectimer' and no extension method 'Rectimer' accepting a first argument of type 'Julian.Audio.Utilities.Recorder' could be found (are you missing a using directive or an assembly reference?)
Error 3 The name 'Status_Label' does not exist in the current context

In error 2 the recTimer is a component that im using on the Recording window form is not recognising it as well as the Status_Label

If Rec() is not a static method you should use the name of an instance rather than the name of the class.

For static method
C#
public class Recorder
{
  public static void Rec()
  {
    ................
    ................
  }
}

// Then in your GUI you can use
Recorder.Rec();


if not static
C#
public class Recorder
{
  public void Rec()
  {
    ................
    ................
  }
}

// Then in your GUI you MUST use
Recorder newRecorder = new Recorder();
// use the name given in the line above
newRecorder.Rec();
 
Share this answer
 
Comments
Chirry 15-Nov-10 12:01pm    
Im getting an error im confuse why it doesnt work im gonna show you what i have

This is my AudioLibrary The class Recorder
namespace Julian.Audio.Utilities
{

public class Recorder
{
public void Rec()
{
..........................
}
}
}


This one here is the GUI form
namespace GUI.application
{
public partial class RecordingWindow : System.Windows.Forms.Form
{
private Recorder newRecorder;

public RecordingWindow()
{
InitializeComponent();
Recorder newRecorder = new Recorder();
}

private void btn_Rec_Click(object sender, EventArgs e)
{
newRecorder.Rec();
}
}
Chirry 15-Nov-10 12:10pm    
PLEASE help me im so desesperated to get this working,
Basically the program is runnin perfectly, the bad point is that the whole code is writen behin the forms rather than using the two libraries, so now i need to separate the code into classes of a library
C#
namespace Julian.Audio.Utilities
{
 public class Recorder
 {
   public void Rec()
   {
     ..........................
   }
 }
}

namespace GUI.application
{
  public partial class RecordingWindow : System.Windows.Forms.Form
  {
    private Recorder newRecorder;

    public RecordingWindow()
    {
      InitializeComponent();
      Recorder newRecorder = new Recorder(); // <============ Here is your problem
    }

    private void btn_Rec_Click(object sender, EventArgs e)
    {
      newRecorder.Rec();
    }
}


The line I have marked declares and instantiates a new instance of Recorder(), it does not instantiate (create) the one at the top of your class. The marked one is inside a block and so is not visible to your click handler. That can only see the one at the top, which is still null.

To correct this, change the marked line to:
C#
newRecorder = new Recorder();
 
Share this answer
 
Comments
Chirry 15-Nov-10 12:23pm    
First i want to than you God bless you for your help I really appreciate it.

3 errors still coming up which are

Error 1 'Julian.Audio.Utilities.Recorder' does not contain a definition for 'Rec' and no extension method 'Rec' accepting a first argument of type 'Julian.Audio.Utilities.Recorder' could be found (are you
missing a using directive or an assembly reference?)

And the other two are complaining about the Label and the timer component that im using at the form
It is difficult to be precise about your first error, since I suspect that the code you posted was not accurate, you will see why I think this in a moment. For future reference, if you post code then copy it from your editor and paste it here rather than typing in an approximation of it.

Still, what I think is happening is that you are calling your Rec() method something like:

C#
newRecorder.Rec(newRecorder);


this is because the error message includes "no extension method 'Rec' accepting a first argument of type 'Julian.Audio.Utilities.Recorder' could be found", which means that you have called Rec() with an argument (the bit between the parentheses). You haven't declared a Rec() method with a parameter, so the system gets confused.

Two possible solutions
1. use Rec() rather than Rec(whatever)
2. in your recorder class, declare and write a Rec(Recorder recorder) method, but only do this if it is needed.

Please be aware that I will not be able to answer you for the next few hours. By all means ask further questions but do not expect a fast response.
 
Share this answer
 
Comments
Chirry 15-Nov-10 13:15pm    
Its ok henry u have helped me a lot.
I will try to organize it. will let u know if im having difficulties, u answer when u really can
thanks for ur tips and help i do really appreciated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900