Thread: Message Box

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    28

    Message Box

    Just a quick Q,

    Using Visual C++, Windows Forms, how can I bring up a message box to show a variable value?

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Quote Originally Posted by paulogrady View Post
    Just a quick Q,

    Using Visual C++, Windows Forms, how can I bring up a message box to show a variable value?
    Code:
    #using <mscorlib.dll>
    #using <System.Windows.Forms.dll>
    
    using namespace System::Windows::Forms;
    
    int main(void)
    {
    	System::String ^sTemp("Test 1,2,3");
    	MessageBox::Show(sTemp, "Test");
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    28
    But will this only work for string variables??

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Quote Originally Posted by paulogrady View Post
    But will this only work for string variables??
    MessageBox.Show only works with string variables. You can use the equivalent of sprintf for other variables such as ints, doubles etc. What other variables do you want to use?

    EDIT:

    You can go on and on with this example...

    Code:
    #using <mscorlib.dll>
    #using <System.Windows.Forms.dll>
    
    using namespace System::Windows::Forms;
    
    int main(void)
    {
    	int iInt = 10;
    	float fFloat = 1.23F;
    
    	System::String ^sTemp("Test 1,2,3");
    	MessageBox::Show(sTemp, "Test String");
    	MessageBox::Show(iInt.ToString(),"Test Int");
    	MessageBox::Show(fFloat.ToString(),"Test Float");
    	sTemp = System::String::Format("{0:(###) ###-####}", 8005551212);
    	MessageBox::Show(sTemp, "Test Format");
    	return 0;
    }
    Last edited by BobS0327; 04-15-2009 at 07:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Desperate Over Ecs!
    By cookie in forum C Programming
    Replies: 17
    Last Post: 07-16-2008, 01:25 PM
  2. Annoying Message Box Problem
    By Necrofear in forum C++ Programming
    Replies: 14
    Last Post: 07-02-2006, 11:25 AM
  3. input/output
    By dogbert234 in forum Windows Programming
    Replies: 11
    Last Post: 01-26-2005, 06:57 AM
  4. Positioning Message Box MFC
    By UnclePunker in forum Windows Programming
    Replies: 2
    Last Post: 08-12-2004, 04:14 AM
  5. Dialog In Message Box
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 03-23-2002, 10:35 AM