Solved

Calling other applications within VB

Posted on 2000-04-06
8
172 Views
Last Modified: 2010-05-02
I have written 2 Vb projects and i want to call one from the other.  Is this easy and how is it done?
0
Comment
Question by:CRICE
[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
8 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2690401
Do you want to start the other application, or do you want the applications to be able to communicate with each other?
0
 
LVL 20

Expert Comment

by:hes
ID: 2690524
In a module put:

Public Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    dwX As Long
    dwY As Long
    dwXSize As Long
    dwYSize As Long
    dwXCountChars As Long
    dwYCountChars As Long
    dwFillAttribute As Long
    dwFlags As Long
    wShowWindow As Integer
    cbReserved2 As Integer
    lpReserved2 As Long
    hStdInput As Long
    hStdOutput As Long
    hStdError As Long
End Type

Public Type PROCESS_INFORMATION
    hProcess As Long
    hThread As Long
    dwProcessID As Long
    dwThreadID As Long
End Type

Public Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long

Public Declare Function CreateProcessA Lib "kernel32" _
(ByVal lpApplicationName As Long, ByVal lpCommandLine As _
String, ByVal lpProcessAttributes As Long, ByVal _
lpThreadAttributes As Long, ByVal bInheritHandles As Long, _
ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, _
ByVal lpCurrentDirectory As Long, lpStartupInfo As _
STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) _
As Long

Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject _
As Long) As Long

Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&

In your code where you want to start the other application put:

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO

'Initialize the STARTUPINFO structure:
start.cb = Len(start)

'Start the shelled application:
ret& = CreateProcessA(0&, "Your Other Program", 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)

'Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2690551
Well, if you just want to start it, why not use:

Call Shell("c:\Project2.exe", vbNormalFocus)
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 3

Expert Comment

by:ashunigam
ID: 2690774
Are these standard EXE or ActiveX?
0
 

Expert Comment

by:AshokKumar
ID: 2692260
Yeah hes. y all these codings (Smile. Of course u have done a great job but . . . ) Erick37's code is enough to start an application. Or if u need to start a new instance of an existing application u can use this:

First give the reference in Project->reference
Then

Dim obj as object
Set Obj = CreateObject("MsWord.Application")

0
 

Author Comment

by:CRICE
ID: 2692598
Thank you all for your help, just one more thing before i allocate the points, what if i wanted to pass information from one application to the other. Like a parameter list.  
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2693249
Your application can process command line parameters.

eg, start the program like this

Call Shell("c:\Project2.exe x y z", vbNormalFocus)

In Projext2's form load you can read the command line switch(es) like this:

Dim sCmdLine As String
sCmdLine = Command

sCmdLine will contain the string "x y z" which you can parse using the Split function.

VB help has an example of reading the command line, search for "Command Line."
0
 

Author Comment

by:CRICE
ID: 2693264
Thanks very much for your help, it's helped me loads!!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

734 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