Results 1 to 10 of 10

Thread: Shellexecute selected file in filelistbox?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Shellexecute selected file in filelistbox?

    I'm trying to launch the selected file in a filelistbox with a specified app., however, filelist1.selected doesn't seem to be correct. What should this be when I use a filelistbox? I've always used listviews & listboxes for most of my apps in the past. My code is below. Any help is appreciated. This is my last issue to resolve.

    VB Code:
    1. ShellExecute filelist1.Path & "\" & filelist1.selected, vbNullString, "C:\launcher\fceu.exe", SW_SHOWNORMAL

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Shellexecute selected file in filelistbox?

    VB Code:
    1. ShellExecute Me.Hwnd, "C:\launcher\fceu.exe", filelist1.Path & "\" & filelist1.selected, "C:\launcher" , SW_SHOWNORMAL
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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

    Re: Shellexecute selected file in filelistbox?

    Debugging, debugging and again - debugging. Step through your code by pressing F8 so you can actually see what's in your variables OR put a breakpointer directly on that line (F9):

    - what is the actual value of filelist1.Path
    - what is the actual value of filelist1.selected
    - what is the actual combined value of filelist1.Path & "\" & filelist1.selected

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Shellexecute selected file in filelistbox?

    My problem is that it doesn't like this:

    VB Code:
    1. filelist1.selected

    It says argument not optional on ".selected". What attribute do I need to use for a filelist box to get the selected item?

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

    Re: Shellexecute selected file in filelistbox?

    I think you may simply use FileName:

    ... File1.Path & File1.FileName ...

    Although, "\" in between might not be needed as File1.Path should be ending with back slash.

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

    Re: Shellexecute selected file in filelistbox?

    ... OR ... you have to specify an Index for Selected property:

    ... File1.Path & File1.Selected(File1.ListIndex) ...

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Shellexecute selected file in filelistbox?

    This is taking way to long................Now I'm getting an error on this. And yes, I put my Public Declarations in a module for the ShellExecute command.

    VB Code:
    1. ShellCode = ShellExecute(Me.hwnd, "open", filelist1.FileName, , "C:\launcher\fceu.exe", SW_SHOWNORMAL)

    And in General Declarations, I dimmed shellcode as and integer

    This code is on a command button and I get "Argument not optional" error on the line I posted above. I've looked on 3 API sites and everything looks correct to me. All I'm trying to do is launch my selected file in a filelistbox with a specified application! It's been two years since I 've use any API, but I don't remember the ShellExecute being this hard!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Shellexecute selected file in filelistbox?

    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    2. ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    3. yVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Check your parameters. You are missing one.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    Re: Shellexecute selected file in filelistbox?

    Ok, I got it working, but I need to open the file with a "specified" program, not the one that is associated with it. Will shellexecute allow me to do this?

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Shellexecute selected file in filelistbox?

    Yes, you pass the program as the third parameter and the file to open as the fourth.

    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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