Solved

Loading programs from another program

Posted on 1998-08-24
11
138 Views
Last Modified: 2010-04-30
I need the code for a command button on a program...to load another program I have made.
0
Comment
Question by:Klueny2
  • 5
  • 3
  • 3
11 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1430837
You have to use the shell function

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

vbHide      0      Window is hidden and focus is passed to the hidden window.
vbNormalFocus      1      Window has focus and is restored to its original size and position.
vbMinimizedFocus      2      Window is displayed as an icon with focus.
vbMaximizedFocus      3      Window is maximized with focus.
vbNormalNoFocus      4      Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus      6      Window is displayed as an icon. The currently active window remains active.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430838
Hi,

    Option Explicit
    Dim ret3&
    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
   "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
   String, ByVal lpFile As String, ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
   
   
    Private Sub cmdRunCalculator_Click()

    ' Run any program EXE,COM from here.

      ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

     End Sub


      Private Sub Form_Load()
      End Sub


0
 

Author Comment

by:Klueny2
ID: 1430839
Also, lets say I wanted to send this program to somebody else in a zip file...and after they unzip it,...will the command button still work to open the prog? if not, how can I do this if I can?
0
 
LVL 14

Expert Comment

by:waty
ID: 1430840
I don't anderstand your question
0
 

Author Comment

by:Klueny2
ID: 1430841
Ok, sorry..I need to know the code so that a command button opens up another form in the same program.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:waty
ID: 1430842
Sub cmdButton_Click()

   frm2.Show

End Sub
0
 

Author Comment

by:Klueny2
ID: 1430843
It gives me a run-time error, and says object required
0
 

Author Comment

by:Klueny2
ID: 1430844
It gives me a run-time error, and says object required
0
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 50 total points
ID: 1430845
the answer to your Question: "I need the code for a command button on a program...to load another program I have made."

Let say your program name is MyProgram.exe

THIS IS A WORKING CODE.
use this code as is first , then change the line,
ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

with this line,
ret3& = ShellExecute(Me.hwnd, "Open", "MyProgram.EXE", "", App.Path, 1)

where MyProgram.EXE is your program that you wish to run..
(Note: Path is the path you choose: c:\MyProgram.EXE , E:\prog\MyProgram.EXE and so on.

If you have any question email to shay@hili.com or post here.


========== start code =========
'in your general declaration:
Option Explicit
           Dim ret3&
           Private Declare Function ShellExecute Lib "shell32.dll" Alias _
          "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
          String, ByVal lpFile As String, ByVal lpParameters As String, _
          ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
     
           
     Private Sub Command1_Click()

           ' Run any program EXE,COM from here.
            ' Replace the calc.exe with your program "MyProgram.EXE"
             ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

     End Sub

=========== end code ========
Shay.

0
 

Author Comment

by:Klueny2
ID: 1430846
I'm sorry...where do I put this following code? I'm kinda new and have no idea where it goes..

Option Explicit
    Dim ret3&
    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
   "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
   String, ByVal lpFile As String, ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430847
The code
Option Explicit
 Dim ret3&
 Private Declare Function........
Go in (general) (Declarations)

If need more help or to fix your code email to shayplace@hotmail.com
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now