NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand call to VisualBasic EXE, how to get exit code from VB?

Using the TestStand 3.0 "Call Executable" adapter, I am calling an EXE written in Visual Basic 6.0. I would like the VB program to return a 'passed' or 'failed' status to TS. How can this be done? The TS call step has an "Exit code status action" control, but the exit code is always zero.

I have a workaround where I can choose to make the VB terminate with a run-time error ("Unload Me(-1)") that the TS can detect, but I am hoping for something a little more normal.
0 Kudos
Message 1 of 5
(5,055 Views)
I've never heard of an exe returning any values. I may be wrong, but an exe was meant to be standalone, not called by anything, so there are no provisions to return parameters, except error codes. If you have the VB source code, you could make it into a dll and use parameters to pass values back to TS. Otherwise, your only option is to set an error for a failure, like your workaround.
- tbob

Inventor of the WORM Global
0 Kudos
Message 2 of 5
(5,052 Views)
Actually, an EXE is sort of a subroutine called from Windows. With programs written in 'C', the "Main" routine ends with "return n;" where n is a return value back to the calling program (in this case, Windows). I presume the TestStand Call Executable step would read this value and put it in the step's result.ExitCode variable.

It would be useful if Visual Basic had a similar exit code.

What, exactly does "Step.Result.ExitCode" do?

PS. I did try making my VB program into an ActiveX EXE so it could return a passed/failed property. I ran into other problems that I may make into another discussion.

Thanks for your reply
0 Kudos
Message 3 of 5
(5,038 Views)
Hello,

Step.Result.ExitCode returns the exit code of the exe. This is usually determined by the return value (ie: "return 0" usually indicates that everything exits correctly).

That being said, I would highly recommend building a dll instead of calling an exe and just passing parameters back as is intended by the different programming techniques. An exe, while it does have an exit code, is not intended to pass variables back. I agree with the earlier posting suggesting you use a different type of code module. As you have discovered, it is definitely possible to get around the issue and use a exe, but it is generally not an encouraged programming practice.

Regards,

Aaron B.
National Instruments
0 Kudos
Message 4 of 5
(5,019 Views)
Thank you Aaron, but I made a mistake and there is no work-around. If I force the VB EXE to end with a run-time error, the error pop-up comes from the VB engine and TestStand still sees Step.Result.ExitCode (and Error.Code) as zero.

All I can do is add a TS step following the Call Executable. The step asks the operator, "Did the test pass?". This is embarrassing.

I really want to make the program ActiveX, but I ran into another big problem. I will start a new conversation thread under the subject, "Calling VisualBasic ActiveX from TestStand, how to make TS wait for the VB 'DONE button' click event."
0 Kudos
Message 5 of 5
(5,009 Views)