[RESOLVED] Delete a file using VB?
I'm trying to delete a reusable file in a VB6 app. This file is for importing information into a seperate Access DB and will be used multiple times. Should I delete it using the kill command like this(which doesn't work right now)-
Pathway = App.Path
FullPath = Pathway & "\ImportFile.txt"
If FullPath <> 0 Then
Kill FullPath
End If
Or should I just overwrite the data in the file(which I doon't know how to do).
John
Re: Delete a file using VB?
Kill will not work if the file is open, and that may be your problem, although in order for me to be certain, you would have to tell me what "which doesn't work right now" means? Are you getting an error message? If so, what?
If you open a file for Output it will delete the entire contents of the file as soon as it is open
VB Code:
Open "c:\ImportFile.txt" For Output As #1
Re: Delete a file using VB?
It doesn't give an error at all. It just parses through the line and stops the entire operation dead in its tracks.
The export routine uses Append to write individual lines in a comma delineated format, so would I use the output operator and then put the append inside a loop?
This is the append operation that I use right now. I think you may have given it to me...
Do While last_rcd = 0
Remarks = Form2.Text1
Open App.Path & "\ImportFile.txt" For Append As #ff
Write #ff, , Form1.idboxes(0), Form1.fieldboxes(0), Form1.fieldboxes(1), _
Form1.fieldboxes(2), Form1.fieldboxes(4), Form1.fieldboxes(43), , _
Form1.fieldboxes(47), Form1.fieldboxes(48), , Form1.fieldboxes(34), _
Form1.fieldboxes(35), Form5.F3(27), , , Remarks, , Form1.fieldboxes(25), _
Form1.fieldboxes(30),
Close #ff
NextBut_click
Loop
The NextBut_click command moves the loop to the next record in the file to be read(it will skip over records not used)
Thanks!
John
Re: Delete a file using VB?
Hey I figured it out! I open and close it before the loop to clear the contents then append as needed inside the loop like this -
ff = FreeFile
Open App.Path & "\ImportFile.txt" For Output As #ff
Close #ff
Do While last_rcd = 0
Remarks = Form2.Text1
Open App.Path & "\ImportFile.txt" For Append As #ff
Write #ff, , Form1.idboxes(0), Form1.fieldboxes(0), Form1.fieldboxes(1), _
Form1.fieldboxes(2), Form1.fieldboxes(4), Form1.fieldboxes(43), , _
Form1.fieldboxes(47), Form1.fieldboxes(48), , Form1.fieldboxes(34), _
Form1.fieldboxes(35), Form5.F3(27), , , Remarks, , Form1.fieldboxes(25), _
Form1.fieldboxes(30),
Close #ff
NextBut_click
Loop
Thanks a bunch!
John