why memver variable with the edit box is blank here? - Programmer

This is a discussion on why memver variable with the edit box is blank here? - Programmer ; Hi, I create a dialog based MFC exe project using project wizard. On my dialogbox I create a textbox (edit box) and a command button. I associate a member variable m_myvariable to my edit box. Its a CString value variable. ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: why memver variable with the edit box is blank here?

  1. why memver variable with the edit box is blank here?

    Hi,
    I create a dialog based MFC exe project using project wizard. On my
    dialogbox I create a textbox (edit box) and a command button. I
    associate a member variable m_myvariable to my edit box. Its a CString
    value variable. OnOK event of command button , I want to display the
    content of edit box. So what I AfxMessageBox function to display
    CString m_myvariable but it always comes blank even I type something in
    the text box. Can someone tell me the reason?

    Thanks,
    Cric


  2. Re: why memver variable with the edit box is blank here?

    Does your OnOK() have and UpdateData(TRUE); ?

    --
    -------------------------------------------------------------------------
    Free software - Baxter Codeworks www.baxcode.com
    -------------------------------------------------------------------------


    wrote in message
    news:1119428707.198284.204030@g44g2000cwa.googlegr oups.com...
    > Hi,
    > I create a dialog based MFC exe project using project wizard. On my
    > dialogbox I create a textbox (edit box) and a command button. I
    > associate a member variable m_myvariable to my edit box. Its a CString
    > value variable. OnOK event of command button , I want to display the
    > content of edit box. So what I AfxMessageBox function to display
    > CString m_myvariable but it always comes blank even I type something in
    > the text box. Can someone tell me the reason?
    >
    > Thanks,
    > Cric
    >




  3. Re: why memver variable with the edit box is blank here?

    free2cric@yahoo.com wrote:
    > Hi,
    > I create a dialog based MFC exe project using project wizard. On my
    > dialogbox I create a textbox (edit box) and a command button. I
    > associate a member variable m_myvariable to my edit box. Its a CString
    > value variable. OnOK event of command button , I want to display the
    > content of edit box. So what I AfxMessageBox function to display
    > CString m_myvariable but it always comes blank even I type something in
    > the text box. Can someone tell me the reason?
    >
    > Thanks,
    > Cric


    I'm not sure what you mean by 'OnOK event of command button' but I'm
    going to assume you mean the click handler for the button you added to
    the dialog.

    It's generally a bad idea to use value variables unless you have a very
    specific type of dialog box. For your main dialog this probably isn't
    going to work unless you manually call UpdateData(). There's a much
    simpler solution however - just use control variables. Make a control
    variable for your CEdit then in your button handler do something like -

    CString text;
    m_MyEditControlVar.GetWindowText(text);
    AfxMessageBox(text);

    Regards,

    Hugh


  4. Re: why memver variable with the edit box is blank here?

    Thanks Hugh,
    U said
    >It's generally a bad idea to use value variables unless you have a very
    >specific type of dialog box


    Which are these specific type of dialog boxes. Could you please
    elaborate a little on this.
    Thanks,
    Cric.


  5. Re: why memver variable with the edit box is blank here?

    free2cric@yahoo.com wrote:
    > Thanks Hugh,
    > U said
    > >It's generally a bad idea to use value variables unless you have a very
    > >specific type of dialog box

    >
    > Which are these specific type of dialog boxes. Could you please
    > elaborate a little on this.
    > Thanks,
    > Cric.


    Well UpdateData is called by the framework in the OnOK handler, which
    updates the value variables. So you can do something like -

    CMyDialog dlg;
    if (dlg.DoModal() == IDOK)
    {
    // Access variables in dlg which have been updated
    DoSomethingWith(dlg.m_EditValue1);
    }

    However, it's almost as simple to get the values yourself with
    GetWindowText, and set them with SetWindowText. Also, using control
    variables applies to many more situations than the above so to keep
    consistent I just use them all the time, rather than using two
    different methods for doing essentially the same thing.

    Regards,

    Hugh


+ Reply to Thread