title: VB6: Remaining time class
body: <p>I always wanted a simple system that would show me how many minutes approximately are left while processing a long for-next-statement.</p>
  
  <p>I tried do achieve this by creating a class.</p>
  
  <p>At the start, I want to set how many for-nexts I have (-> setMax)
  At each For-Next, I will tell the class that one of the for-nexts was done. (->addOneDone)
  The class would then tell me how many minutes I still have to wait until the entire for-next-statement will be done.</p>
  
  <p>I was pretty sure I made that quite ok, but something is still wrong.
  I suspect it is the milliseconds to minutes conversion.</p>
  
  <p>Would anybody try to help me find my mistake?</p>
  
  <p>Thank you very much!</p>
  
  <pre><code>Option Explicit
  
  Private Declare Function GetTickCount Lib "kernel32" () As Long
  
  Private m_lMax&amp;
  Private m_lItemsDone&amp;
  Private m_lStart&amp;
  Private m_cMillisecondsAlreadyNeeded As Currency
  Private m_lMinutesLeft&amp;
  Private m_lLastTick&amp;
  
  Public Sub setMax(ByVal uCount As Long)
  
      m_lMax = uCount
  
      m_lStart = GetTickCount()
  
  End Sub
  Public Sub addOneDone()
  
      m_lItemsDone = (m_lItemsDone + 1)
  
      Dim lTick&amp;
      lTick = GetTickCount
  
      Dim lMillisecondsNeeded&amp;
      lMillisecondsNeeded = (lTick - m_lLastTick)
  
      If (m_lLastTick &gt; 0) Then
  
          m_cMillisecondsAlreadyNeeded = (m_cMillisecondsAlreadyNeeded + lMillisecondsNeeded)
  
          Dim lMillisecondsForOneItem&amp;
          lMillisecondsForOneItem = (m_cMillisecondsAlreadyNeeded / m_lItemsDone)
  
          Dim lItemsLeft&amp;
          lItemsLeft = (m_lMax - m_lItemsDone)
  
          Dim cMillisecondsLeftToBeDone As Currency
          cMillisecondsLeftToBeDone = (lMillisecondsForOneItem * lItemsLeft)
  
          Dim lMinutes&amp;
          lMinutes = MillisecondsToMinutes(cMillisecondsLeftToBeDone)
  
          m_lMinutesLeft = lMinutes
  
      End If
  
      m_lLastTick = lTick
  
  End Sub
  Private Function MillisecondsToMinutes(ByVal uMilliseconds As Long) As Integer
  
      Dim seconds As Double
      seconds = uMilliseconds / 1000
  
      Dim minutes As Double
      minutes = seconds / 60
  
      MillisecondsToMinutes = minutes
  
  End Function
  Public Property Get MinutesLeft() As Long
  
      MinutesLeft = m_lMinutesLeft
  
  End Property
  </code></pre>