Program time

Nemo
Getting Started
Getting Started
Posts: 5
Joined: Mon Jun 04, 2012 2:17 pm

Program time

Post by Nemo » Tue Jun 12, 2012 1:51 pm

Nemo wrote:When running a program in run mode there is a column in the program window that says Time(min) is there a way to tell or add to the report how long it took to run that program?
Solved - Please see page 2 of this thread for complete solution - Updated Post

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1092
Joined: Wed Feb 23, 2011 7:26 pm

Re: Program time

Post by US_Helpdesk » Tue Jun 12, 2012 10:42 pm

You can calculate the time it takes to run a program...

For example run this script at the beginning of your program

Code: Select all

MinStrt = Minute(Time())
SecStrt = Second(Time())
Then this at the end

Code: Select all

MinEnd = Minute(Time())
SecEnd = Second(Time())

Min = MinEnd - MinStrt
Sec = SecEnd - SecStrt
PrgTime = CStr(Min) + " Minutes and " + CStr(Sec) + " Seconds"
Use Customer Data button in the Report properties to include the variable "PrgTime" in the report header. Note: Use the Set Variable button to specify the variable name.
I've migrated to a new user account, see my other posts here

Tabor
Super User
Super User
Posts: 176
Joined: Thu Dec 20, 2012 3:43 pm

Re: Program time

Post by Tabor » Wed Jan 09, 2013 1:56 pm

I tried this but when my program ran through the top of the hour, it was returning negative values. I made the following changes and it seems to work.

Tabor

Code: Select all

MinEnd = Minute(Time())
SecEnd = Second(Time())
If MinEnd < MinStrt Then
MinEnd = MinEnd + 60
End If
If SecEnd < SecStrt Then
SecEnd = SecEnd + 60
End If
Min = MinEnd - MinStrt
Sec = SecEnd - SecStrt
PrgTime = CStr(Min) + " Minutes and " + CStr(Sec) + " Seconds"
Tabor

Tabor
Super User
Super User
Posts: 176
Joined: Thu Dec 20, 2012 3:43 pm

Re: Program time

Post by Tabor » Fri Jan 11, 2013 11:50 am

Needed to make a correction. Forgot to "carry the one"...

Code: Select all

MinEnd = Minute(Time())
SecEnd = Second(Time())
If MinEnd < MinStrt Then
MinEnd = MinEnd + 60
End If
If SecEnd < SecStrt Then
SecEnd = SecEnd + 60
MinEnd = MinEnd - 1
End If
Min = MinEnd - MinStrt
Sec = SecEnd - SecStrt
PrgTime = CStr(Min) + " Minutes and " + CStr(Sec) + " Seconds"
[/quote]
Tabor

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1092
Joined: Wed Feb 23, 2011 7:26 pm

Re: Program time

Post by US_Helpdesk » Fri Jan 11, 2013 12:25 pm

Will this work if the program time is longer than one hour? Maybe we could use a function that provides epoch time and then subtract start from finish and then calculate Hrs / Min / Sec.

I see there is a Timer() function - Returns the number of seconds since 12:00 AM
I've migrated to a new user account, see my other posts here

Tabor
Super User
Super User
Posts: 176
Joined: Thu Dec 20, 2012 3:43 pm

Re: Program time

Post by Tabor » Fri Jan 11, 2013 1:38 pm

I don't believe so but you could add an hour line:

Start of Program:

Code: Select all

MinStrt = Minute(Time())
SecStrt = Second(Time())
HrStrt = Hour(Time())
End of Program:

Code: Select all

 MinEnd = Minute(Time())
SecEnd = Second(Time())
HrEnd = Hour(Time())
If HrEnd < HrStrt Then
HrEnd = HrEnd + 24
If MinEnd < MinStrt Then
MinEnd = MinEnd + 60
HrEnd = HrEnd - 1
End If
If SecEnd < SecStrt Then
SecEnd = SecEnd + 60
MinEnd = MinEnd - 1
End If
Min = MinEnd - MinStrt
Sec = SecEnd - SecStrt
PrgTime = CStr(Min) + " Minutes and " + CStr(Sec) + " Seconds"
You would probably have to change your computer time to 24hr time or modify this to reflect AM/PM because running a program through noon would cause errors in 12hr time. I'm only going on what a few minutes of online research told me and it seemed to work. I'm still very much a novice here. Not sure if this new "hour" code will work but if it uses the same syntax as the minutes and seconds, it should.

Tabor
Tabor

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1092
Joined: Wed Feb 23, 2011 7:26 pm

Re: Program time

Post by US_Helpdesk » Fri Jan 11, 2013 3:13 pm

try DateDiff()

http://www.w3schools.com/vbscript/func_datediff.asp

Here is an example...

Enter this VB Script at the beginning of your program:

Code: Select all

fromDate = (Format(now, "mm-dd-yy hh:mm:ss"))
Then this VB Script at the End of your program:

Code: Select all

toDate = (Format(now, "mm-dd-yy hh:mm:ss"))

MyDiff = DateDiff("s",fromDate,toDate)

IntHrs = Int(MyDiff / 3600)
Hrs = MyDiff / 3600
IntMin = Int((Hrs - IntHrs) * 60)
Min = (Hrs - IntHrs) * 60
IntSec = Int((Min - IntMin) * 60)

hms = IntHrs & " Hrs: " & IntMin & " Min: " & IntSec & " Sec"
Enter the Variable "hms" into a Customer Data Field in the Report Properties dialog. The Report Header will display the time as shown below.
Report.jpg
You do not have the required permissions to view the files attached to this post.
I've migrated to a new user account, see my other posts here

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1092
Joined: Wed Feb 23, 2011 7:26 pm

Re: Program time

Post by US_Helpdesk » Tue Apr 02, 2013 12:07 pm

Here is the project file in 3.3 Format.
You do not have the required permissions to view the files attached to this post.
I've migrated to a new user account, see my other posts here

Ralliartevo
Regular User
Regular User
Posts: 25
Joined: Tue Oct 22, 2013 12:32 pm

Re: Program time

Post by Ralliartevo » Fri Jan 17, 2014 3:47 pm

I did this but it didnt report the time. Im thinking i did the Customer data part wrong, could you be more descriptive in that area? Im using the first script because my programs dont exceed and hour. Also it might help to know i have NO experience with VB

User avatar
US_Helpdesk
Moderator
Moderator
Posts: 1092
Joined: Wed Feb 23, 2011 7:26 pm

Re: Program time

Post by US_Helpdesk » Sat Jan 18, 2014 5:59 pm

There is a project attached to the previous post... Download it and have a look directly at how this was done.
I've migrated to a new user account, see my other posts here

Post Reply