CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2011
    Posts
    5

    What's wrong with my code?

    Hey guys, I am very much new to C# programming. Actually, new to programming period. I'm using visual C# 2010 express and I'm going through a tutorial right now (http://tinyurl.com/69e9hsj). I'm stuck right now on this piece of code, it's exactly the same as the code in the tutorial, however, I'm getting several errors. Help would be greatly appreciated.

    Code:
     private void mnuQuit_Click(object sender, EventArgs e)
            
             if(MessageBox.Show("Really Quit?", "Exit", MessageBoxButtons.OKCancel)==DialogResult.OK)
            {
                Application.Exit();
            }

  2. #2
    Join Date
    Jun 2010
    Posts
    56

    Re: What's wrong with my code?

    What is the exact error you are receiving? I just pasted the body code into a button and it seemed to work just fine.

  3. #3
    Join Date
    May 2011
    Posts
    5

    Re: What's wrong with my code?

    -Invalid token 'if' in class, struct, or interface member declaration (There's about 7 of those

    -Error 7 'System.Windows.Forms.MessageBox.Show(System.Windows.Forms.IWin32Window, string)' is a 'method' but is used like a 'type'

    -Error 8 'System.Windows.Forms.MessageBoxButtons.OKCancel' is a 'field' but is used like a 'type'

    There's a couple of more than that. Could it be the version i'm using?

  4. #4
    Join Date
    Jun 2010
    Posts
    56

    Re: What's wrong with my code?

    I think you're missing the brackets {} for the method:

    Code:
     private void mnuQuit_Click(object sender, EventArgs e)
    {
             if(MessageBox.Show("Really Quit?", "Exit", MessageBoxButtons.OKCancel)==DialogResult.OK)
            {
                Application.Exit();
            }
    }

  5. #5
    Join Date
    May 2011
    Posts
    5

    Re: What's wrong with my code?

    Quote Originally Posted by user612345 View Post
    I think you're missing the brackets {} for the method:
    \
    Oh wow, yup that is it. Thank you very much. Like I said, I'm very new to programming.

    [Edit]
    On another note, I've noticed that most people use visual 2005 on this forum, what's the reason for that? Should I switch to that version?
    Last edited by rechee123; May 18th, 2011 at 10:48 AM.

  6. #6
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: What's wrong with my code?

    Quote Originally Posted by rechee123 View Post
    [Edit]
    On another note, I've noticed that most people use visual 2005 on this forum, what's the reason for that? Should I switch to that version?
    No, better you learn on the newest platform... that is just a widely deployed Visual Studio version along with 2008 that a lot of development is still taking place in.

  7. #7
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,016

    Re: What's wrong with my code?

    There are a variety of IDEs available. The full version of Visual Studio is probably the best if you can get it (don't know about the express edition). I think it's fairly expensive to buy, but if you are a student then you might check to see if your school has an MSDNAA program, which may offer the program for free (or low cost) to students. There are some other options too. My favorite one is probably SharpDevelop (link), which is free, open source software.

    Good steps looking at tutorials! That's the way to learn. Let us know if you have further questions and welcome to the forum!

    You can read more about other editors on the CodeGuru Forum FAQ: http://www.codeguru.com/Csharp/.NET/...cle.php/c6873/

    And link to the rest of the FAQs on Learning C#: http://www.codeguru.com/forum/showthread.php?t=283516
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  8. #8
    Join Date
    Jun 2010
    Posts
    56

    Re: What's wrong with my code?

    For beginners Visual Studio Express is not bad. As you start to move further into the language and start developing more advanced programs it can be a pain.

    One example is multi-threaded programs. From what I read and experienced with the limitation on breakpoints I am at the mercy of VS to break at the right moment. So if I have several objects running in their own threads and one of them is breaking I need to step through and hope I catch the right thread because there is no real way to break inside a particular thread.

  9. #9
    Join Date
    May 2011
    Posts
    5

    Re: What's wrong with my code?

    Quote Originally Posted by BioPhysEngr View Post
    .
    Thanks for the useful links. I am actually a student, so I did look into the MSDNAA program. Unfortunately, I am not yet admitted into my major's department so I don't think I'll be allowed to download the software. But, I did send a polite e-mail asking if there was someway I can. Thanks again.

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

Featured