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:
ShellExecute filelist1.Path & "\" & filelist1.selected, vbNullString, "C:\launcher\fceu.exe", SW_SHOWNORMAL
Re: Shellexecute selected file in filelistbox?
VB Code:
ShellExecute Me.Hwnd, "C:\launcher\fceu.exe", filelist1.Path & "\" & filelist1.selected, "C:\launcher" , SW_SHOWNORMAL
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
Re: Shellexecute selected file in filelistbox?
My problem is that it doesn't like this:
It says argument not optional on ".selected". What attribute do I need to use for a filelist box to get the selected item?
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.
Re: Shellexecute selected file in filelistbox?
... OR ... you have to specify an Index for Selected property:
... File1.Path & File1.Selected(File1.ListIndex) ...
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:
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!
Re: Shellexecute selected file in filelistbox?
VB Code:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
yVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Check your parameters. You are missing one.
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?
Re: Shellexecute selected file in filelistbox?
Yes, you pass the program as the third parameter and the file to open as the fourth.
HTH