|
-
Jul 26th, 2005, 06:23 AM
#1
Thread Starter
Addicted Member
how to execute a file type? (Resolved with thanks)
im createing my own GOOGLE EARTH KML files. These KML files are created by useing notepad then saveing as a KML extention.
When you double click on a KML file, it auto starts Google Earth and zooms to the co ords etc in the file.
I have created my own KML files which work fine, i just have to double click them to execute them. How would i do this effect in vb.
I want to execute the file, the same way as double cliking on it would.
Many thanks in advance.
Last edited by fgp123; Jul 27th, 2005 at 04:28 AM.
-
Jul 26th, 2005, 06:27 AM
#2
Re: how to execute a file type?
Im pretty sure you need to change the default application for that program, you can do this manually but that isnt what you want.
Will look on vbCode.com...
-
Jul 26th, 2005, 06:29 AM
#3
Re: how to execute a file type?
-
Jul 26th, 2005, 06:30 AM
#4
Re: how to execute a file type?
fgp123,
Just shell to it. There are plenty of examples in the forum.
-
Jul 26th, 2005, 06:43 AM
#5
Re: how to execute a file type?
The easiest way to execute a file type is the ShellExecute API. That will open any file type that is registered in Windows.
e.g. txt - NotePad, wri - WordPad, doc - Winword, bmp - Paint etc.
VB Code:
Option Explicit
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
Const SW_SHOW = 5
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
End Sub
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
-
Jul 27th, 2005, 03:34 AM
#6
Thread Starter
Addicted Member
Re: how to execute a file type?
 Originally Posted by Keithuk
The easiest way to execute a file type is the ShellExecute API. That will open any file type that is registered in Windows.
e.g. txt - NotePad, wri - WordPad, doc - Winword, bmp - Paint etc.
VB Code:
Option Explicit
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
Const SW_SHOW = 5
Private Sub Command1_Click()
ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
End Sub
I get an error saying invalid use of the .Me command on that last line.
-
Jul 27th, 2005, 03:40 AM
#7
Re: how to execute a file type?
fgp123,
The function has to be in a form or you can replace the Me.hwnd with 0 if running in a module.
-
Jul 27th, 2005, 04:27 AM
#8
Thread Starter
Addicted Member
Re: how to execute a file type?
Perfect thank you, i had it in a module.
-
Jul 27th, 2005, 03:14 PM
#9
Re: how to execute a file type? (Resolved with thanks)
If you look at my code you will see that the ShellExecute call is made from a Command button, which should be on a Form. Me.hwnd returns the handle of the Form.
Keith
I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|