Solved

Setting

Posted on 2001-09-17
3
991 Views
Last Modified: 2007-11-27
I want to be able to set the operating system ERRORLEVEL from a VB application(NT4 with VB6) so the calling process can respond to the ERRORLEVEL accordingly.  The errorlevel would correspond say 1 for success and 0 for no and other values as required.    

Batch file would be as follows:

MYVBAPP.EXE   (call vb app which sets errorlevel)
if errorlevel 1 goto next1
process1.exe
goto next2
:next1
goto end
:next2
process2.exe
:end
0
Comment
Question by:ajmfoxy
[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
3 Comments
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 50 total points
ID: 6487244
0
 
LVL 1

Expert Comment

by:K7
ID: 6487524
Hi
this is straight from MSDN

HOWTO: Set an Error Level from a Visual Basic Application
ID: Q178357

 

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Basic Professional and Enterprise Editions for Windows, versions 4.0, 5.0, 60

--------------------------------------------------------------------------------


SUMMARY
This article contains a sample Visual Basic application that sets the error level upon exiting and a DOS batch file to test the result. Visual Basic applications can also retrieve the error level returned by another Windows application using the technique shown in Q129796 listed below.



MORE INFORMATION

Steps to Reproduce Behavior
Create a new Standard EXE project. Form1 is created by default.


Place three CommandButtons on the form (use the default names).


Add the following code to the General Declarations section of Form1:


      Private Declare Sub ExitProcess Lib "kernel32" _
      (ByVal uExitCode As Long)

      Private Sub Command1_Click()
         ExitProcess (50&) 'Button labeled "50"
      End Sub

      Private Sub Command2_Click()
         ExitProcess (100&) 'Button labeled "100"
      End Sub

      Private Sub Command3_Click()
         ExitProcess (150&) ''Button labeled "150"
      End Sub

      Private Sub Form_Load()
         Command1.Caption = "50"
         Command2.Caption = "100"
         Command3.Caption = "150"
      End Sub
 



Save your Project and Make an executable named Project1.EXE.


Create the following batch file named errlevel.bat in your project directory:


      echo off
      start /w project1
      rem "start /w"
      if errorlevel 150 goto 150
      if errorlevel 100 goto 100
      if errorlevel 50 goto 50
      echo Exit Code 0
      goto Done
      :150
      echo Exit Code 150
      goto done
      :100
      echo Exit Code 100
      goto done
      :50
      echo Exit Code 50
      :done
      echo done
 



Run the batch file. When the user clicks on a CommandButton, the application will terminate with the error level shown on the button. The batch file will then test the error level and echo the result to the screen.


Additional notes:

Start /w is necessary for this to work correctly in Windows 95.


"if errorlevel" must be in the order presented. "If the EXIT status is less than the specified value, the specified DOS command is executed; otherwise, processing continues with the next batch file command."


In order to retrieve the error level from a Visual Basic Program instead of a DOS Batch file:


Implement Knowledge Base article Q129796. Modify the call to ExecCmd function in the Form_Click event to pass "project1.exe" instead of "notepad.exe". Run the project and click on form1 to launch project1.exe.
0
 

Author Comment

by:ajmfoxy
ID: 6487600
Tried the program in the ZIP file pointed to by this and it does the trick.  

Many thanks.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

688 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