Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calling other applications within VB

Posted on 2000-04-06
8
Medium Priority
?
190 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses

609 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