Friday, March 16, 2012

Delete A File - Snippet

Below is a very small VB6 code snippet. It allows you to delete a file from the hard drive. To try out this Visual Basic code snippet first go to your hard drive and create a new text file on the C drive. Call the file test.txt and fill it with some junk data. Now create a new Visual Basic program. On the main form add a command button. Double click the command button to get to the click event code. Add the following inside the click event handler

Answer = MsgBox("Are you sure you want to delete " & Filename, vbYesNo)

Obviously in a real world application you would not hard code in the file name but for simplicity sake we did so here. They key to getting rid of the file is the Kill Filename command. This is left over from the old original dos days but it still works today.

This was a very basic example to give you a taste of what VB6 allows you to do in relation to File handling. We also have a whole list of VB6 File Handling Tutorials located on this site. Feel free to check them out to learn much more about dealing with files in VB.

Note: The source for this was found at DreamVB which is no longer online.


View the original article here

No comments:

Post a Comment