PRB: No Trappable Error on Shell to Nonexistent .BAT FileID: Q118644
|
When you execute the Shell command to run a batch (.BAT) file, no error message is generated if the batch file specified does not exist.
The following is from the Help topic "Shell":
The Visual Basic Shell command runs an executable program. If the Shell() function successfully executes the named program, it returns the instance handle of the started program. If the Shell() function can't start the named program, an error occurs.
Cannot find file.
Check to make sure the path and filename are correct.
This is by design and is the same behavior you see when using the Windows
API WinExec. "Shelling" to a batch program generates a handle to the
command processor, which runs the batch program. This handle is returned to
Visual Basic. When the command processor determines that there is no such
batch file, it is a process independent from Visual Basic and the error is
therefore not reported to Visual Basic.
Sub Form_Click()
Dim X As Integer
X = Shell((Text1.Text))
Print X, Err
'returns a valid process handle in x and err = 0
End Sub
Sub Form_Click()
Dim X As Integer
If Len(Dir((Text1.Text))) > 0 Then
X = Shell((Text1.Text))
Print X, Err
'returns a valid process handle in x and err = 0
Else
MsgBox "No such file exists."
End If
End Sub
Additional query words: 2.00 3.00
Keywords :
Version :
Platform :
Issue type :
Last Reviewed: June 25, 1999