dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: [RESOLVED] Function Call! Error

  1. #1
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    [RESOLVED] Function Call! Error

    Code:
    public void prog_show()
            {
                Application.Run(new ShowRes());
            }
                
                public void show_progress()
                {
                    System.Threading.Thread tt1 = new System.Threading.Thread(new System.Threading.ThreadStart(prog_show));
                    tt1.Start();
                }

    I want to call show progress() methode from another class. Is this possible?? If yes then please Help!!

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Function Call! Error

    Did you mean 'show_progress()'? Where is it defined? The method is already public so you should be able to call it from another class. Your title says 'Function call! Error'. What error are you actually getting? Where are you getting the error? Provide a little bit more information and someone might be able to help you.

  3. #3
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Function Call! Error

    the piece of code I provided Up is in class 'A' and i like to access that function show_process(); from class B. Both Calasses are in different namespaces say....First.Second and First.Third....

  4. #4
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Function Call! Error

    Just reference the namespace using a 'using' statement or provide the fully qualified name when referencing the class that has the method your are interested in (e.g. First.Second.ClassB.show_progress()). Seems obvious. Am I missing something?

  5. #5
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Function Call! Error

    Tried to do same before too but after typing First.Second.ClassB my intellisence doesnot show the show_process() does not shows. Even if i try to type First.Second.ClassB.show_progress(); then at runtime it shows error saying
    Code:
    Error	1	An object reference is required for the non-static field, method, or property 'First.Second.ClassB.show_progress()'	C:\Documents and Settings\Munni\My Documents\UCMAS\abacus_Buttons_updated_01\First\Second\ClassB.cs	643	13	First

  6. #6
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Function Call! Error

    Are you sure that is a runtime error? Seems like a compilation error to me. Anyway if you want to call the method that way you have to make it static. otherwise you have to first create an instance of classB then call the method.
    Code:
    public static void show_progress()
    {
    }
    // Or this
    First.Second.ClassB b = new First.Second.ClassB();
    b.show_progress();

  7. #7
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Function Call! Error

    You're trying to call an instanced member statically. This is why you're getting the object reference required for non-static method.

    You must create an instance of your Type and then invoke the member off the instance.

  8. #8
    Join Date
    Dec 2009
    Location
    Kathmandu,Nepal
    Posts
    168

    Re: Function Call! Error

    Perfect! Thanks.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)