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. Combo Boxes and numbers

Combo Boxes and numbers

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 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.
  • E Offline
    E Offline
    Eversman
    wrote on last edited by
    #1

    Hey, got another question. I hace a combo box and an edit box, and in the combo box, there is options for time, 10 mins, 20 mins etc etc. And when you click on them, it adds it to the edit box and keesp track of the total, remeber there are 7, so you choose 7 values and it adds it up, but if you hit the wrong value and change to the other one it adds both values to the edit box, and you can't change it back without restarting the program. int cur = m_type2.GetCurSel (); CString text; m_type2.GetLBText (cur, text); int cur1 = m_dur2.GetCurSel (); CString text1; m_dur2.GetLBText (cur1, text1); if (text1 == "10 Minutes") { if (text == "Swimming #1" ) { totalswim+=10; totalrun+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Run #1" ) { totalrun+=10; totalswim+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Cycling #1" ) { totalcycling+=10; totalrun+=0; totalswim+=0; totalstrength+=0; } else if (text == "Strength #1" ) { totalcycling+=0; totalrun+=0; totalswim+=0; totalstrength+=10; } else if (text == "Stretching #1" ) { totalswim+=0; totalrun+=0; totalcycling+=0; totalstrength+=0; } Hours(); } void CDEPDlg::Hours() { CString str; str.Format(TEXT("%i"),totalswim); m_swimtime.SetWindowText (str); CString str1; str1.Format(TEXT("%i"),totalrun); m_runtime.SetWindowText (str1); CString str2; str2.Format(TEXT("%i"),totalcycling); m_cyclingtime.SetWindowText (str2); CString str3; str3.Format(TEXT("%i"),totalstrength); m_strengthtime.SetWindowText (str3); } That is the code for it, if you have any ideas of how to have it to waht I need it to do, please post, becasue I am out of ideas and don't really know how else to do it. Thanks

    M A 2 Replies Last reply
    0
    • E Eversman

      Hey, got another question. I hace a combo box and an edit box, and in the combo box, there is options for time, 10 mins, 20 mins etc etc. And when you click on them, it adds it to the edit box and keesp track of the total, remeber there are 7, so you choose 7 values and it adds it up, but if you hit the wrong value and change to the other one it adds both values to the edit box, and you can't change it back without restarting the program. int cur = m_type2.GetCurSel (); CString text; m_type2.GetLBText (cur, text); int cur1 = m_dur2.GetCurSel (); CString text1; m_dur2.GetLBText (cur1, text1); if (text1 == "10 Minutes") { if (text == "Swimming #1" ) { totalswim+=10; totalrun+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Run #1" ) { totalrun+=10; totalswim+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Cycling #1" ) { totalcycling+=10; totalrun+=0; totalswim+=0; totalstrength+=0; } else if (text == "Strength #1" ) { totalcycling+=0; totalrun+=0; totalswim+=0; totalstrength+=10; } else if (text == "Stretching #1" ) { totalswim+=0; totalrun+=0; totalcycling+=0; totalstrength+=0; } Hours(); } void CDEPDlg::Hours() { CString str; str.Format(TEXT("%i"),totalswim); m_swimtime.SetWindowText (str); CString str1; str1.Format(TEXT("%i"),totalrun); m_runtime.SetWindowText (str1); CString str2; str2.Format(TEXT("%i"),totalcycling); m_cyclingtime.SetWindowText (str2); CString str3; str3.Format(TEXT("%i"),totalstrength); m_strengthtime.SetWindowText (str3); } That is the code for it, if you have any ideas of how to have it to waht I need it to do, please post, becasue I am out of ideas and don't really know how else to do it. Thanks

      M Offline
      M Offline
      Mahendra_786
      wrote on last edited by
      #2

      You can provide another button to undo the last operation or a "Reset" button to start again. At least it is better than re-starting:) Due Regards Mahendra

      1 Reply Last reply
      0
      • E Eversman

        Hey, got another question. I hace a combo box and an edit box, and in the combo box, there is options for time, 10 mins, 20 mins etc etc. And when you click on them, it adds it to the edit box and keesp track of the total, remeber there are 7, so you choose 7 values and it adds it up, but if you hit the wrong value and change to the other one it adds both values to the edit box, and you can't change it back without restarting the program. int cur = m_type2.GetCurSel (); CString text; m_type2.GetLBText (cur, text); int cur1 = m_dur2.GetCurSel (); CString text1; m_dur2.GetLBText (cur1, text1); if (text1 == "10 Minutes") { if (text == "Swimming #1" ) { totalswim+=10; totalrun+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Run #1" ) { totalrun+=10; totalswim+=0; totalcycling+=0; totalstrength+=0; } else if (text == "Cycling #1" ) { totalcycling+=10; totalrun+=0; totalswim+=0; totalstrength+=0; } else if (text == "Strength #1" ) { totalcycling+=0; totalrun+=0; totalswim+=0; totalstrength+=10; } else if (text == "Stretching #1" ) { totalswim+=0; totalrun+=0; totalcycling+=0; totalstrength+=0; } Hours(); } void CDEPDlg::Hours() { CString str; str.Format(TEXT("%i"),totalswim); m_swimtime.SetWindowText (str); CString str1; str1.Format(TEXT("%i"),totalrun); m_runtime.SetWindowText (str1); CString str2; str2.Format(TEXT("%i"),totalcycling); m_cyclingtime.SetWindowText (str2); CString str3; str3.Format(TEXT("%i"),totalstrength); m_strengthtime.SetWindowText (str3); } That is the code for it, if you have any ideas of how to have it to waht I need it to do, please post, becasue I am out of ideas and don't really know how else to do it. Thanks

        A Offline
        A Offline
        Andrew Quinn AUS
        wrote on last edited by
        #3

        Hi, As a side issue have you considered using SetItemData to make the code look cleaner? e.g. create enum for the Activity:

        enum enumActivity
        {
        eSwim = 0,
        eRun,
        eCycle,
        eStretch
        };

        Then when you create both combos...

        // populate duration drop-down
        CString strText;
        for(int t=10; t<=60; t++)
        {
        strText.Format("%d Minutes");
        int nIdx = m_dur2.AddString(strText);
        if (nIdx >= 0) m_sur2.SetItemData(nIdx, t);
        }

        // populate activity drop-down
        int nIdx2 = m_type2.AddString(_T("Swimming"));
        if (nIdx2 >= 0) m_type2.SetItemData(nIdx2, (DWORD)eSwim);

        nIdx2 = m_type2.AddString(_T("Running"));
        if (nIdx2 >= 0) m_type2.SetItemData(nIdx2, (DWORD)eRun);

        // ... etc ...

        Then in the handler you gave the code for you can use a nice switch statement:

        int cur1 = m_dur2.GetCurSel ();
        int cur = m_type2.GetCurSel ();

        switch((enumActivity)m_type2.GetItemData(cur))
        {
        case eSwim:
        totalswim += m_dur2.GetItemData(cur1);
        break;
        case eRun:
        totalrun += m_dur2.GetItemData(cur1);
        break;
        }
        // ...

        Hope this helps, Andy

        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