How to get double data to work with edit boxes?

This is a discussion on How to get double data to work with edit boxes? within the Windows Programming forums, part of the Platform Specific Boards category; I'm working on a program that connects to a Microsoft Access database, and am about 2/3 of the way done. ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    14

    How to get double data to work with edit boxes?

    I'm working on a program that connects to a Microsoft Access database, and am about 2/3 of the way done. It will edit string data from the text boxes, but not numeric. I have tried numerous conversions, but I keep getting error messages like this conversion is not possible. pAmount is the one pesky item that won't work. Please help. Here is the section of code:

    void CProject2cView::OnEdit()
    {

    m_pSet->AddNew();
    m_pSet->Edit();
    m_pSet->Update();

    CEdit* pPayto = (CEdit*)GetDlgItem(IDC_PAYTO);
    //CEdit* pAmount =(CEdit*)GetDlgItem(IDC_AMOUNT);
    CEdit* pDate = (CEdit*)GetDlgItem(IDC_DATE);
    CEdit* pMemo = (CEdit*)GetDlgItem(IDC_MEMO);

    pPayto->GetWindowText(m_pSet->m_payto);
    pDate->GetWindowText(m_pSet->m_date);
    pMemo->GetWindowText(m_pSet->m_memo);
    //I tried the same line for pAmount but it wouldn't work.

    UpdateData();

    }

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Is pAmount a char/string?

    Try GetDlgItemText() into a temp string and
    atof() to convert to a float/double.

    (I use only WIN32 no ++/MFC. That is how it would work without the class)
    Last edited by novacain; 11-20-2001 at 11:08 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    pAmount is not a char or string, it's a double. That's why I'm having problems with it. I need a good type cast or conversion method that works, preferably by next week when the project is due. I'm also leaving this afternoon for the holiday and won't be back until Sunday, so an early reply would be really nice.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    The conversion method is the function

    atof()

    takes a string and returns a double.

    Catch the input in a string and atof() to the class member.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    14
    Thanks! This seems to work now.

    void CProject2eView::OnEdit()
    {
    m_pSet->Edit();

    CString amt;

    CEdit* pPayto = (CEdit*)GetDlgItem(IDC_PAYTO);
    CEdit* pAmount =(CEdit*)GetDlgItem(IDC_AMOUNT);
    CEdit* pDate = (CEdit*)GetDlgItem(IDC_DATE);
    CEdit* pMemo = (CEdit*)GetDlgItem(IDC_MEMO);

    pPayto->GetWindowText(m_pSet->m_payto);
    pDate->GetWindowText(m_pSet->m_date);
    pMemo->GetWindowText(m_pSet->m_memo);

    pAmount->GetWindowText(amt);
    //Convert to double
    m_pSet->m_amount = atof(amt);

    m_pSet->Update();
    m_pSet->Requery();
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21