Problem

cyseng10
cyseng10 used Ask the Experts™
on
i have problem to return a value. Example: i running A appplication then it will call B application from A. the B will run as verification. if B return the result is OK then the A will continue to run else B will show Error window.


How do i do this. since calling B applcation from A application. how do i get the result from B. sp, A can continue to run else Stop running A application.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Why does B need to be an application?  What if B were simply a component that you can call from A.  Components are much better for passing data back and forth. A component can be very complex and act just like an application.  Please explain in more detail.  Instead of program A, Program B, please state it like this to help us help you:

I am writing a program called "MyProgram"

MyProgram is calling a 3rd party program called "Excel"
   or
MyProgram is calling another program I am developing called "MyCheckerProgram"

Thanks.
Hi Cyseng10

The SHELL function runs an executable program and returns a Variant (Double) representing the program's task ID if successful, otherwise it returns zero.

Syntax
Shell(pathname[,windowstyle])

eg.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1)

Specifying 1 as the second argument opens the application in normal size and gives it the focus.

Your program A can use this function to execute and determine the success/failure of program B

EB

Author

Commented:
ElijahBailey,

  thanks for your comment, my B application will perform task to verify. how do i get result on it? example, if the result is ok then A application will continue to run else a error window will appear to ask user doing something.

  now, i have problem to get the result. the comment you given is return the result on B application is running or not. but i need the result generated from B application. any suggestion to get the result and return to A application.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Not to my knowledge, Cyseng10. You can get return codes but unless the program was specifically written to return results to a calling program, there is little you can do.

However, if you wrote program B yourself, there are a number of things that you could do. For example, you could write program B as a DLL and exchange the information though strings or other variables. Or you could pass the information through temp files but otherwise, you are limited to the result codes from the application.

If you did not write program B, it gets a bit harder. It is possible for one program to capture the output from another program in which case you could analyse the results directly.

To capture the output and control the input of programs that use low-level console I/O, you sit in a loop while the child process is executing, continuously monitoring the contents of the console screen buffer using ReadConsoleOutput() and sending any keystrokes using WriteConsoleInput().

There are several problems with this design. One minor problem is that it doesn't cope at all well with Win32 programs that take full advantage of the features of the Win32 low-level console paradigm and use alternate console screen buffers for their output. A more major problem is that because it uses polling (Win32 not providing any handy event mechanism to latch on to so that the monitor could know when the buffer has been modified) it is always going to be both unreliable and expensive.

To capture the output and control the input of programs that use high-level console I/O, you redirect their standard input and standard output through pipes, and read from and write to the other end of the pipes in the monitoring process.

The advantage of this method is that you don't need to worry about missing any output, since this approach doesn't use polling. But, conversely, this method has a problem of its own, in that it won't capture any output generated by low-level console I/O, and that programs that use low-level console I/O for input will bypass the redirection entirely.

EB

Commented:
maybe what you can do is make program B as an Active X DLL
and call it from A. Create a property in B that will serves
as a check if the calling app (Program A) will continue.

The call could look like this

DIM appB as Object

set AppB = CreateObject("AppB.clsAppB)
AppB.Activate
'lets assume this will activate and will   process something and assigns a value to the property RetValue

' example code inside class clsAppB of AppB
if MyProcess = True then
   Me.RetValue = 0
else
   Me.RetValue = -99
end if

'continuation of code in AppA
IF AppB.RetValue  <> 0 then
   End -terminate AppA
end if

You can return a value from a VB App you created yourself.  Make sure you clean up all your objects and file handles before running this.  Then perform:

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

' terminate the program and return ErrorLevel = 3
ExitProcess 3

Author

Commented:
twalgrave ,

  cab you tell me more detail on this coding. i not familiar on this handing. if can, do you have any sample code for it.


thanks.
That is the coding.  The windows API function called ExitProcess ends you application and allows you to return back a long numeric value .  In your case, this code would need to be placed in application B.  When application B has finished it's processing it can run a test like:

If BSuccess then
    ExitProcess 0
else
    if bFailedDuringLoad
        ExitProcess 1
    elseif bFailedDuringRead
        ExitProcess 2
    Elseif bFailedDuringWrite
        ExitProcess
    endif

endif

Of course the example here uses variables such as bSuccess, bFailedDuringLoad, etc that need to be set somewhere in application B (in otherwords, these are not defined anywhere, you need to define and set them in application B)

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in Community Support that this question is:
- points to twalgrave
Please leave any comments here within the
next seven days.
answer force-accepted

DigitalXtreme
CS Moderator

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial