Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 18013
Number of posts: 55386

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Kill command button!!! Posted by allgameplaya on 15 Jun 2005 at 3:05 PM
I'm trying to create a button on vb 6 and everytime I click on it, it deletes the file, but if I click on it a second time, it gives me an error 53 saying "file not found". Does any1 know a code to fix this?
-------------------------------------------------------------------------------------
Here's the code im using:

Private Sub Command2_Click()
Kill "C:/WINDOWS/Temp/"
End Sub

-------------------------------------------------------------------------------------
Tnx.


Report
Re: Kill command button!!! Posted by MFH on 16 Jun 2005 at 4:03 AM
: Private Sub Command2_Click()
: Kill "C:/WINDOWS/Temp/"
: End Sub

I'm not sure, but maybe this code kills the directory, or what's in it, and then there is nothing more to kill, so it generates an error.

If the problem is that, you have to insert a code that controls if there is a directory with that name, or if the directory is not empty.

If that doesn't work try with

Private Sub Command2_Click()
On Error GoTo EndOfSub
Kill "C:/WINDOWS/Temp/"
EndOfSub:
End Sub

It's not so elegant, but better than nothing...
Report
Re: Kill command button!!! Posted by allgameplaya on 16 Jun 2005 at 12:05 PM
: : Private Sub Command2_Click()
: : Kill "C:/WINDOWS/Temp/"
: : End Sub
:
: I'm not sure, but maybe this code kills the directory, or what's in it, and then there is nothing more to kill, so it generates an error.
:
: If the problem is that, you have to insert a code that controls if there is a directory with that name, or if the directory is not empty.
:
: If that doesn't work try with
:
: Private Sub Command2_Click()
: On Error GoTo EndOfSub
: Kill "C:/WINDOWS/Temp/"
: EndOfSub:
: End Sub
:
: It's not so elegant, but better than nothing...
:

Tnx. this solved the problem. Ur the best!!

Report
Re: Kill command button!!! Posted by infidel on 16 Jun 2005 at 1:41 PM
: : Private Sub Command2_Click()
: : On Error GoTo EndOfSub
: : Kill "C:/WINDOWS/Temp/"
: : EndOfSub:
: : End Sub
: :
: : It's not so elegant, but better than nothing...
: :
:
: Tnx. this solved the problem. Ur the best!!

Technically it just ignores the "problem".


infidel

$ select * from users where clue > 0
no rows returned


Report
Re: Kill command button!!! Posted by allgameplaya on 16 Jun 2005 at 2:16 PM
: : : Private Sub Command2_Click()
: : : On Error GoTo EndOfSub
: : : Kill "C:/WINDOWS/Temp/"
: : : EndOfSub:
: : : End Sub
: : :
: : : It's not so elegant, but better than nothing...
: : :
: :
: : Tnx. this solved the problem. Ur the best!!
:
: Technically it just ignores the "problem".
:
:
: infidel
:
:
: $ select * from users where clue > 0
: no rows returned
: 

:
:

Ya ur right but as long as it doesnt mess with my program is ok with me. =)

Report
Re: Kill command button!!! Posted by MicroDot on 22 Jun 2005 at 11:55 PM
: : : : Private Sub Command2_Click()
: : : : On Error GoTo EndOfSub
: : : : Kill "C:/WINDOWS/Temp/"
: : : : EndOfSub:
: : : : End Sub
: : : :
: : : : It's not so elegant, but better than nothing...
: : : :
: : :
: : : Tnx. this solved the problem. Ur the best!!
: :
: : Technically it just ignores the "problem".
: :
: :
: : infidel
: :
: :
: : $ select * from users where clue > 0
: : no rows returned
: : 

: :
: :
:
: Ya ur right but as long as it doesnt mess with my program is ok with me. =)
:
:

Then why not just check if directory exist before killing it?
Like with "Dir" maybe?





//MicroDot

Report
Re: Kill command button!!! Posted by BitByBit_Thor on 18 Jun 2005 at 7:57 AM
:
: infidel
:

You crack me up!

Greets...
Richard

Report
Re: Kill command button!!! Posted by jagd_tysonh on 24 Jun 2005 at 9:31 AM
: : Private Sub Command2_Click()
: : Kill "C:/WINDOWS/Temp/"
: : End Sub
:
: I'm not sure, but maybe this code kills the directory, or what's in it, and then there is nothing more to kill, so it generates an error.
:
: If the problem is that, you have to insert a code that controls if there is a directory with that name, or if the directory is not empty.
:
: If that doesn't work try with
:
: Private Sub Command2_Click()
: On Error GoTo EndOfSub
: Kill "C:/WINDOWS/Temp/"
: EndOfSub:
: End Sub
:
: It's not so elegant, but better than nothing...
:

lol....
the only way you could hack this code worse is by using "on error resume next"
Report
Re: Kill command button!!! Posted by iKinjal on 16 Jun 2005 at 6:17 AM
: I'm trying to create a button on vb 6 and everytime I click on it, it deletes the file, but if I click on it a second time, it gives me an error 53 saying "file not found". Does any1 know a code to fix this?
: -------------------------------------------------------------------------------------
: Here's the code im using:
:
: Private Sub Command2_Click()
: Kill "C:/WINDOWS/Temp/"
: End Sub
:
: -------------------------------------------------------------------------------------
: Tnx.
:

I understand the following from your message:
If C:\Windows\Temp\ does not exist, you get an error message, telling you that it is not there.
To get rid of this problem, add the following code to the first line to the Sub-procedure:
On Error Resume Next

What this does is tell the compiler to ignore the error and simply go to the next line of code. To learn more about this, see help on the Internet about "Error handling"

:
:

Report
Re: Kill command button!!! Posted by rhenerlau on 27 Aug 2005 at 4:11 PM
If FileExists (file you are trying to kill) then

(do the kill Code)

- else: exit sub

End If

You might check the exact syntax for the FileExists command.

Hope this helps!

Richard

: Here's the code im using:
:
: Private Sub Command2_Click()
: Kill "C:/WINDOWS/Temp/"
: End Sub
: Tnx.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.