Thread: Show a number in the MessageBox

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    385

    Show a number in the MessageBox

    I am trying to display myValue in the MessageBox. I use C++ 2008.
    How is this possible. It seems that MessageBox in this case only can display a string, "".


    int myValue = 0;
    double myVal2 = 3.14;
    myValue = myVal2;

    MessageBox::Show(myValue);

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    I think Prelude has examples of string streams in the f.a.q. It's something like;

    std::stringstream blah;
    blah<<myValue;
    std::string myMessage;
    myMessage=blah.str();;

    You can't use the sstream directly (I don't think you can, but perhaps you can), so you'd tranfer that to a std. string for display -

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This looks like C++ dot net. There are better ways to do that in the managed C++. Or you can just scrap the non-standard, vector lock-in language and use native C++ or C#.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I did try the code above but this didn&#180;t work and it couldn&#180;t convert stringstream to System::String ^ (VC++ 2008)

    However, the real thing that I need to make function is to in the same way display an integer, double etc.. in a "TextBox".
    The same example follow like this.
    It must be possible in an easy way to display ex:

    int Number = 5; in the texbox ? This do display: TextLine but this is a string. One question here is that perheps it should be written something else instead of ->Text as this only can display text.

    textBox3->Text = "TextLine";
    Last edited by Coding; 01-26-2008 at 08:52 AM.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do you need to use C++ dot net or will C++ Native do? C++ dot net is demon's work and should be avoided. C++ Native or C# is recommended instead.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Elysia,

    I have to ask as I am quite new to C++, the differeces.
    I downloaded VC++ 2008 Express Editon from this link but assume you already understood that:
    http://www.microsoft.com/express/vc/

    When you speak about if C++ Native will be okay for me I don&#180;t really know what to refer to really
    and what Native stands for. I know that you write Native code etc...
    Is there any limitatons using the edtion that I do. I don&#180;t know.
    I am up to program a Windows application.
    I am really open to listen to alternatives to understand better. Perheps the version of 2005 is better.
    I don&#180;t know how many different editions there are. However I would like to use C++ and not C#.
    I think I begin my question like this.

    C++ dot net, what is that. I am not sure if I follow here...
    Last edited by Coding; 01-26-2008 at 12:22 PM.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The version makes no difference. C++ dot net works on Microsoft's dot net platform. However, C++ dot net is not standard, so it will only work on Windows, while other languages such as C# is standard and will work on other platforms, as well. So C++ dot net is what we call vendor lock-in and therefore is to be avoided.
    Native C++ is much more low level and more complex than dot net and creating GUI can be a difficult process. If you are satisfied with this, then you'll have to be prepared to spend a lot of time and studies on the language to understand it. Also note that making GUIs in C++ is a no-no from the start. Instead we work on typical CLI applications to master the language first. Programming GUI in C++ is a difficult beast.

    In case you want to do GUI from the get-go, then I suggest looking the other way at other programming languages such as C#.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    I see, I think you meen by GUI, Graphical user interface.
    It will be okay for me for now that the program is just working on Window platforms and I will only for this application do very "easy" stuff like putting values into texboxes write a value into a textbox to make a calculation. Display numbers and results in a gridview.
    Reading and writing to files.

    Save a file and open a file. This is quite what I will do. So It is kind of basic. No graphics or things like this. Only calculations.
    What do you think. Will the editon I use now be okay for this as I have learned a lot and also already done much basic code in the program, about 30 pages...huhh...

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I think you should try C#. It's almost the same.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    Sorry for asking so much but to understand easier.. C# is good because it it compatible with other platforms. The basics is the same as you say, wich is interesting ofcourse.

    So my question is except this. Is it easier to do window applications using C#. I red somewhere that C# i easier to use also.

    Should Visual C# 2008 Express Edition be a good id&#233;a ?

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    C# is better than C++ dot net because it's not a vendor lockin. It's a standard and therefore compilers will emerge to compile the code on other platforms. Like C/C++.
    Since you want to do GUI, I recommend C# due to it being easy to do GUI in. So yes, the C# 2008 Express Edition should do fine.
    What is the difference between Native C++ and C# you might ask? C# is driven by a huge framework, which slows down performance. It also has problems communicating directly with hardware due to its nature. But it's far easier to use.
    So performance and flexibility is C++'s area, and GUI and easiness is C#'s area.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Dec 2007
    Posts
    385
    okay I think I understand better. As performace is very important for this program as it does calculations that could take more than 10 hours perheps I think a bit what will be best.
    Perheps I will experiment with both to see actual difference on that one...
    Thank you for all information anyway...

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, C++ is best for performance demanding applications such as emulators or video encoding/decoding software, but for typical applications that do not require such performance, C# can be a bit better.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Quote Originally Posted by Coding View Post
    I am trying to display myValue in the MessageBox. How is this possible. It seems that MessageBox in this case only can display a string
    It doesn't look like anyone answered your original question.
    A message box can only display a string, so you have to convert your number to a string. Something like:
    Code:
    char msg[32];
    sprintf( msg, "%d", myValue );
    MessageBox::Show(msg);
    Just make sure your msg buffer is big enough.

  15. #15
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This is bad. This is C++ dot net, not managed.
    I'm not sure it will accept a char[] array instead of String^.
    There are ways to do that inside the .net framework.
    But wait until the OP decides on what language to use and post questions later to answer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Need help with this compiler error
    By Evangeline in forum C Programming
    Replies: 7
    Last Post: 04-05-2008, 09:27 AM
  3. adding a number to a number
    By bigmac(rexdale) in forum C Programming
    Replies: 11
    Last Post: 10-24-2007, 12:56 PM
  4. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM