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. Passing a variable

Passing a variable

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 4 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.
  • D Offline
    D Offline
    DanYELL
    wrote on last edited by
    #1

    I have this code: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID); And then this function: CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; } If I just called GetString(pView, IDC_EDIT1), the code works. But if I use: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; I get an "unhandled exception" and it points to this code: void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd)); Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle Brina

    H D P 3 Replies Last reply
    0
    • D DanYELL

      I have this code: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID); And then this function: CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; } If I just called GetString(pView, IDC_EDIT1), the code works. But if I use: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; I get an "unhandled exception" and it points to this code: void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd)); Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle Brina

      H Offline
      H Offline
      Harold_Wishes
      wrote on last edited by
      #2

      If I understand correctly, you are using a test condition for the following:

      if (a = 1) dwID = IDC_EDIT1;
      if (a = 2) dwID = IDC_EDIT2;
      if (a = 3) dwID = IDC_EDIT3;

      If that is the case, you should be using the == operator instead of the = operator. if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3; It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs. :) -- modified at 13:27 Monday 24th July, 2006

      D 1 Reply Last reply
      0
      • H Harold_Wishes

        If I understand correctly, you are using a test condition for the following:

        if (a = 1) dwID = IDC_EDIT1;
        if (a = 2) dwID = IDC_EDIT2;
        if (a = 3) dwID = IDC_EDIT3;

        If that is the case, you should be using the == operator instead of the = operator. if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3; It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs. :) -- modified at 13:27 Monday 24th July, 2006

        D Offline
        D Offline
        DanYELL
        wrote on last edited by
        #3

        I appreciate the reply. The = is just a typo on my part. Im using == but I still get the error.

        D 1 Reply Last reply
        0
        • D DanYELL

          I appreciate the reply. The = is just a typo on my part. Im using == but I still get the error.

          D Offline
          D Offline
          DanYELL
          wrote on last edited by
          #4

          That might have been it. I take back my earlier statement.

          1 Reply Last reply
          0
          • D DanYELL

            I have this code: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID); And then this function: CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; } If I just called GetString(pView, IDC_EDIT1), the code works. But if I use: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; I get an "unhandled exception" and it points to this code: void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd)); Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle Brina

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

            DanYELL wrote:

            if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3;

            If a was equal to 1, why would you want the last two statements to be evaluated?


            "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

            "Judge not by the eye but by the heart." - Native American Proverb

            1 Reply Last reply
            0
            • D DanYELL

              I have this code: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; GetString(pView, dwID); And then this function: CString GetString(CView *pView, UINT dwID) { CString str; CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID); pWndChild->GetWindowText(str); return str; } If I just called GetString(pView, IDC_EDIT1), the code works. But if I use: if (a = 1) dwID = IDC_EDIT1; if (a = 2) dwID = IDC_EDIT2; if (a = 3) dwID = IDC_EDIT3; I get an "unhandled exception" and it points to this code: void CWnd::GetWindowText(CString& rString) const { ASSERT(::IsWindow(m_hWnd)); Is there any way I can call GetString(pView, dwID) or something like this instead of GetString(pView, IDC_EDIT1); Please, any response any one can give me will be greatly appreciated. Sincerely, Danielle Brina

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              DanYELL wrote:

              if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3;

              Can you show how 'a' is passed. Possibly it is not going through any of above condition and 'dwID' is having garbage value.

              DanYELL wrote:

              CWnd *pWndChild = pView->GetDlgItem( (UINT)dwID);

              and this statement is initializing pWndChild with NULL.

              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