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