Solved

Exiting VB execution with an error.

Posted on 2004-09-24
4
337 Views
Last Modified: 2010-05-02
 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
Comment
Question by:JonGartzia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 26

Expert Comment

by:EDDYKT
ID: 12141875
Have you set the time out value

ie

set cn = Server.CreateObject("ADODB.Connection")
cn.CommandTimeout = 60
cn.open sConnString
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12142483
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
 
LVL 1

Author Comment

by:JonGartzia
ID: 12142704
Thank you very much, Idle Mind. It works.
0
 

Expert Comment

by:mikey2nicey
ID: 12274814
I was looking for something very similar and this was just the job Idle Mind. Thanks.

Mike
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question