Estimate process finish time

a9192shark

New member
Joined
Feb 9, 2007
Messages
4
Programming Experience
10+
Hello,
I have experience of VBA and I am developing my first app in VB within VS2005. The app will have to process hundreds of files on a frequent basis and import them into a SQL Server database. The user will select lots of files and then walk away from the machine. I want to be able to estimate the finish time so that they can watch progress and manage their time.
In VBA it is simple as the type date can be used in functions so the equation
dtFinish = dtStart + (Now() - dtStart) * lngFilesToProcess / lngFilesProcessed
would yield a date with the estimated finish time.
A similar approach in VB does not work as I get IDE errors in my code telling me I can not * a date and an integer.
I have looked at the timespan data type but I can not multiply the timespan either.
Do I really have to write code to determine the number of seconds and then calculate the date myself? How do I do this as timespan.seconds is readonly....
Help!
Thanks,
A.
PS I have also posted this to the MSDN site forum and will update both if I receive answers!
A.
 
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dtStart [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2].Now[/SIZE]
 
[SIZE=2][COLOR=#008000]'...[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ts [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] TimeSpan = [/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2].Now.Subtract(dtStart)[/SIZE]
 
[SIZE=2][COLOR=#008000]'use ts.TotalSeconds [SIZE=2]or ts.TotalMinutes [/SIZE]which is Double value in calculation?[/COLOR][/SIZE]
Get it?
 
John,

Thanks for the reply. I see how you have calculated the time taken from the start to now, but how do you estimate the finish time?

The .TotalSeconds is also read only.

How can I scale the time taken to complete, say, 25% of the work to give me an estimate of 100%?

Code like (should have used code tags last time- sorry):
VB.NET:
dtFinish = dtStart + (Now() - dtStart) [B][U]*[/U][/B] 100 [B][U]/[/U][/B] 25
or
VB.NET:
tsTotalDuration = Now()-dtStart[B][U]*[/U][/B] 100 [B][U]/[/U][/B] 25
dtFinish = dtStart.Add tsTotalDuration

The operators * and / are not allowed with date or timespan data types.

A.
 
seconds remaining = ts.TotalSeconds / itemsdone * itemsremaining

total seconds = ts.TotalSeconds / itemsdone * itemstotal
 
John,

I will then need to convert the total seconds variable to a time. How can I do that as I can not add a long to a date?

Am I missing something here? I want to know the date and time that the process is estimated to finish. How do I get a dateTime variable with that information?

I must admit that most of VS 2005 has impressed me, it certainly is very easy to create an application. This one though has me asking why??? :confused:

Thanks for your help,

A.
 
You must learn to see things as objects, that's Object Oriented Programming, which VB.Net is.

The Date has properties and methods that allow you to do all this. When you have calculated the estimate remaining seconds or minutes, consider how easy it is now to call dt.AddMinutes or dt.AddSeconds to find out what date/time will be. These methods are function methods that return the result of the operation, in other words:
modifiedDate = originalDate.AddMinutes(123)
 
John,
Excellant!

I was warned that I would spend more time learning the object model than coding. I must explore more of the methods and properties of objects; even the ones that I think I know (like a 'simple' variable type...)

Thank you for your help.

My solution was:
VB.NET:
'Inside the initialising procedure for teh process
dtStart = now()
 
'In the update progress procedure
tsDuration = now()-dtStartTime
dtEstFinishTime = dtStartTime.AddSeconds(tsDuration.TotalSeconds * lngFilesToLoad / lngFilesLoaded)

A very neat solution, as I had hoped for!

Thanks again for your help,

Alan.
 
Back
Top