messagebox.show (string) method

when i use this code

using namespace::System.Windows;

void main()

{

public:

static MessageBoxResult Show (

String^ "hi!"

)

}

it always has an error (it says i need a semicolon before public).. why is this




Answer this question

messagebox.show (string) method

  • natchURL

     pyrodouthat wrote:

    when i use this code

    using namespace::System.Windows;

    void main()

    {

    public:

    static MessageBoxResult Show (

    String^ "hi!"

    )

    }

    it always has an error (it says i need a semicolon before public).. why is this

     

    You made me smile!

    I think it would be good to back up a little and compile some already-worked examples to see how it is done.  You can start with the example at Help | Search "Creating a Simple Windows Form"

     - Dennis


    So you are perhaps used to programming in Java or C#, is that it  

    main() is not a class definition, it is a simple function declaration.  Think of it as a free-standing method (the main method of the entire program that you are compiling).

    main() itself is automatically public (external) and static (in the class loading sense).  The public keyword is not usable inside a method (that is, a function body).  You also don't need to say static on an internal declaration.  It isn't helpful here.   

    If your program compiles with those changes (and it shouldn't), you may find that it doesn't do anything.  There's much more to figure out.  Look up "message boxes" in the VC++ 2005 Help | Index.

     

     - Dennis

     



  • Dave Smalley

    orcmid wrote:

    I think it would be good to back up a little and compile some already-worked examples to see how it is done. You can start with the example at Help | Search "Creating a Simple Windows Form"

    I was thinking that I was a little cavalier. The "Creating a Simple Windows Form" is a little mysterious. Here is a simple program a bit like yours that compiles. It is a command line program, so you will see a console window, but the message box does appear. After this, you might try the Windows Form. Or more simple examples.

    
    

    using namespace System::Windows::Forms;

    void main()

    { /* A Command Line CLR Program that shows a simple message box. */


    /* 1. Start with a CLR Empty Project.

    2. Then, right click on the Project (in bold) in the Solution

    Explorer.

    3. Select properties.

    4. Under Common Properties | References click Add New Reference ...

    5. Scroll down in the Add New Reference window until you find

    System.Windows.Forms. Select that.

    6. This tells VC++ where to find the assembly that defines the

    classes you will be using.

    7. Now make this single CPP program (without the comments if you

    like), Build it (F7), and when there are no errors, run it (F5).

    */

    MessageBox::Show( "Hi!");

    } // main



  • MazterDeath

    You need to close void main()

    so the code will be

    void main();
    {

    Messagebox stuff

    }

    hope that helps


  • messagebox.show (string) method