We help IT Professionals succeed at work.

Return A Value When VB Exits

ssherlock
ssherlock asked
on
206 Views
Last Modified: 2010-05-03
Can VB return values when it exits to let us know error conditions etc ?  In C you would just use return(1) but nobody in our VB team seems to know!!!
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
Does that include the Main (or VB equivalent) function ?  Could you give a quick and small example that I can pass on ?  Thanks, Simon.

Commented:
The main, is a sub, it can not return values

Here is another sample

' *** Retrieve the Short Path Name
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long

Public Function GetShortPath(strFilename As String) As String
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 7/12/98
   ' * Time             : 12:17
   ' * Module Name      : Lib_Module
   ' * Module Filename  : Lib.bas
   ' * Procedure Name   : GetShortPath
   ' * Parameters       :
   ' *                    strFilename As String
   ' **********************************************************************
   ' * Comments         :
   ' *  Retrieving the Short Path Name
   ' *  Retrieve to Short Path name for a file.
   ' *  For instance "c:\my documents\this is a long file.doc" becomes "c:\mydocu~1\thisis~1.doc".
   ' *  This use the GetShortPathName API function that is built into a Windows DLL
   ' *
   ' *
   ' **********************************************************************

   Dim nRes             As Long
   Dim sPath            As String

   sPath = String$(165, 0)
   nRes = GetShortPathName(strFilename, sPath, 164)
   GetShortPath = Left$(sPath, nRes)

End Function

Commented:
Maybe this function will work.
Declare Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)

Commented:
Why was this answer accepted?

Author

Commented:
Because the people I passed it onto somehow got it working.  I presumed they used this answer but admit I don't *know* it worked.

Commented:
So which answer did they use? They didn't know how to make a function in VB?

Author

Commented:
>So which answer did they use?
Not sure to be honest.

>They didn't know how to make a function in VB?
Would it matter if the main EXE can't return a value ?

Commented:
The Main EXE can return a value, see one of my previous comments.

Author

Commented:
>Declare Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)
This was the only other comment to this question that you made and I thought we had established that there was a question mark over it.  If the EXE can return a value any other way then please let me know.  Thanks, Simon.

Commented:
You could store some return values in a file, or in the registry.

Author

Commented:
waty,

I have just checked and what they did in the end was have the scheduling programme check whether the error file was zero bytes (successful completion) or not.  If not then raise an alert telling the operator to check the error file.  Simon.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.