Kill command button!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Kill command button!!!

allgameplayaallgameplaya Posts: 3Member
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.


Comments

  • MFHMFH Posts: 56Member
    : 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...
  • iKinjaliKinjal Posts: 1Member
    : 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:WindowsTemp 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"

    :
    :

  • allgameplayaallgameplaya Posts: 3Member
    : : 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!!

  • infidelinfidel Posts: 2,900Member
    : : 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".


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • allgameplayaallgameplaya Posts: 3Member
    : : : 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".
    :
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :
    : [code]
    : $ select * from users where clue > 0
    : no rows returned
    : [/code]
    :
    :

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

  • BitByBit_ThorBitByBit_Thor Posts: 2,444Member
    :
    : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    :

    You crack me up!

    Greets...
    Richard

  • MicroDotMicroDot Posts: 142Member
    : : : : 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".
    : :
    : :
    : : [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]
    : :
    : : [code]
    : : $ select * from users where clue > 0
    : : no rows returned
    : : [/code]
    : :
    : :
    :
    : 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?


    [hr]

    [b][blue]//MicroDot[/blue][/b]

  • jagd_tysonhjagd_tysonh Posts: 8Member
    : : 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"
  • rhenerlaurhenerlau Posts: 3Member
    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.

Sign In or Register to comment.