PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Classic VB - How do I open a file/web-page in its default application?-VBForums
Results 1 to 1 of 1

Thread: Classic VB - How do I open a file/web-page in its default application?

  1. #1

    Thread Starter
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Classic VB - How do I open a file/web-page in its default application?

    To perform either of these tasks you can use the ShellExecute API function as shown below.

    ShellExecute basically tells Windows to open the item as if you had double-clicked it in Windows Explorer.

    VB Code:
    1. 'in General-Declarations:
    2. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal lpOperation As String, _
    5.     ByVal lpFile As String, _
    6.     ByVal lpParameters As String, _
    7.     ByVal lpDirectory As String, _
    8.     ByVal nShowCmd As Long) As Long
    9.  
    10.  
    11. 'Example code:
    12.      'open a file
    13.   ShellExecute Me.hWnd, "open", "c:\My folder\Test.doc", vbNullString, "C:\", ByVal 1&
    14.  
    15.      'open a web page
    16.   ShellExecute Me.hWnd, "open", "http://www.VBForums.com", vbNullString, "C:\", ByVal 1&

    Here are two useful Subs for you, which will make the code easier to write:
    VB Code:
    1. Private Sub OpenAFile(strFileLocation As String)
    2. 'Just call the OpenAFile sub with the path of the file to open as its parameter.
    3.     If Dir$(strFileLocation) = "" Then
    4.         Exit Sub
    5.     End If
    6.     ShellExecute Me.hWnd, "open", strFileLocation, vbNullString, "C:\", ByVal 1&
    7. End Sub
    8.  
    9. Private Sub OpenURL(strURL As String)
    10. 'Just call the OpenURL sub with the URL of the webpage to open as its parameter.
    11.  
    12.     ShellExecute Me.hWnd, "open", strURL, vbNullString, "C:\", ByVal 1&
    13. End Sub
    14.  
    15.  
    16. 'Example code (same effect as the examples above)
    17.   Call OpenURL("http://www.VBForums.com")
    18.   Call OpenAFile("c:\My folder\Test.doc")





    Cheers,

    RyanJ
    Last edited by si_the_geek; Jul 18th, 2005 at 05:16 PM. Reason: added explanation & tidied up

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width