Open application code

CEH

Curtis
Local time
Today, 14:14
Joined
Oct 22, 2004
Messages
1,187
OK< I started this in another post, but it has come down to being a coding problem. So I thought I would post that part here....... I am opening a program via the path (photo programs) and also opening the image (also via path)
As below
Code:
Private Sub cmdRun_Click()
On Error GoTo Err_cmdRun_Click

    Dim stAppName As String

    stAppName = ([txtPathToProg] & " " & [imagepath])
    
    Call Shell(stAppName, 1)

Exit_cmdRun_Click:
    Exit Sub

Err_cmdRun_Click:
    MsgBox Err.Description
    Resume Exit_cmdRun_Click

Now for most photo programs this works fine..... But a few I try... MS Paint and Gimp as 2 examples won't work.
If I drop the "imagepath" part the programs will open... But together, adding the "imagepath", it causes errors.
Is there another way to approach this to get around this problem? And why is it a problem in the first place?

Thanks
 
I just tried it with mspaint and a jpeg with a hard coded app and file location. Have you tried to debug.print to see what exactly is being passed to the Call Shell?
 
Try changing the following line of code:
Code:
stAppName = ([txtPathToProg] & " " & [imagepath])
...to:
Code:
stAppName = """" & [txtPathToProg] & """ """ & [imagepath] & """"
 
Your the man Byte!!!!
Works like a charm now....With all programs......
Could you explain what the difference makes? Inserting empty string???
 
All my change did was to enclose both the application path and the image path arguments in quotes. This is to account for Path arguments which contain spaces in strings. For example:

C:\Program Files\My Image Program\MyProg.exe C:\My Images\Image1.jpg

...will likely have problems, because the Shell command could interpret the command as having six arguments instead of two:
C:\Program
Files\My
Image
Program\MyProg.exe
C:\My
Images\Image1.jpg


However, if you enclose the arguments in quotes as the text qualifier thus:

"C:\Program Files\My Image Program\MyProg.exe" "C:\My Images\Image1.jpg"

...then the Shell command properly recognizes and interprets the two arguments:
C:\Program Files\My Image Program\MyProg.exe
C:\My Images\Image1.jpg
 
Last edited:
  • Like
Reactions: CEH
Thanks again Byte.... You are referring to the spaces between words in the path? I saw that when comparing paths that worked and those that didn't... You don't know how many hours I looked at different examples of this and NO ONE took this into consideration! Workin good now! Thanks again!
 

Users who are viewing this thread

Back
Top Bottom