error - edit box variable cannot be evaluated
-
I am getting a runtime error that an edit box variable on a dialog cannot be evaluated. I am not seeing what the problem is and would appreciate it if someone can point it out to me. There is a global variable declared as:
double currentBP;
In the first initDialog of the program, currentBP is initialized. Class CGetNewBP displays a dialog. There is an edit box for the user to enter a value. It is declared as:double m_newBP;
When the user clicks OK on this dialog, the value entered into the edit box is transferred to the global currentBP. On another dialog, there is a button - Change BP. When this button is clicked, the CGetNewBP dialog is displayed as modal. On return, the global currentBP which was just updated is assigned to an edit box declared:double m_currentBP;
At this assignment, however, an exception is raised saying that m_currentBP cannot be evaluated. If I comment out the call to create and display CGetNewBP, the code executes without exception, and m_currentBP displays the initialized value of the global currentBP. When the display CGetNewBP code is in, and execution is broken at the assignment statement, the value in the global currentBP has been updated correctly.void CModeCtrlDlg::OnBnClickedChangeBP () { CGetNewBP getNewBP = new CGetNewBP; INT_PTR nResponse = getNewBP.DoModal(); delete getNewBP; m_currentBP = currentBP; <- error message that m_currentBP cannot be evaluated UpdateData(false); }
Without the first 3 lines, no error message and m_currentBP accepts the assignment and displays on the screen. I have tried further qualifying m_currentBP as CModeCtrlDlg::m_currentBP, with no success. -
I am getting a runtime error that an edit box variable on a dialog cannot be evaluated. I am not seeing what the problem is and would appreciate it if someone can point it out to me. There is a global variable declared as:
double currentBP;
In the first initDialog of the program, currentBP is initialized. Class CGetNewBP displays a dialog. There is an edit box for the user to enter a value. It is declared as:double m_newBP;
When the user clicks OK on this dialog, the value entered into the edit box is transferred to the global currentBP. On another dialog, there is a button - Change BP. When this button is clicked, the CGetNewBP dialog is displayed as modal. On return, the global currentBP which was just updated is assigned to an edit box declared:double m_currentBP;
At this assignment, however, an exception is raised saying that m_currentBP cannot be evaluated. If I comment out the call to create and display CGetNewBP, the code executes without exception, and m_currentBP displays the initialized value of the global currentBP. When the display CGetNewBP code is in, and execution is broken at the assignment statement, the value in the global currentBP has been updated correctly.void CModeCtrlDlg::OnBnClickedChangeBP () { CGetNewBP getNewBP = new CGetNewBP; INT_PTR nResponse = getNewBP.DoModal(); delete getNewBP; m_currentBP = currentBP; <- error message that m_currentBP cannot be evaluated UpdateData(false); }
Without the first 3 lines, no error message and m_currentBP accepts the assignment and displays on the screen. I have tried further qualifying m_currentBP as CModeCtrlDlg::m_currentBP, with no success.theFrenchHornet wrote: In the first initDialog of the program... You have more than one? theFrenchHornet wrote: There is an edit box for the user to enter a value. It is declared as: double m_newBP; The variable associated with the edit control should be
CEdit
. theFrenchHornet wrote: void CModeCtrlDlg::OnBnClickedChangeBP () { CGetNewBP getNewBP = new CGetNewBP; INT_PTR nResponse = getNewBP.DoModal(); delete getNewBP; m_currentBP = currentBP; <- error message that m_currentBP cannot be evaluated UpdateData(false); } Several things wrong here. First, don't use a heap-based variable unnecessarily. Second,UpdateData()
is also unnecessary. Third, too many variable involved. Fourth,getNewBP
is not a pointer so thenew
operator cannot be used. Try something like this instead:class CGetNewBP : public CDialog
{
public:
CEdit m_edit;
double m_BP; // you could also make this a CString and do the atof()
// conversion in the OnBnClickedChangeBP() method
};void CGetNewBP::OnOK()
{
CString str;m\_edit.GetWindowText(str); m\_BP = atof(str);
}
...
class CModeCtrlDlg : public CDialog
{
public:
CEdit m_editBP;
};
...
void CModeCtrlDlg::OnBnClickedChangeBP()
{
CGetNewBP dlg;
INT_PTR nResponse = dlg.DoModal();
if (IDOK == nResponse)
{
CString str;str.Format("%f", dlg.m\_BP); m\_editBP.SetWindowText(str); }
}
Make sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
theFrenchHornet wrote: In the first initDialog of the program... You have more than one? theFrenchHornet wrote: There is an edit box for the user to enter a value. It is declared as: double m_newBP; The variable associated with the edit control should be
CEdit
. theFrenchHornet wrote: void CModeCtrlDlg::OnBnClickedChangeBP () { CGetNewBP getNewBP = new CGetNewBP; INT_PTR nResponse = getNewBP.DoModal(); delete getNewBP; m_currentBP = currentBP; <- error message that m_currentBP cannot be evaluated UpdateData(false); } Several things wrong here. First, don't use a heap-based variable unnecessarily. Second,UpdateData()
is also unnecessary. Third, too many variable involved. Fourth,getNewBP
is not a pointer so thenew
operator cannot be used. Try something like this instead:class CGetNewBP : public CDialog
{
public:
CEdit m_edit;
double m_BP; // you could also make this a CString and do the atof()
// conversion in the OnBnClickedChangeBP() method
};void CGetNewBP::OnOK()
{
CString str;m\_edit.GetWindowText(str); m\_BP = atof(str);
}
...
class CModeCtrlDlg : public CDialog
{
public:
CEdit m_editBP;
};
...
void CModeCtrlDlg::OnBnClickedChangeBP()
{
CGetNewBP dlg;
INT_PTR nResponse = dlg.DoModal();
if (IDOK == nResponse)
{
CString str;str.Format("%f", dlg.m\_BP); m\_editBP.SetWindowText(str); }
}
Make sense?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Yes - makes sense. Thanks so much for the quick reply - big help - I learned - have implemented and works.