Results 1 to 3 of 3

Thread: open file filelistbox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2006
    Location
    Greater Manchester, UK
    Posts
    476

    open file filelistbox

    I have this code, i am making a file explorer. How do i get it to open the file i click on when i double click it. I have got the path right as it shows in a msgbox.

    I tried Shell strFullPath, VbNormalFocus


    Code:
    Private Sub Dir1_Change()
        File1.Path = Dir1.Path
    End Sub
    
    Private Sub Drive1_Change()
        Dir1.Path = Drive1.Drive
    End Sub
    
    Private Sub cmdMask_Click()
        File1.Pattern = txtMask.Text
    End Sub
    
    Private Sub File1_DblClick()
        Dim strFullPath As String
        
        strFullPath = Dir1.Path
        
        If Right$(Dir1.Path, 1) <> "\" Then strFullPath = strFullPath & "\"
        
        strFullPath = strFullPath & File1.FileName
        
        MsgBox strFullPath
        Shell strFullPath 'This part dosent work
    End Sub
    Thanks in advance Chris1990
    If your question is answered then mark your thread RESOLVED and give credit to whoever answered it.

    If you fail, try and try again, its the only way to success.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: open file filelistbox

    Not every file type can be shelled using the Shell function.
    If you try to shell text file you would need to specify associated program like the NOTEPAD:

    Shell "notepad c:\test.txt" and so on...
    In you case it may look like:

    Shell "notepad " & strFullPath

    However better way is to use ShellExecute api function that resolves the associated program automatically.
    Search forum for samples.

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: open file filelistbox

    Example:
    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    4. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    5. ByVal lpParameters As String, ByVal lpDirectory As String, _
    6. ByVal nShowCmd As Long) As Long
    7.  
    8. Private Const SW_SHOWNORMAL = 1
    9.  
    10. Private Sub Command1_Click()
    11. ShellExecute Me.hwnd, vbNullString, File1.FileName, vbNullString, "C:\", SW_SHOWNORMAL
    12. End Sub

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