swansonplace
asked on
vb 6.0 shellexecute substitute
I am currently executing the below line:
lResult = ShellExecute(hwnd, vbNullString, labImageFile.caption, vbNullString, "", 1)
I am trying to read a .jpg file that exists at the location being looked at. I "think" that the shellexecute command
cannot read all file types. It can read "document files" which I "assume" jpg is not.
Is there another function that will allow me to open any file or execute any file. All I am doing, is opening or
executing any file on a local computer.
Thanks.
lResult = ShellExecute(hwnd, vbNullString, labImageFile.caption, vbNullString, "", 1)
I am trying to read a .jpg file that exists at the location being looked at. I "think" that the shellexecute command
cannot read all file types. It can read "document files" which I "assume" jpg is not.
Is there another function that will allow me to open any file or execute any file. All I am doing, is opening or
executing any file on a local computer.
Thanks.
ASKER
I get a result error of 31. The file name is winter.jpg.
ShellExecute(hwnd,"open", labImageFile.caption, vbNullString, "", 1)
ASKER
For file name winter.jpg, I have no problem with opening the file directly in the directory.
ASKER
Below is a snippet from the shellexecute documentation
pFile
Address of a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.
pFile
Address of a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.
Yes,... there may not be a default action (e.g. "open") as mentioned by egl1044 for that file type.
PS.
[ http://support.microsoft.com/?kbid=238245 ]
A return of 31 indicates a failure of "no association".
Did you try to double-click the file from Windows Explorer [i.e. not through your code].
Did an application open as expected?
PS.
[ http://support.microsoft.com/?kbid=238245 ]
A return of 31 indicates a failure of "no association".
Did you try to double-click the file from Windows Explorer [i.e. not through your code].
Did an application open as expected?
Yes since you want to open a file you need to tell it to "open" for the second parameter. If you wanted to print then you would tell it "print"
If the above don't work I would check the filepath and make sure it doesn't have an errors or null characters appended.
If the above don't work I would check the filepath and make sure it doesn't have an errors or null characters appended.
If you right-click the file in Windows Explorer, which of the menu commands that pop-up is in Bold type-face?
ASKER
I have done the following:
1. Open from windows explorer at the path that was issued to the shell execute command, and the
file opened with no issue.
2. I changed the default action to "open", and it still received a 31 error
3. When I look at the data being passed into the shellexecute command, the filepath contains only characters.
Thanks for you help. Any other suggestions.
1. Open from windows explorer at the path that was issued to the shell execute command, and the
file opened with no issue.
2. I changed the default action to "open", and it still received a 31 error
3. When I look at the data being passed into the shellexecute command, the filepath contains only characters.
Thanks for you help. Any other suggestions.
Any of these any better?...
1)
ShellExecute(hwnd,"open", Trim$(labImageFile.caption ), vbNullString, "", 1)
2)
ShellExecute(hwnd,"open", Trim$(labImageFile.caption ) & vbNullChar, vbNullString, "", 1)
3)
Dim strFile As String
strFile = Trim$(labImageFile.caption )
ShellExecute(hwnd,"open", strFile , vbNullString, "", 1)
....
Can you open other graphic image files (".gif", ".bmp", etc)?
BFN,
fp.
1)
ShellExecute(hwnd,"open", Trim$(labImageFile.caption
2)
ShellExecute(hwnd,"open", Trim$(labImageFile.caption
3)
Dim strFile As String
strFile = Trim$(labImageFile.caption
ShellExecute(hwnd,"open", strFile , vbNullString, "", 1)
....
Can you open other graphic image files (".gif", ".bmp", etc)?
BFN,
fp.
Try...
Option Explicit
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 Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
Dim fileName As String
fileName = labImageFile.Caption
If Dir(fileName) <> "" Then
ShellExecute Me.hwnd, "Open", fileName, 0&, 0&, SW_SHOWNORMAL
Else
MsgBox fileName, vbExclamation, "File Not Found"
End If
End Sub
Option Explicit
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 Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
Dim fileName As String
fileName = labImageFile.Caption
If Dir(fileName) <> "" Then
ShellExecute Me.hwnd, "Open", fileName, 0&, 0&, SW_SHOWNORMAL
Else
MsgBox fileName, vbExclamation, "File Not Found"
End If
End Sub
ASKER
I can link to another file in the same exact path but of type gif.
ASKER
It seems that I can read .bmp, .txt, .gif, but not .jpg. I tried another jpg file but it could not open.
Sounds like the association of your JPEG files may be screwed-up.
Do you have an application that can reset them? (Paint Shop Pro, for instance)
Do you have an application that can reset them? (Paint Shop Pro, for instance)
But author previously stated:
I have done the following:
1. Open from windows explorer at the path that was issued to the shell execute command, and the
file opened with no issue.
So how could the association be broken?...
swansonplace, are you sure you opened a JPG file from windows explorer?
I have done the following:
1. Open from windows explorer at the path that was issued to the shell execute command, and the
file opened with no issue.
So how could the association be broken?...
swansonplace, are you sure you opened a JPG file from windows explorer?
ASKER
Idle Mind,
Thank you. I am sure I can open the same exact file from windows explorer.
Idle Mind, since I am able to open other file types do you still want me to test the reference to the shellexecute command.
Thank you. I am sure I can open the same exact file from windows explorer.
Idle Mind, since I am able to open other file types do you still want me to test the reference to the shellexecute command.
ASKER
How do I check the associations for the jpg file
I'm sure everyone is confused because there is obviously a JPG file associaton, but the ShellExecute() call is still not working.
I recommend you create a new project with just the "labImageFile" label (and the full path to your JPG in it), a button named Command1, and the code I posted above.
This will eliminate any other factors we might not be seeing...
I recommend you create a new project with just the "labImageFile" label (and the full path to your JPG in it), a button named Command1, and the code I posted above.
This will eliminate any other factors we might not be seeing...
ASKER
I have created a dummy project, and added the below code. The result is returning 31.
Option Explicit
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 Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
Dim fileName As String
Dim lResult As Long
fileName = "c:\Friend.jpg"
If Dir(fileName) <> "" Then
lResult = ShellExecute(Me.hwnd, "Open", fileName, 0&, 0&, SW_SHOWNORMAL)
Else
MsgBox fileName, vbExclamation, "File Not Found"
End If
End Sub
Option Explicit
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 Const SW_SHOWNORMAL As Long = 1
Private Sub Command1_Click()
Dim fileName As String
Dim lResult As Long
fileName = "c:\Friend.jpg"
If Dir(fileName) <> "" Then
lResult = ShellExecute(Me.hwnd, "Open", fileName, 0&, 0&, SW_SHOWNORMAL)
Else
MsgBox fileName, vbExclamation, "File Not Found"
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I really have to Thank Everyone for help on this!!!!!!!
THANK YOU.
THANK YOU.
So what happened?...
Was there an association or not?
What did you do to resolve the problem?
Was there an association or not?
What did you do to resolve the problem?
ASKER
Eventhough I could open up from Windows Explorer, and view a jpg file the program was returning a result of 31.
I created a dummy project with the code you gave me. I also made the changes to the jpg file. It was set to letting
the service decide which file to open. I changed the type to a specific piece software package that can read .jpg files
and that did it.
The associated file type was off!
Thanks!!!!
I created a dummy project with the code you gave me. I also made the changes to the jpg file. It was set to letting
the service decide which file to open. I changed the type to a specific piece software package that can read .jpg files
and that did it.
The associated file type was off!
Thanks!!!!
"It was set to letting the service decide which file to open."
What version windows are you running? I'm not familiar with that option...
What version windows are you running? I'm not familiar with that option...
ASKER
The windows version is Windows XP professional v 5.1 sp 1. The option that it was set on was
"Use the Web Service to find the appropriate program". I set it to "Windows Picture and Fax Viewer".
It was really something finding it. Wew.
"Use the Web Service to find the appropriate program". I set it to "Windows Picture and Fax Viewer".
It was really something finding it. Wew.
Gotcha... =)
Glad we all collectively helped.
Shame you only accepted one suggestion as the resolution, though... but as long as you're happy that's all that matters.
BFN,
fp.
Shame you only accepted one suggestion as the resolution, though... but as long as you're happy that's all that matters.
BFN,
fp.
Is the file extension of your JPEG file (".jpeg", or ".jpg", or ".jpe" etc) registered as a known file type on your machine?
What happens when you double-click the file from Windows Explorer?
BFN,
fp.