Summary
adTempus generally uses a program's exit code to determine whether the program was successful.
However, programs written using Visual Basic 6 (and earlier versions) cannot return exit codes due to a limitation of the VB language. (Note that VB.NET applications can return exit codes, so the workaround described here is not needed).
If you need your VB application to return status information to adTempus, and you have control of the source code for the application, you can have your program pass status information back to adTempus by using a text file created by your program.
This is possible because adTempus allows you to execute a script to indicate whether a program was successful. In the example below, this script feature is used to read the status file created by your program, and based on that indicate whether the program succeeded.
More Information
To return a result code, your VB6 program can write a result to a text file that adTempus will read.
To use this approach, your program should:
- When it starts, delete the "result" file from the last run.
- If it runs successfully, create a "result" file. This should be a text file to which only the word "success" is written.
- If it does not run successfully, do not create the file.
In adTempus, edit the step that runs your program.
- In the Program Execution Task Properties window, Go to the Advanced page.
- In the Success Criteria section, select "Use a script" and click Select.
- In the Select Script window, select New....
- In the Script Properties window, paste the following script code into the Script box. Be sure to change "yourfile.txt" to the complete path and filename of the result file that your program will create.
'This script is used to allow a VB program to return an "exit code" to adTempus. 'Instead of directly returning an exit code, 'your program should create a text file and write the exit code to the file. 'This script will read the exit code from the file. ' 'Replace "yourfile.txt" below with the full path and name 'of the file your application creates. ' dim fso dim f Dim contents On Error Resume Next Result=false Set fso=CreateObject("Scripting.FileSystemObject") Set f=fso.OpenTextFile("yourfile.txt",1) If err.number=0 Then contents=f.readall If left(contents,7)="success" Then Result=True End If End If Set f=nothing Set fso=nothing
After adTempus runs your program, it will execute the script. If the result file exists and contains the word "success", the script will return True, telling adTempus that the program was successful. If the file does not exist, or does not contain the word "success", the script will return False, telling adTempus that the program failed.
Returning Error Information
You can extend this approach to allow your program to return an error message that adTempus can use to send a notification message that contains the reason for the failure.
To do this, modify the approach as follows:
- If your program completes successfully, write the word "success" to the result file.
- If the program fails, write to the file any error information or other message you want to use in the notification message.
Use the following script:
' 'Replace "yourfile.txt" below with the full path and name 'of the file your application creates. ' dim fso dim f Dim contents On Error Resume Next Result=false Set fso=CreateObject("Scripting.FileSystemObject") Set f=fso.OpenTextFile("yourfile.txt",1) If err.number=0 Then contents=f.readall If left(contents,7)="success" Then Result=True Else parameters("FailureMessage")=contents End If Else parameters("FailureMessage")="Result file not found" End If Set f=nothing Set fso=nothing
This script reads the message from the file, and assigns it to the "FailureMessage" script parameter.
When you create the response that sends the notification message, insert the token "%FailureMessage%" (without the quotation marks) at the point in the message where you want the message to appear. adTempus will replace the token with the actual message when the notification is sent. For example, your message could be:
Program XYZ failed. The error message returned by the program was: %FailureMessage%
If your program writes "Cannot open input file" to the result file, the final notification message will be:
Program XYZ failed. The error message returned by the program was: Cannot open input file
Workaround
To return an exit code from a Visual Basic application you may be able to use the Windows API ExitProcess function. This approach was previously detailed in Microsoft Knowledge Base article Q178357 (article no longer available), but is no longer supported or recommended by Microsoft due to the problems discussed in article Q288216. In addition to the problems described by Microsoft note that calling the ExitProcess function while your program is being debugged in the Visual Basic development environment will cause the Visual Basic IDE itself to terminate, along with your program.