• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

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.
   
0
swansonplace
Asked:
swansonplace
  • 12
  • 7
  • 7
  • +1
1 Solution
 
[ fanpages ]IT Services ConsultantCommented:
ShellExecute is not limited to just "documents".

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.
0
 
swansonplaceAuthor Commented:
I get a result error of 31.  The file name is winter.jpg.
0
 
nffvrxqgrcfqvvcCommented:
ShellExecute(hwnd,"open", labImageFile.caption, vbNullString, "", 1)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
swansonplaceAuthor Commented:
For file name winter.jpg, I have no problem with opening the file directly in the directory.
0
 
swansonplaceAuthor Commented:
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.
0
 
[ fanpages ]IT Services ConsultantCommented:
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?

0
 
nffvrxqgrcfqvvcCommented:
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.
0
 
[ fanpages ]IT Services ConsultantCommented:
If you right-click the file in Windows Explorer, which of the menu commands that pop-up is in Bold type-face?
0
 
[ fanpages ]IT Services ConsultantCommented:
PS. More code for your review:

[ http://www.vbaccelerator.com/codelib/shell/shellex.htm ]
0
 
swansonplaceAuthor Commented:
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.
 
0
 
[ fanpages ]IT Services ConsultantCommented:
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.

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
0
 
swansonplaceAuthor Commented:
I can link to another file in the same exact path but of type gif.
0
 
swansonplaceAuthor Commented:
It seems that I can read .bmp, .txt, .gif, but not .jpg.  I tried another jpg file but it could not open.
0
 
[ fanpages ]IT Services ConsultantCommented:
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)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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?
0
 
swansonplaceAuthor Commented:
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.





0
 
swansonplaceAuthor Commented:
How do I check the associations for the jpg file
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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...
0
 
swansonplaceAuthor Commented:
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
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
(I have WinXP Pro SP2)

In Windows Explorer...

Click on Tools --> Folder Options.

Click on the "File Types" tab.

Is there a "JPG" entry in the "Extensions" column?

    Yes.  Down below in the "Details" section, what does it "Open with"?  If necessary, click the "Change" button to chagne the application associated with JPGs.

    No.  Click on "New".  Type in "JPG" and select "Advanced".  Select an appropriated "Associated File Type" from the DropDown list and select "OK".  Click on "Close".
0
 
swansonplaceAuthor Commented:
I really have to Thank Everyone for help on this!!!!!!!


THANK YOU.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
So what happened?...

Was there an association or not?

What did you do to resolve the problem?
0
 
swansonplaceAuthor Commented:
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!!!!



0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"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...
0
 
swansonplaceAuthor Commented:
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.

 
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Gotcha...  =)
0
 
[ fanpages ]IT Services ConsultantCommented:
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 12
  • 7
  • 7
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now