By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,412 Members | 929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,412 IT Pros & Developers. It's quick & easy.

Simple Windows application

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 22 '05 #2

P: n/a
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

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.