Solved

Return A Value When VB Exits

Posted on 1998-12-07
12
191 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!!!
0
Comment
Question by:ssherlock
[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
  • 5
  • 4
  • 3
12 Comments
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1448466
When you create functions, functions can have return values.

Declare Function IsOk() as Boolean

   If Ok then
      IsOk = True
   else
      Is Ok= False

End Function
0
 

Author Comment

by:ssherlock
ID: 1448467
Does that include the Main (or VB equivalent) function ?  Could you give a quick and small example that I can pass on ?  Thanks, Simon.
0
 
LVL 14

Expert Comment

by:waty
ID: 1448468
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

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

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

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1448470
Why was this answer accepted?
0
 

Author Comment

by:ssherlock
ID: 1448471
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.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1448472
So which answer did they use? They didn't know how to make a function in VB?
0
 

Author Comment

by:ssherlock
ID: 1448473
>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 ?

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1448474
The Main EXE can return a value, see one of my previous comments.
0
 

Author Comment

by:ssherlock
ID: 1448475
>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.
0
 
LVL 14

Expert Comment

by:waty
ID: 1448476
You could store some return values in a file, or in the registry.
0
 

Author Comment

by:ssherlock
ID: 1448477
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.
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.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

695 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