473,425 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Delete existing before running Open "c:\MyFile.txt" For Output As #1 ?

MLH
Is it good programming practice to delete existing file before running
Open "c:\MyFile.txt" For Output As #1 ???

IE, I already have a file c:\MyFile.txt on disk and I launch
Open "c:\MyFile.txt" For Output As #1 ==> VBA is supposed to
overwrite whatever WAS there with the new contents - right? And
if that is true, does it matter whether I delete the existing file
prior to running the Open statement?
Dec 13 '05 #1
4 9146
I generally like to clean up, either before a process or after it ends,
for files that are disposable. Try something like this ...

If Dir("c:\MyFile.txt") <> "" Then Kill("c:\MyFile.txt")

--

Danny J. Lesandrini
dl*********@hotmail.com
http://amazecreations.com/datafast
"MLH" <CR**@NorthState.net> wrote in message news:as********************************@4ax.com...
Is it good programming practice to delete existing file before running
Open "c:\MyFile.txt" For Output As #1 ???

IE, I already have a file c:\MyFile.txt on disk and I launch
Open "c:\MyFile.txt" For Output As #1 ==> VBA is supposed to
overwrite whatever WAS there with the new contents - right? And
if that is true, does it matter whether I delete the existing file
prior to running the Open statement?

Dec 13 '05 #2
MLH
On Tue, 13 Dec 2005 11:01:36 -0700, "Danny J. Lesandrini"
<dl*********@hotmail.com> wrote:
I generally like to clean up, either before a process or after it ends,
for files that are disposable. Try something like this ...

If Dir("c:\MyFile.txt") <> "" Then Kill("c:\MyFile.txt")

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Yep. That's good practice.
Dec 13 '05 #3
Opening a file As #1 isn't good programming practice!

Dim intFile As Integer

If Len(Dir("c:\MyFile.txt")) > 0 Then
Kill "c:\MyFile.txt"
End If

intFile = FreeFile()
Open "c:\MyFile.txt" For Output As #intFile

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"MLH" <CR**@NorthState.net> wrote in message
news:as********************************@4ax.com...
Is it good programming practice to delete existing file before running
Open "c:\MyFile.txt" For Output As #1 ???

IE, I already have a file c:\MyFile.txt on disk and I launch
Open "c:\MyFile.txt" For Output As #1 ==> VBA is supposed to
overwrite whatever WAS there with the new contents - right? And
if that is true, does it matter whether I delete the existing file
prior to running the Open statement?

Dec 13 '05 #4
MLH
Good point. I agree.
xxxxxxxxxxxxxxxxxxxxxxxxxx
Opening a file As #1 isn't good programming practice!

Dim intFile As Integer

If Len(Dir("c:\MyFile.txt")) > 0 Then
Kill "c:\MyFile.txt"
End If

intFile = FreeFile()
Open "c:\MyFile.txt" For Output As #intFile


Dec 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Matthias Haberkorn | last post by:
Hello, I haved used VS2003 and send some Reports as EMail attachmend with vb.net. The code looks like this: Dim pdfOpts As PdfRtfWordFormatOptions = _...
8
by: Seth Darr | last post by:
I'm working on migrating an Classic ASP/VB6 COM application from an NT Server with IIS<6 to an virtual machine running Windows Server 2003 and IIS 6. I've worked through most of the obvious...
0
by: John Appleby | last post by:
Hi there, I've been searching high and low for instructions on where to add the command to launch "ResGen.exe" in Visual Studio in order to compile a ".txt" based resources file I've added to my...
1
by: John Layton | last post by:
Hi there, Does anyone know if there's a built-in way to read a ".txt" based resources file (one that's converted to a ".resources" file by "resgen.exe" at build time). I need to read/write the...
3
by: John Torville | last post by:
Hi there, Does anyone know how to add ".txt" resources file to a C# project in Visual Studio. It should compile down to an embedded ".resources" file the same way as a ".resx" file. Thanks.
5
by: John Nagle | last post by:
This bug, " robotparser interactively prompts for username and password", has been open since 2003. It killed a big batch job of ours last night. Module "robotparser" naively uses "urlopen" to...
5
by: John Nagle | last post by:
Python's "robots.txt" file parser may be misinterpreting a special case. Given a robots.txt file like this: User-agent: * Disallow: // Disallow: /account/registration Disallow: /account/mypro...
2
by: John Nagle | last post by:
For some reason, Python's parser for "robots.txt" files doesn't like Wikipedia's "robots.txt" file: False The Wikipedia robots.txt file passes robots.txt validation, and it doesn't disallow...
2
by: ishakarthika | last post by:
i have a .txt file which contains line of string like the below format |111|34 sdddd| ppppp| A/C| 32| sadfd| |4324|23 mmm| yyyyy| A/C|32| fdfffdfd| the sixth column is the no...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.