Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

Exiting VB execution with an error.

 Hello everybody,

  We've got an SQL-Server's job executing an VB 6.0 exe. We want to know whether this execution
failed or not. We've tried using Err.Raise or Stop but execution never ends (executing from this
SQL-Server 2000 job). Could anybody help?

  Thanks in advance,

  Jon
0
JonGartzia
Asked:
JonGartzia
1 Solution
 
EDDYKTCommented:
Have you set the time out value

ie

set cn = Server.CreateObject("ADODB.Connection")
cn.CommandTimeout = 60
cn.open sConnString
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So you want an exit code to be generated from your VB6 app that can be trapped by your SQL server job?  (Typically 0 means success and anything indicates something went wrong.)  Here is how you can do it.  Just set the global exitCode variable to the value you want and then use Unload Me to end the program.

' API Call to generate an Exit Code *** Do all clean up First! ***
' When this function is called the program IMMEDIATELY exits with the
' specified exit code.
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

' Used to determine if we are running in the IDE or not
Private Declare Function GetModuleFileName Lib "kernel32" Alias _
    "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, _
    ByVal nSize As Long) As Long

Private exitCode as Long ' Set this global variable to the code you want to exit with

Private Sub Form_Unload(Cancel As Integer)
    Dim strFileName     As String
    Dim lngCount        As Long
           
    ' Produce an exit code that is trappable by other programs
    strFileName = String(255, 0)
    lngCount = GetModuleFileName(App.hInstance, strFileName, 255)
    strFileName = Left(strFileName, lngCount)
    If UCase(Right(strFileName, Len(App.EXEName) + 4)) = UCase(App.EXEName) & ".EXE" Then
        ExitProcess exitCode ' We are not in the IDE...actually exit with code
    Else
        MsgBox "Exit Code: " & exitCode ' We are in the IDE...simulate exit w/ code
    End If
End Sub
0
 
JonGartziaAuthor Commented:
Thank you very much, Idle Mind. It works.
0
 
mikey2niceyCommented:
I was looking for something very similar and this was just the job Idle Mind. Thanks.

Mike
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now