Results 1 to 8 of 8

Thread: run a file ....

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15

    Question

    hi,

    how can i run a file such as helloworld.html with its default viewer after i click a cmdButton or some how in the code ...

    MS VB Enterprise, C

  2. #2

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'open a file with associated app can be done this way [using API]
    
    'open a file with it's associated application
    'this example opens an mp3 file with winamp
    
    
    'put this in a bas module
    '
     Public Declare Function ShellEx Lib "shell32.dll" Alias _
     "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
     ByVal lpFile As String, ByVal lpParameters As Any, _
     ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
     '
     Sub ShellDef(strFileName)
       x = ShellEx(Form1.hwnd, "open", strFileName, "", "", 1)
     End Sub
    
    'this goes in your form
    
    Private Sub Command1_Click()
    '  >>> code for event on form <<<
    '
     Dim strYourFileVariable$
      strYourFileVariable = "c:\myfolder\myFile.mp3"
      ShellDef strYourFileVariable
    '=====================================
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    Copy into a Module:
    Code:
    Public 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
    
    Public Const SW_SHOWNORMAL = 1
    then copy this into your form:

    Code:
    Public Sub Link2Net(AddUrl As String)
    Dim iloc As Long
    iloc = ShellExecute(Me.hwnd, vbNullString, AddUrl, vbNullString, "c:\", SW_SHOWNORMAL) 'Me.hwnd or formname.hwnf
    End Sub
    
    
    Private Sub Command1_Click()
    Call Link2Net(Text2.Text) ' I used a textbox for the url but just put the url inplace ("http://www.whatever.com")
    End Sub
    Hope that helps!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15
    i had try both of the code shown .... nothing happen when i try to open html file type (offline) ...??
    MS VB Enterprise, C

  6. #6
    Guest
    Try shelling IE directly with the file as the command line.

    Code:
    Shell "C:\Program Files\Internet Explorer\IExplore.exe C:\OfflineFile.htm", vbNormalFocus

  7. #7
    Lively Member Skateboarder's Avatar
    Join Date
    Nov 2000
    Location
    Delfzijl, the Netherlands
    Posts
    66

    This should work:

    [code]
    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 hwnd, "open", "helloworld.html", "", "", 1
    End Sub
    To VB or not to VB, that's the question...

  8. #8

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    15

    Unhappy

    sorry, is my mistake. all the code work perfectly ... thank!!
    MS VB Enterprise, C

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