Shell() Function

Mr_Si

Registered User.
Local time
Today, 17:17
Joined
Dec 8, 2007
Messages
163
Hi all, I have the following code:

Code:
Private Sub lstboxProjectFiles_DblClick(Cancel As Integer)
Dim strWholePath As String

    Call getextension(Me.lstboxProjectFiles)
    If getextension(Me.lstboxProjectFiles) = "nbp" Then
        strWholePath = Me.ProjectPath & "\" & Me.lstboxProjectFiles
        MsgBox "This is the data in strWholeFile ' " & strWholeFile & " ' ", vbOKOnly
        Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe & strWholePath")
        
    ElseIf getextension(Me.lstboxProjectFiles) = "CMG" Then
        strWholePath = Me.ProjectPath & "\" & Me.lstboxProjectFiles
        MsgBox "This is the data in strWholeFile ' " & strWholeFile & " ' ", vbOKOnly
        Shell ("c:\program files\01dB\01dB Software\dBBati32.exe  & strWholePath")
        
    'ElseIf getextension(Me.lstboxProjectFiles) = "DWG" Or "DXF" Then
        'shell ("c:\program files
    Else
        
    Call GoHyperlink(Me.ProjectPath & "\" & Me.lstboxProjectFiles)
    'Application.FollowHyperlink Me.ProjectPath & "\" & Me.lstboxProjectFiles
    '    nDT = GetDesktopWindow()
     '   nApp = ShellExecute(nDT, "Open", Me.ProjectPath & "\" & Me.lstboxProjectFiles, "", "C:\", SW_SHOWNORMAL)
      '  DoEvents
    End If
End Sub
Before you say anything about using an alternative, I need to use the shell command rather than application.hyperlink or shellExecute as these two commands don't work in a few of the cases. (I have tried :) )

Anyway, basically I am trying to open a program and file with it too. But all I can get at the moment is an open program.

Also,
For some reason, the message box for strWholeFile (only using a msgbox for debugging purposes) is returning nothing in the variable, so for some reason it's not getting information delivered into it, which is bizarre as it should be.

I'd appreciate your help, mainly with the syntax for Shell()

another version I'd tried was

Code:
Private Sub lstboxProjectFiles_DblClick(Cancel As Integer)
Dim strWholePath As String

    Call getextension(Me.lstboxProjectFiles)
    If getextension(Me.lstboxProjectFiles) = "nbp" Then
        Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe Me.ProjectPath" & "\" & Me.lstboxProjectFiles)
        
    ElseIf getextension(Me.lstboxProjectFiles) = "CMG" Then
        Shell ("c:\program files\01dB\01dB Software\dBBati32.exe Me.ProjectPath" & "\" & Me.lstboxProjectFiles)
        
    'ElseIf getextension(Me.lstboxProjectFiles) = "DWG" Or "DXF" Then
        'shell ("c:\program files
    Else
        
    Call GoHyperlink(Me.ProjectPath & "\" & Me.lstboxProjectFiles)
    'Application.FollowHyperlink Me.ProjectPath & "\" & Me.lstboxProjectFiles
    '    nDT = GetDesktopWindow()
     '   nApp = ShellExecute(nDT, "Open", Me.ProjectPath & "\" & Me.lstboxProjectFiles, "", "C:\", SW_SHOWNORMAL)
      '  DoEvents
    End If
End Sub
but that didn't work, so I tried putting the two Me.ProjectPath and Me.lstboxProjectFiles and the back slash into a single variable for simplicity when calling. As shown in the first code listing.

"Me.ProjectPath" is the path name for where the file is stored, not including a backslash or the file itself.

"Me.lstboxProjectFiles" is the listbox where all the filenames are shown and depending on the filename clicked, the file name will change

Edit:

I've also just tried this but to no avail:

Code:
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe Me.ProjectPath & chr(34)\chr(34) & Me.lstboxProjectFiles")
 
Last edited:
Simple Software Solutions

Is the basic concept of the form is to show a list of files in a listbox and let the user click on any file (whatever type) and get it to open in its native application.

For example if it a word doc it will open in word
if it is a pdf it will open in Adobe
if it is a txt fiel it will open wordpad
etc

if I am correct let me know as I have a perfect example for you.

CodeMaster::cool:
 
I think I've seen it, and maybe even tried it but I don't think it worked for my .nbp files.

But by all means I'm willing to give it a go if I haven't tried it.
 
Simple Software Solutions

What type of files are .nbp

David:cool:
 
Hi David,

They are a Norbuild file. The program is a dongle-protected one, but you might beable to download a demo version from here

It makes graphs for sound insulation tests (we're an acoustic consultancy)

I can open most files from a double-click in my listbox, but where there've been some non-normal file types, like this one, I've decided that shell is the most likely function to use. But i've only managed to open the program so far.

All I need is the correct syntax to open a file with the program using the shell function

cheers,

Si
 
Simple Software Solutions

Normally when using Shell if you add the file name to end of the shell command it will open it up. It looks like Norbuild does not support this functionality. I would suggest you contact the suppliers and see if they have a fix for it.

David
 
Ah ok, that is a shame, but I appreciate your help all the same. So it seems my syntax is correct then.

That's cool.

Thank you :)
 
Hi all, I have the following code:

Code:
Private Sub lstboxProjectFiles_DblClick(Cancel As Integer)
Dim strWholePath As String
 
    Call getextension(Me.lstboxProjectFiles)
    If getextension(Me.lstboxProjectFiles) = "nbp" Then
        strWholePath = Me.ProjectPath & "\" & Me.lstboxProjectFiles
        MsgBox "This is the data in strWholeFile ' " & strWholeFile & " ' ", vbOKOnly
        Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe & strWholePath")
 
    ElseIf getextension(Me.lstboxProjectFiles) = "CMG" Then
        strWholePath = Me.ProjectPath & "\" & Me.lstboxProjectFiles
        MsgBox "This is the data in strWholeFile ' " & strWholeFile & " ' ", vbOKOnly
        Shell ("c:\program files\01dB\01dB Software\dBBati32.exe  & strWholePath")
 
    'ElseIf getextension(Me.lstboxProjectFiles) = "DWG" Or "DXF" Then
        'shell ("c:\program files
    Else
 
    Call GoHyperlink(Me.ProjectPath & "\" & Me.lstboxProjectFiles)
    'Application.FollowHyperlink Me.ProjectPath & "\" & Me.lstboxProjectFiles
    '    nDT = GetDesktopWindow()
     '   nApp = ShellExecute(nDT, "Open", Me.ProjectPath & "\" & Me.lstboxProjectFiles, "", "C:\", SW_SHOWNORMAL)
      '  DoEvents
    End If
End Sub
Before you say anything about using an alternative, I need to use the shell command rather than application.hyperlink or shellExecute as these two commands don't work in a few of the cases. (I have tried :) )

Anyway, basically I am trying to open a program and file with it too. But all I can get at the moment is an open program.

Also,
For some reason, the message box for strWholeFile (only using a msgbox for debugging purposes) is returning nothing in the variable, so for some reason it's not getting information delivered into it, which is bizarre as it should be.

I'd appreciate your help, mainly with the syntax for Shell()

another version I'd tried was

Code:
Private Sub lstboxProjectFiles_DblClick(Cancel As Integer)
Dim strWholePath As String
 
    Call getextension(Me.lstboxProjectFiles)
    If getextension(Me.lstboxProjectFiles) = "nbp" Then
        Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe Me.ProjectPath" & "\" & Me.lstboxProjectFiles)
 
    ElseIf getextension(Me.lstboxProjectFiles) = "CMG" Then
        Shell ("c:\program files\01dB\01dB Software\dBBati32.exe Me.ProjectPath" & "\" & Me.lstboxProjectFiles)
 
    'ElseIf getextension(Me.lstboxProjectFiles) = "DWG" Or "DXF" Then
        'shell ("c:\program files
    Else
 
    Call GoHyperlink(Me.ProjectPath & "\" & Me.lstboxProjectFiles)
    'Application.FollowHyperlink Me.ProjectPath & "\" & Me.lstboxProjectFiles
    '    nDT = GetDesktopWindow()
     '   nApp = ShellExecute(nDT, "Open", Me.ProjectPath & "\" & Me.lstboxProjectFiles, "", "C:\", SW_SHOWNORMAL)
      '  DoEvents
    End If
End Sub
but that didn't work, so I tried putting the two Me.ProjectPath and Me.lstboxProjectFiles and the back slash into a single variable for simplicity when calling. As shown in the first code listing.

"Me.ProjectPath" is the path name for where the file is stored, not including a backslash or the file itself.

"Me.lstboxProjectFiles" is the listbox where all the filenames are shown and depending on the filename clicked, the file name will change

Edit:

I've also just tried this but to no avail:

Code:
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe Me.ProjectPath & chr(34)\chr(34) & Me.lstboxProjectFiles")

Take this line for instance

Code:
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe & strWholePath")

You are including strWholePath inside the literal string, so instead of trying to open the file name the program is trying to open a file called strWholePath.

Try

Code:
strWholePath = Chr$(34) & strWholePath & Chr$(34)
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe " & strWholePath)

You can leave out the double quotes if you already included them on the form.
 
Take this line for instance

Code:
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe & strWholePath")
You are including strWholePath inside the literal string, so instead of trying to open the file name the program is trying to open a file called strWholePath.

Try

Code:
strWholePath = Chr$(34) & strWholePath & Chr$(34)
Shell ("c:\Program Files\Norsonic\NorBuild\NorBuild.exe " & strWholePath)
You can leave out the double quotes if you already included them on the form.

Hi DJKarl,

Thanks for your post.

Before I attempt this, I'm confused as to why I'd have to do the first line in your code as I thought I was supposed to be making it equal to the other 3 bits (me.projectpath, "\", and me.lstboxprojectfiles)

Cheers,
Si
 
Ok I'm not sure what your list boxes store. From the name I'm guess one stores the path to where the file is, and the other store the file name.

So I assumed the variable strWholePath was the combination of all of these together.

strWholePath = me.projectpath & "\" & me.lstboxprojectfiles

If this is not the case then you just need to enclose the path and file name in double quotes. The reason you need to include the path in double quotes or Chr$(34), is in case the file path or name has any spaces in it. If it does the shell command will not work properly unless the path and file name are enclosed in quotes.
 
You did assume correctly, strWholePath was the combination of the 3 bits.

I get you now.

Thanks.
 
DJKarl,

I tried your method but it didn't work unfortunately, it still just opens the program without the file. It's a shame, cause double clicking the .nbp file from within windows explorer will open the file in the program.

It remains to me a mystery.

strWholePath is, however, returning the correct filepath and filename now though, so it must just not support opening the file via the shell function. ho hum.

I appreciate everyone's help with this one.
 
You say you can double click a file and it'd open the program?

If so, I'm pretty sure it should be able to do the same from a shell.

Try and fire up a shell, then type the command yourself- you can get feedback from the shell and see if there's anything that it is expecting?

Also, check your program's documentation to see if they support commandline options; in case of Access, we have to reference the application MSACCESS.exe first then supply a switch to direct which database it should open. It may be similar with this norbuild thingy.
 
Try and fire up a shell, then type the command yourself- you can get feedback from the shell and see if there's anything that it is expecting?

Sorry for being dumb here, but do you mean opening up a command prompt as in start -> run -> cmd ?

Thanks,

Si
 
Yes. (Sorry, I should be calling it cmd.exe, not shell.... too much UNIX. :o)

What you type in shell and works, will work in shell function.
 
Hi,

i had an issue similar to this thouh i was not trying to get it working in Access. the problem was a file type recognition. is the .ndp listed in the registry?

i had to associate my filetype in the registry so the file could push the program and vice versa. prior to this, i could only open the program then open the file.

i created a new key, then a new Key inside the key. mine was

HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.mcd\OpenWithList

so i went to
HKEY_CURRENT_USER\Microsoft\Windows\CurrentVersion\Explorer\FileExts\
Created a new key called .mcd
inside this key, created a new Key called OpenWithList
Inside this, created a string (Default)
Edited the Value Data to Vectorworks2008.exe which is the name of the program that opens the file. once this was done, worked perfectly.

might be your issue and its worth the check.

NS
 
Hi Neil,

I just went to my respective one, and there was more than 1 key value. There was "a" and "a"'s value was set to NorBuild.exe, but the value wasn't set for (default) so I edited it's value to be NorBuild.exe also.

I changed my code to use shellExecute() instead, and it seems to be liking it now!

the CMG file type's program (Dbbati32.exe) does not support opening a file like this, or even via explorer.

So There we go! I shall just have to modify everyone's registry when it comes to it.

Si
 
It was only a suggestion. it might not be the registry setting but then again it could have been. in any case, if you right click the registry key and select export, you can save it as a text file. you can then change its filetype from .txt to .reg. after that, if you double click the file, it will prompt for you to update the registry but i would only do that if you know what you are doing. this could be initiated i guess from within the Access environment.

also, if you have an installer like SageKey, you can edit the registry anyway to change or add if needed.

NS
 
In terms of registry editing, I have done this before and from what I have just done, it seems to have worked. :)

Oh, and Banana, we've gotta love UNIX/Linux. :D
 

Users who are viewing this thread

Back
Top Bottom