hexagon logo

Program execution logger script

' A very simple program execution logger by vpt.se
'
' Assign a variable in your PC-DMIS program called WATCHER that is empty:
'     ASSIGN/WATCHER=""
'
' Call the script and it will look for the variable, when found and the
' contents of WATCHER is "" it will write the programname and date + time
' to a file on C: called 'proglog.txt'
' The script will change the WATCHER value to "TRUE" indicating that the program
' is running.
'
' At the end of the PC-DMIS program, call the script again and it will look
' for WATCHER again, and if the contents of WATCHER is "TRUE" it will treat
' this as the program has finished measuring and write the end date and time
' to "C:\proglog.txt"
'
' vpt.se in 2011

Sub Main
Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, varname, wvar
Dim sstate As String

'Initialization
Set PCDApp = CreateObject("PCDLRN.Application")
Set PCDPartPrograms = PCDApp.PartPrograms
Set PCDPartProgram = PCDApp.ActivePartProgram
Set PCDCommands = PCDPartProgram.Commands

'Assignment To look For
varname = "WATCHER"
' Is it enabled?
sstate = ""

For cnt = 1 To PCDCommands.Count
  Set PCDCommand = PCDCommands.Item(cnt)
  If ((PCDCommand.Type = 195) And (varname = PCDCommand.GetText(DEST_EXPR, 0))) Then
    wvar = PCDCommand.GetText(SRC_EXPR, 0)

  If wvar = """""" Then 
      sstate = " started @ "
      retval = PCDCommand.PutText("""TRUE""", SRC_EXPR, 0)
  End If
  If wvar = """TRUE""" Then
      sstate = " ended   @ "
      retval = PCDCommand.PutText("""""", SRC_EXPR, 0)
  End If

  Open "C:\proglog.txt" For Append As #1
  Write #1, PCDPartProgram.Name & sstate & Date & " " & Time(Now)
  Close #1
  End If
Next

'Cleanup
Set PCDPartProgram = Nothing
Set PCDPartPrograms = Nothing
Set PCDApp = Nothing
End Sub


Example of "proglog.txt":

"test.PRG started @ 2011-04-20 09:17:48"
"test.PRG ended   @ 2011-04-20 09:18:43"


As always, feel free to modify the code to suit your needs.