Dr. Demento
Well-known Member
- Joined
- Nov 2, 2010
- Messages
- 618
- Office Version
- 2019
- 2016
- Platform
- Windows
Thanks to shg, I'm now able to estimate how much time a sub has left before it's complete. However, when I put this function within a loop, I'd like to test if the % complete (dPctComp) is a multiple of 10% (so that the function doesn't produce an output with every loop, only at each 10% complete. From what I've read, the nuances of matching a double are mind-boggling (clearly out of my ability). However, I'm hoping someone can tell me what is wrong with this formula or if I need to use a different approach.
I've tried using rounding factor (rFactor) as a double (0.10) or long (10 (%)), but neither one is ever true. I realize that with large loops, the equation may be true over a confined range (10% of 10,000 is 1,000 and the test may be true from 990 - 1010 (or something like that)), which is acceptable. In fact, if you can put in a variable that will allow the degree of precision, that would be awesome!
I feel like I'm flailing around in the dark with this one.
Thanks y'all.
I've tried using rounding factor (rFactor) as a double (0.10) or long (10 (%)), but neither one is ever true. I realize that with large loops, the equation may be true over a confined range (10% of 10,000 is 1,000 and the test may be true from 990 - 1010 (or something like that)), which is acceptable. In fact, if you can put in a variable that will allow the degree of precision, that would be awesome!
Code:
Dim dPctComp As Double
dPctComp = 0#
Dim rFactor As Long
rFactor = 10 ' ~~ Rounding factor (%)
If CDbl(Round(dPctComp * rFactor, 1)) - CInt(Round(dPctComp * rFactor, 1)) <> 0# then DoStuff ' [URL]https://stackoverflow.com/a/1795444\[/URL]
I feel like I'm flailing around in the dark with this one.
Thanks y'all.