Click here to Skip to main content
12,996,841 members (133,235 online)
Rate this:
Please Sign up or sign in to vote.
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
	double horsePower = 0.0;
	CString hP;							
	horsePower = horsePower * 0.745699872;	// conversion to kilowatts
void CTry_4Dlg::OnBnClickedButton3()
    // TODO: Add your control notification handler code here
    double kiloWatts = 0;                  // initialize kiloWatts
    CString kW;                             
    kiloWatts = kiloWatts * 1.34102209;     // conversion to horsepower

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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 1 Nov 2010
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100