[Webinar] Streamline your web hosting managementRegister Today


Shell Command only Works Sometimes.  HELP!

Posted on 1999-11-09
Medium Priority
Last Modified: 2010-05-02
I've written an image viewing application in VB6 Pro.  A user views images stored on his/her computer in an image box and can do various things like editing.  Basically, the user configures my program to work with their favorite graphics editor.  I save this info to the registry without a problem.  Anyway, there's a huge bug in my edit routine.  I found it today when I installed my program on someone else's computer.  And MS Paint was the problematic editor, even for BMP files.

Here's the code I use to bring the image up in the selected editor:

Private Sub mnuFileEdit_Click()
    Dim dblRetVal As Double
    Dim strReply As String
    If m_EditorChoice = "" Then
        strReply = MsgBox("You must choose a graphic editing " _
                & "program on your system to edit " _
                & vbCrLf & "images that you view." _
                & vbCrLf & vbCrLf _
                & "Click Preferences ---> Graphics Editor on " _
                & "the Lucid P.i.X. menu to " _
                & vbCrLf & "make your selection.", _
                vbOKOnly, "Graphic Editor Not Chosen")
        Exit Sub
    End If
    If m_SelectedFile = "" Then
        strReply = MsgBox("You must select a file in the file list box" _
                & vbCrLf & " before you can edit.", _
                "File not selected for edit")
        Exit Sub
        dblRetVal = Shell(m_EditorChoice & " " & m_SelectedFile, 1)
    End If
End Sub

SelectedFile is the pathname and filename of the file to edit.  My editors (PhotoPaint, Debabelizer, etc.) work fine, but others (like Paint and NetStudio) will not recognize the path and filenames that have spaces in them.  For instance a file, Dog.bmp in the My Documents folder will produce an annoying error like "My.bmp not found."  This only happens with some editors, so I'm at a loss as to how to work this out.  These same editors will open these files on their own, just not from my program.  I'd be grateful for any ideas.
Question by:ljklinsky
LVL 32

Accepted Solution

Erick37 earned 200 total points
ID: 2195859
Convert the long names into short path names using GetShortPathName API:

Private Declare Function GetShortPathName Lib "kernel32" _
         Alias "GetShortPathNameA" (ByVal lpszLongPath As String, _
         ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private Function GetShortName(ByVal sLongFileName As String) As String
    Dim lRetVal As Long
    Dim sShortPathName As String
    Dim iLen As Integer
    'Set up buffer area for API function call return
    sShortPathName = Space(255)
    iLen = Len(sShortPathName)
    'Call the function
    lRetVal = GetShortPathName(sLongFileName, sShortPathName, iLen)
    'Strip away unwanted characters.
    GetShortName = Left(sShortPathName, lRetVal)
End Function

Private Sub Command1_Click()
Debug.Print GetShortName(App.Path)
End Sub

Author Comment

ID: 2196777
Bless you! :)

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question