5
« on: March 12, 2009, 04:00:56 PM »
I took the macro's posted by Scott and modified them slightly to produce a running job log. The output file is compatible with Microsoft Excel. I did this becuase I need to be able to track total time for a job with multiple parts in varying quantities for each part.
It still works Scott originally posted it with the exception that the resulting output from the M1003 macro is not destroyed with each run.
'****************************
'M1002.m1s Store Start time point
Dim StartTime As String
Dim StartDate As String
StartTime = Time(Now)
StartDate = Date()
Open "TimeFile" For Output As #1 ' Open to write file.
Write #1, StartTime
Write #1, StartDate
Close #1
Code "G4 P0.5"
While IsMoving
Wend
Sec = Second(StartTime)
Min = Minute(StartTime)
Hr = Hour(StartTime)
Dy = Day(StartDate)
SetVar(100,Sec)
SetVar(101,Min)
SetVar(102,Hr)
SetVar(103,Dy)
'*****************************
Here is the M1003 macro:
'*****************************
'M1003.m1s Get End Time point and calc, and post file
Dim StartTime As String
Dim StartDate As String
Dim EndTime As String
Dim EndDate As String
Dim File As String
Dim Days
EndTime = Time(Now)
EndDate = Date()
SecEnd = Second(EndTime)
MinEnd = Minute(EndTime)
HrEnd = Hour(EndTime)
DyEnd = Day(EndDate)
SecStart = GetVar(100)
MinStart = GetVar(101)
HrStart = GetVar(102)
DyStart = GetVar(103)
File = FileName()
Open "TimeFile" For Input As #1 ' Open file.
Line Input #1, TextLine ' Read line into variable.
StartTime = TextLine ' get start time.
Line Input #1, TextLine ' Read line into variable.
StartDate = TextLine ' get start date.
Close #1 ' Close file.
Code "G4 P0.5"
While IsMoving
Wend
If HrEnd<HrStart Then
Hr=((24-HrStart)+(24-(24-HrEnd)))
ElseIf (HrEnd>HrStart and MinEnd>MinStart) Then
Hr=(HrEnd-HrStart)
Else
Hr = 0
End If
If MinEnd<MinStart Then
Min=((60-MinStart)+(60-(60-MinEnd)))
ElseIf (MinEnd>MinStart And SecEnd>SecStart) Then
Min=(MinEnd-MinStart)-1
Else
Min=(MinEnd-MinStart)
End If
If SecEnd<SecStart Then
Sec=((60-SecStart)+(60-(60-SecEnd)))
Else
Sec=(SecEnd-SecStart)
End If
If (DyEnd-DyStart)= 0 Then
Days = 0
End If
If ((DyEnd-DyStart)=1) And (HrEnd<HrStart) Then
Days = 0
End If
If ((DyEnd-DyStart)=1) And (HrEnd>HrStart) Then
Days = 1
End If
If ((DyEnd-DyStart)>1) Then
Days = (DyEnd-DyStart)
End If
Kill "TimeFile"
Open "CostEstimate.csv" For Append As #2 ' Open to write file.
Write #2, File & " " & "," & StartDate & "," & StartTime & "," & EndDate & "," & EndTime & ","& Days & "," & Hr & ":" & Min & ":" & Sec
Close #2
Code "G4 P0.5"
While IsMoving
Wend
'*****************************
The only thing I am not pleased with is the CostEstimate.csv file has some double quotation marks in it that can be a problem for Excel to deal with. I would also like to be able to get rid of the AM and PM designations on the two time fields but have not been able to determine if VBscript will allow me to do that. Some or all of these problems are either due to the Cypress Enable scripting package or to my lack of knowledge in this area.
Any help or comments will be welcomed.
John Guenther
'Ye Olde Pen Maker'
Sterling, Virginia