Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Kill statement in debug mode

Status
Not open for further replies.

patelr

Programmer
Oct 10, 2002
17
CH
I am trying to use KILL statement/function in VB 6, but error trapping not working. file is not on the system. Code is failing in Debug mode with error code 53 as expected and I can't get pass the kill statement/function. Any pointers???

snippet of the code

Private Sub Command1_Click()

Dim xyz As String

On Error Resume Next

xyz = "c:\xyzxyzx.tif"
Kill (xyz)

On Error GoTo 0

End Sub


Thanks in advance.
 
You should check to make sure that the file exists before you try to use the kill statement.

xyz = "c:\xyzxyzx.tif"
If Dir$(xyz) <> &quot;&quot; Then Kill xyz
Thanks and Good Luck!

zemp
 
Thats fine, but shouldn't you be able to use error handling to by-pass such error.
 


Debugging Code with Error Handlers

When you are debugging code, you may find it confusing to analyze its behavior when it generates errors that are trapped by an error handler. You could comment out the On Error line in each module in the project, but this is also cumbersome.

Instead, while debugging, you could turn off error handlers so that every time there's an error, you enter break mode.

To disable error handlers while debugging

From the Code window context menu (available by right-clicking on the Code window), choose Toggle.


Select the Break on All Errors option.
With this option selected, when an error occurs anywhere in the project, you will enter break mode and the Code window will display the code where the error occurred.

If this option is not selected, an error may or may not cause an error message to be displayed, depending on where the error occurred. For example, it may have been raised by an external object referenced by your application. If it does display a message, it may be meaningless, depending on where the error originated.

 
Nothing wrong with this code, error must be elsewhere.

Although there is an inherent problem you should check specifically for errors 0 and 53, you may not be able to delete the file for other reasons even if it exists - such as already open, read only or insufficient permissions.

...
Kill(xyz)
If Not (Err.Number = 0 Or Err.Number = 53) Then
MsgBox &quot;Cannot delete file&quot;
.....
End If

Hope this helps
cjw

 
I have resolved the problem, please see my earlier reply to this thread.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top