Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you call a VB executable from within another VB app? 4

Status
Not open for further replies.

CBMC

Programmer
Nov 22, 2001
13
CA
I am working with VB 6.0 and I am pretty new at this, so any help will be appreciated.

I have created a VB application (call it app #1) that takes in command-line parameters. App #1 does it's calculations and I want this to be called by another VB application (call it app #2). Both do not require any forms (all is done in sub main()).

I have two questions:

1. How would I call VB app #1 with command-line parameters from within VB app #2? (can I do this without using shell?)

2. How does one return a value in an application? (i.e. I want VB app #1 to return an integer).
If you need more details, let me know and I'll post another message.

Any help is greatly appreciated. Thanks
 
Use this to call an exe:

lRet = ShellExecute(app.hwnd, "", app.name, parameters,, 0)

An exe can't return any value when executed, if you wan't that you need to use a .dll.

Regards,
Mats
 
I guess it's worth demonstrating how. The following example illustrates a solution to both the initial questions.

Program 1
This is the program to which you can pass a parameter, and which returns a value (note that the value is limited to being numeric). For the purposes of the example, a message is shown indicating the passed parameter, and then returns a value that is double this.

WARNING: If you run this program in the IDE it will close VB

Ok, create a project with no forms. Add a module and drop in the following code:
[tt]
Option Explicit

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

Private Sub Main()
Dim lExitCode As Long
MsgBox "You passed the following parameter: " & Command$
If IsNumeric(Command$) Then lExitCode = CLng(Command$) * 2
ExitProcess lExitCode
End Sub
[/tt]
Compile this program (in the rest of the example I assume it is compiled to c:\exitprocess.exe).

Ok, now create a new project with a form. Add a command button to the form, then drop in the following (this program is safe to run from the IDE):
[tt]
Option Explicit

Private Sub Command1_Click()
' Use script host for quick way of running another program synchronously
Dim wsh As Object
Set wsh = CreateObject("wscript.shell")
MsgBox "Exit code was: " & wsh.run("c:\exitprocess.exe", , True)
Set wsh = Nothing
End Sub
 
I am new to VB6 and am writing an application. I want to include a link to a web-page from within one of my forms. I think I need to use Shell - but then what?
 
Thanks strongm. I've tested it and it works wonderfully! I don't think people like you get enough credit for what they do.

Again thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top