Results 1 to 7 of 7

Thread: [RESOLVED] New to C#: Calling Functions

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    Resolved [RESOLVED] New to C#: Calling Functions

    I have a piece of code that I need to call a function to save settings. This is what I'm using currently.:
    Code:
            
    private void exeSaveBut_Click(object sender, EventArgs e)
    {
            MainForm exeSave = new MainForm();
            exeSave.exeSaveAction();
    }
    
    ...
    
    void exeSaveAction()
    {
            MessageBox.Show("VPSM Directory Settings Have Been Saved!", "Settings Saved");
            exe42PathBox.Text = Convert.ToString(Settings1.Default.ExePath42);
            exe50PathBox.Text = Convert.ToString(Settings1.Default.ExePath50);
            exe52PathBox.Text = Convert.ToString(Settings1.Default.ExePath52);
            exe60PathBox.Text = Convert.ToString(Settings1.Default.ExePath60);
            exe62PathBox.Text = Convert.ToString(Settings1.Default.ExePath62);
            exe70PathBox.Text = Convert.ToString(Settings1.Default.ExePath70);
            exe71PathBox.Text = Convert.ToString(Settings1.Default.ExePath71);
            Settings1.Default.Save();
    }
    Now when I click on the button it doesn't seem to call the function...what am I doing wrong, I know it's a stupid, easy answer but I can't seem to find information that actually works for me. Thanks.

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: New to C#: Calling Functions

    Does that code even compile? The default access modifier of a class member is private, so you shouldnt be able to access the exeSaveAction method from that class, you need to add the 'public' modifier infront of 'void'
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    Re: New to C#: Calling Functions

    Yeah it compiles without errors or warnings. Even with public in front the button still does not ultimately display the message box, or seem to do anything and I can't figure out why.

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: New to C#: Calling Functions

    What if you put a breakpoint in the buttons click event handler, and step through the code? What actually happens? Does it even enter the event handler?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    29

    Re: New to C#: Calling Functions

    It wasn't stepping into it, had to re-"double-click" the buttons. My guess is a reference in the designer file was a little confused when I went from a form based program to a tab based one. Thanks for the help. Should have tried that myself first though ;-)

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: New to C#: Calling Functions

    Quote Originally Posted by Atheist
    The default access modifier of a class member is private
    Bzzt. Public.

    You may be thinking of Java.

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: New to C#: Calling Functions

    Quote Originally Posted by penagate
    Bzzt. Public.

    You may be thinking of Java.
    http://msdn2.microsoft.com/en-us/lib...w2(VS.80).aspx

    You may be thinking of VB.
    Last edited by jmcilhinney; Feb 4th, 2008 at 05:08 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

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



Click Here to Expand Forum to Full Width