Help converting code - time remaining function

Dr. Demento

Well-known Member
Joined
Nov 2, 2010
Messages
618
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Evening all.

I found some code that, at least from the basic description, does what I would like. However, it's written in a variety of C. It's not too long; would anyone be willing to "translate" it?

The end goal is a Function that can be called (additional input: execute at x% of total --> first part of program would test if the x% of total loops have been performed, function would be executed; otherwise Exit) and will output the time remaining and the percent complete.

https://www.codeproject.com/Articles/27436/Remaining-Timer

Any takers?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
One thing I forgot. Currently, I'm trying to implement this in Outlook, so if it's application "universal," that would be awesome!! Obviously, it has a lot of potential in Excel as well.

Thanks y'all.
 
Upvote 0
Maybe this will get you started. Look at the status bar.

Code:
Sub demento()
  Dim i As Long
  
  Application.StatusBar = "ETC: " & ETC ' initialize
  
  For i = 1 To 5
    Application.Wait Now + (5 + 3 * Rnd) / 86400
    Application.StatusBar = "ETC: " & Format(ETC(i / 5), "hh:mm:ss")
    DoEvents
  Next i
  
  Application.StatusBar = False
  Beep
End Sub

Function ETC(Optional dPctComp As Double = 0#) As Variant
  ' Returns estimated time to complete based on start time and percent complete
  
  Static tBeg       As Date

  Select Case dPctComp
    Case 0#
      tBeg = Now
      ETC = "Starting now ..."
    Case Is < 0#, Is > 1#
      ETC = "Invalid percent complete!"
    Case Else
      ETC = (Now - tBeg) * (1# / dPctComp - 1#)
  End Select
End Function
 
Upvote 0
Much appreciated, shg. I don't know if it was because it's Monday or what, but it took me a while to suss out what each variable in the slope equation paired to. I got it now!! Thank you!!

Out of curiosity, why did you subtract one from the slope (1# / dPctComp - 1#)?
 
Last edited:
Upvote 0
You're welcome.

why did you subtract one from the slope (1# / dPctComp - 1#)?

(1# / dPctComp - 1#) is not the slope; it's how many more multiples of the elapsed time you need to complete. If you're 1/3 done, you need twice as much time to finish as you have spent so far.
 
Upvote 0

Forum statistics

Threads
1,217,358
Messages
6,136,095
Members
449,991
Latest member
IslandofBDA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top