Solved

How to show a number...

Posted on 1998-11-28
4
175 Views
Last Modified: 2013-11-20
Hi again (yes, I am new to programming),
How can I show a number that is in a variable in the MessageBox?  There is no "%d" like with printf, hence the question.

Thanx.
0
Comment
Question by:lama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 50 total points
ID: 1325451
Answer coming...
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1325452
To do this, you want to create a temporary CString object.  Then, you can use the "Format" member function to create a string with the value of a variable.  Here is an example:

int var_you_want_shown = 123; // This is the variable you want to display.
CString temp;                 // This is only a temporary buffer.
temp.Format ("The value of var_you_want_shown is %d", var_you_want_shown); // This is similar to "printf"
MessageBox (temp, "Here it is!"); // This is the message box function displaying the temporary string.

Note that this technique can be applied to essentially any data type.  You can use the familiar "%d" "%ld" "%s" and "%f" format strings.  You might consider looking the functions up in the help because it explains all of the format strings.

If you have further questions, please feel free to ask.  Thanks!
0
 

Author Comment

by:lama
ID: 1325453
Good, that fixed my problems too.  I am so new at MFC... I don't know anything! 8-)
0
 
LVL 1

Expert Comment

by:The_Brain
ID: 1325454
this is my way sweet and straight to the answer. :)
char buffer[5];
Messagebox(0, _iota(number, buffer, 10)

_itoa(NUMBER, *buffer/buffer[](which is a pointer), radix/BASE)

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 73
move a line in eclipse 3 111
Sed question 2 139
Change to event 1 136
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question