Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error - edit box variable cannot be evaluated

error - edit box variable cannot be evaluated

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theFrenchHornet
    wrote on last edited by
    #1

    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.

    D 1 Reply Last reply
    0
    • T theFrenchHornet

      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.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      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 the new 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

      T 1 Reply Last reply
      0
      • D 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 the new 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

        T Offline
        T Offline
        theFrenchHornet
        wrote on last edited by
        #3

        Yes - makes sense. Thanks so much for the quick reply - big help - I learned - have implemented and works.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups