Connecting Tech Pros Worldwide Forums | Help | Site Map

Simple Windows application

Nicolae Fieraru
Guest
 
Posts: n/a
#1: Jul 22 '05
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



Niels Dekker - no reply address
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Simple Windows application


Nicolae Fieraru wrote:[color=blue]
> 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.[/color]

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
Nicolae Fieraru
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Simple Windows application


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



Closed Thread