Nicolae Fieraru wrote:
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