Simple Windows application

N

Nicolae Fieraru

Hi All,

I just start using MS Visual C++ 6.0 and I try to make a very simple
application
I created a dialog application and I added two controls (Edit boxes).
Using ClassWizard I added a CString member variable to each edit box.
Now, I want to create the code that when I press on a button, I should read
the number I type in the first Edit Box (an integer) and to display the
double of that number in Edit Box no 2.
I am not sure if I should create String variables for each Edit Box or an
Integer variable.

Any help appreciated

Regards,
Nicolae
 
N

Niels Dekker - no reply address

Nicolae said:
I just start using MS Visual C++ 6.0 and I try to make a very simple
application
I created a dialog application and I added two controls (Edit boxes).
Using ClassWizard I added a CString member variable to each edit box.
Now, I want to create the code that when I press on a button, I should read
the number I type in the first Edit Box (an integer) and to display the
double of that number in Edit Box no 2.
I am not sure if I should create String variables for each Edit Box or an
Integer variable.

Are you sure you need the CString member variable for each edit box?
It's much easier if you do integer member variables instead, like this:

void CMyDialogBox::OnButton1()
{
UpdateData(true);
m_int2 = 2 * m_int1;
UpdateData(false);
}

Otherwise you would have to convert between string an integer yourself.
For instance:

#include <boost/lexical_cast.hpp> // From www.boost.org

void CMyDialogBox::OnButton1()
{
try
{
UpdateData(true);
const TCHAR *const psz = m_string1;
const int i = 2 * boost::lexical_cast<int>(psz);
m_string2.Format(_T("%d"), i);
UpdateData(false);
}
catch(...)
{
// TODO Exception handling...
}
}

If you wanna know more about converting strings to integers, this is the
right newsgroup for you! But if you have more questions on MFC,
ClassWizard, CString, UpdateData, and edit boxes, you'd better try
another newsgroup, for instance: microsoft.public.vc.mfc

Niels Dekker
www.xs4all.nl/~nd/dekkerware
 
N

Nicolae Fieraru

Hi Niels,

Thank you very much for your answer, it is helpful. I will use integer
variables for this project.
I was also looking for the proper NG, but I couldn't find it before. I will
post my future questions related to Visual C++ on microsoft.public.vc.mfc

Best regards,
Nicolae
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top