It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Opening Program with a button

Moderator: dafunkymunky

Opening Program with a button

Postby weirddemon on Fri Jan 02, 2009 1:10 am

I'm building a program that will allow me to launch other files/programs with a button.

I'm currently doing this with
Code: Select all
Shell ("c:\Test.txt")


The problem is that this program is going to be a light weight .exe that will be used on multiple computers. That being said, I can't really use the Shell command because it requires a direct path.

I was wondering how to tell the button to call forth a program or file as long as it is in the same folder as the exe.

Any help would be appreciated.

Thanks
weirddemon
 
Posts: 3
Joined: Fri Jan 02, 2009 1:02 am

Re: Opening Program with a button

Postby Etheryte on Fri Jan 02, 2009 1:20 am

Image
User avatar
Etheryte
250+ Club
 
Posts: 255
Joined: Sun Mar 16, 2008 12:21 pm

Re: Opening Program with a button

Postby weirddemon on Fri Jan 02, 2009 1:36 am

That's funny because I use the "Let me Google that for you" pretty often.

I guess my problem was that I wasn't wording it right in google, because I googled it for awhile before I went to the forums for the answer.

Thanks
weirddemon
 
Posts: 3
Joined: Fri Jan 02, 2009 1:02 am

Re: Opening Program with a button

Postby White95dp on Mon Mar 09, 2009 6:25 pm

Dim cMyOut As String
cMyOut = App.Path & "\Quest.exe"
Dim cShellcmd As String
cShellcmd = """" & cMyOut & """"
Shell cShellcmd, vbNormalFocus
White95dp
 
Posts: 7
Joined: Mon Mar 09, 2009 12:52 am

Re: Opening Program with a button

Postby Keithuk on Sat Jul 11, 2009 1:44 pm

weirddemon wrote:I'm building a program that will allow me to launch other files/programs with a button.

I'm currently doing this with
Code: Select all
Shell ("c:\Test.txt")



I know this is an old topic but no one has given a useful solution.

No you can't really use Shell for this because Shell will only open a com, exe or bat file on its own. You can use Shell if you specify what exe you want to open the txt file.

Shell "NotePad.exe " & "c:/temp.txt", 1

You don't have to specify where NotePad.exe is because its in the Windows path.

A far better way of doing this is to use the ShellExecute API call.

Code: Select all
Option Explicit

Private Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
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()

ShellExecute Me.hwnd, "open", "c:/temp.txt", vbNullString, vbNullString, SW_SHOW

End Sub


This will use the registered application used for opening txt files. This is normally NotePad.exe in Windows.

Now ShellExecute is s useful API where you can Open any file, Print any file and Email someone. :wink:
User avatar
Keithuk
 
Posts: 11
Joined: Fri Jun 01, 2007 11:16 am
Location: Staffordshire, England


Who is online

Users browsing this forum: No registered users and 3 guests