two simple questions

I have two simple questions:

1.  I have two spin controls.  One of them works fine, the other also works OK except when you click the down arrow the value goes up and when you click the up arrow the value goes down.  It should be doing the other way round and I don't know why it is doing this.

2. I have a CString variable str1 and int variable int1.  int 1 contains say 193.  The 193 is seconds and I would like convert this to minutes so that it becomes 3 minutes and 13 seconds. then I want str1 to display "time remainig: 3 minutes and 13 second" just like when you download things.

LVL 12
Who is Participating?
mikeblasConnect With a Mentor Commented:
1) It's doing that because your low limit value is higher than your high limit value. Such a setting makes the control work upside-down. Also, note that the default setting for the control is for the low value to be 100 and the high value to be zero.  You need to call SetRange() or SetRange32() on the object.

2) See this code:

int nSeconds = 193;
CString str;
str.Format("%d minutes, %d seconds", nSeconds / 60, nSeconds % 60);

And that's that.

..B ekiM
Well done, mikeblas.  Personally, I do not want to see "minutes" displayed unless they are non-zero.  (And I'd really like to see one minute as "1 minute" rather than "1 minutes".)  But I'm really picky.
gbzhhuAuthor Commented:

I agree with ernest, but your answer will do me fine.  thanks.

Getting rid of "minutes" if they're zero is trivial.

CString FormatRemainingSeconds(int nTime)
   ASSERT(nTime > 0);
   CString strReturn;
   int nSeconds = nTime % 60;
   int nMinutes = nTime / 60;

   if (nMinutes > 0)
      strReturn.Format("%d minute%s, ", nMinutes,
         (nMinutes == 1) ? "" : "s");

   CString strTemp;
   strTemp.Format("%d second%s remaining", nSeconds,
      (nSeconds == 1) ? "" : "s");

   strReturn += strTemp;
   return strReturn;
All Courses

From novice to tech pro — start learning today.