Solved

Return A Value When VB Exits

Posted on 1998-12-07
12
184 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
  • 5
  • 4
  • 3
12 Comments
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 13

Expert Comment

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

0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Why was this answer accepted?
0
 

Author Comment

by:ssherlock
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 13

Expert Comment

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

Author Comment

by:ssherlock
Comment Utility
>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
Comment Utility
The Main EXE can return a value, see one of my previous comments.
0
 

Author Comment

by:ssherlock
Comment Utility
>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
Comment Utility
You could store some return values in a file, or in the registry.
0
 

Author Comment

by:ssherlock
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now