Results 1 to 9 of 9

Thread: how to execute a file type? (Resolved with thanks)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    129

    Resolved 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.

  2. #2
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

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

  3. #3
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: how to execute a file type?


  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: how to execute a file type?

    fgp123,

    Just shell to it. There are plenty of examples in the forum.

  5. #5
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    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:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias _
    4. "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String,_
    5. ByVal lpFile As String, ByVal lpParameters As String, _
    6. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    7.  
    8. Const SW_SHOW = 5
    9.  
    10. Private Sub Command1_Click()
    11.  
    12. ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
    13.  
    14. 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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    129

    Re: how to execute a file type?

    Quote 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:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias _
    4. "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String,_
    5. ByVal lpFile As String, ByVal lpParameters As String, _
    6. ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    7.  
    8. Const SW_SHOW = 5
    9.  
    10. Private Sub Command1_Click()
    11.  
    12.  
    13. ShellExecute Me.hwnd, "open", "c:\yourlocation\yourfile", vbNullString, vbNullString, SW_SHOW
    14.  
    15. End Sub

    I get an error saying invalid use of the .Me command on that last line.

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    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.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2005
    Posts
    129

    Re: how to execute a file type?

    Perfect thank you, i had it in a module.

  9. #9
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    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
  •  



Click Here to Expand Forum to Full Width