Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello The Code Project Community,

I'm new to writing code for Visual C++ GUI's. I'm trying to make an application to convert Horsepower to Kilowatts and vise versa.

I am able to convert it when I instantiate horsePower into a random number like 300 (double horsePower = 300.0) but what I wanted is that when I press the button.. it would take the value in the edit control box and convert that and display it into the results box. Picture provided below.

I had many errors beforehand experimenting from what I searched online and it included converting double into CStrings and vice versa and LPCTSTR and whatnot.

Help would be appreciated.

void CTry_4Dlg::OnBnClickedButton1()
{
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	double horsePower = 0.0;
	CString hP;							
	horsePower = horsePower * 0.745699872;	// conversion to kilowatts
	hP.Format(_T("%f"),horsePower);
	m_inputVariable.SetWindowText(hP);
	UpdateData(false);
}

void CTry_4Dlg::OnBnClickedButton3()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);
    double kiloWatts = 0;                  // initialize kiloWatts
    CString kW;                             
    kiloWatts = kiloWatts * 1.34102209;     // conversion to horsepower
    kW.Format(_T("%f"),kiloWatts);
    m_inputVariable.SetWindowText(kW);
    UpdateData(false);
}

}


Posted
Updated 1-Nov-10 10:28am
v3

1 solution

You need to add member variables for the two EDIT boxes, and set them to be of type double. Now in your button's click function, call UpdateData(TRUE) and the variables will update to the correct values (and will be of type double).

In VS 2010, adding a member variable is as simple as right clicking on the edit control in the designer and selecting Add Variable.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900