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

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
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,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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