-
Apr 6th, 2016, 03:47 AM
#1
Thread Starter
New Member
Shell function syntax
Hi
I've done a forum search on this problem but no-one else seems to be having it. I have the following code
Dim retVal
retVal = Shell("C:\Readmems.exe", 1)
But when I try and run the host program (And note that C:\Readmems.exe does exist) I just get the error
"wrong number of arguments or invalid property assignment"
What am I doing wrong ?
-
Apr 6th, 2016, 03:59 AM
#2
Re: Shell function syntax
Are you really using VB6?
When running your sample directly from the IDE
Code:
Private Sub Form_Load()
Dim retVal
retVal = Shell("C:\Readmems.exe", 1)
End Sub
Gives the following error:
Code:
Run-time error '53':
File not found
[Continue] [End] [Debug] [Help]
-
Apr 6th, 2016, 04:23 AM
#3
Thread Starter
New Member
Re: Shell function syntax
Originally Posted by Arnoutdv
Are you really using VB6?
Afraid so Up to now it has done everything I wanted so I didn't bother upgrading.
What I have done is put a button (Called 'Shell') on my form and the full code is:
Private Sub Shell_Click()
Dim retVal
retVal = Shell("""C:\Readmems.exe""")
End Sub
And I get that error.
Just in case I tried it in Form_Load() but still got the same error
-
Apr 6th, 2016, 04:36 AM
#4
Member
Re: Shell function syntax
Hello, Why do you not use ShellExecute ?
Code:
ShellExecute (0, "Open", "C:\Readmems.exe", vbnullstring,vbnullstring,10)
Last edited by christ62; Apr 6th, 2016 at 04:40 AM.
-
Apr 6th, 2016, 04:37 AM
#5
Re: Shell function syntax
Is it possible you have a function that is also named Shell? VB allows this, and I was able to reproduce your error like this:
Code:
Private Function Shell(a As String, b As Long, c As Long) As Long
MsgBox "shelled"
End Function
Private Sub Command8_Click()
Shell "C:\test.exe", 2, 3, 4
End Sub
Edit: Also I agree with the above poster that you should just switch to ShellExecute (or ShellExecuteEx), since VB's Shell has some issues on newer Windows versions (not the type that would cause your error here though)
Public 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
Last edited by fafalone; Apr 6th, 2016 at 04:41 AM.
-
Apr 6th, 2016, 04:55 AM
#6
Re: Shell function syntax
The problem is that your command button is named "Shell" like the Shell function you want to call!
Code:
Private Sub Shell_Click()
Dim retVal
retVal = Shell("""C:\Readmems.exe""", 1)
End Sub
-
Apr 6th, 2016, 07:07 AM
#7
Thread Starter
New Member
Re: Shell function syntax
Originally Posted by Arnoutdv
The problem is that your command button is named "Shell" like the Shell function you want to call!
Code:
Private Sub Shell_Click()
Dim retVal
retVal = Shell("""C:\Readmems.exe""", 1)
End Sub
Oh, for goodness sake, how did I miss that ? I will crawl into a corner, assume the foetal position and suck my thumb.
My only excuse is the quote "The only stupid question is the one you don't ask".
Many thanks, although I will take the advice and start trying ShellExecute.
Cheers
Al
-
Apr 6th, 2016, 09:13 AM
#8
Re: Shell function syntax
I would also suggest that you properly dim retval rather than letting it default to a variant.
-
Apr 6th, 2016, 10:42 PM
#9
Re: Shell function syntax
Also I am nervous about doing some things in Form_Load
I usually do them in Form_Activate, and have a flag to ensure they only happen once
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|