473,809 Members | 2,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9170
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*********@hot mail.com
http://amazecreations.com/datafast
"MLH" <CR**@NorthStat e.net> wrote in message news:as******** *************** *********@4ax.c om...
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*********@ho tmail.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")

xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx xxxxx
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:\MyF ile.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**@NorthStat e.net> wrote in message
news:as******** *************** *********@4ax.c om...
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.
xxxxxxxxxxxxxxx xxxxxxxxxxx
Opening a file As #1 isn't good programming practice!

Dim intFile As Integer

If Len(Dir("c:\MyF ile.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
3051
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 = _ ExportOptions.CreatePdfRtfWordFormatOptions() Dim MailOptions As MicrosoftMailDestinationOptions = _ ExportOptions.CreateMicrosoftMailDestinationOptions() Dim exportOpts As ExportOptions = New ExportOptions
8
2492
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 problems resulting from IIS 6 prohibiting ASP and SSI etc, but I've hit a peculiar wall. One ASP page uses a VB6 COM object that basically reads from an .INI file and uses it to open another file. The existing code uses this line (in VB6) to do this:...
0
1157
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 C# project. I simply want to generate the corresponding ".resources" file containing my strings (for all localized ".txt" files) but can't figure out where to add the call to "ResGen.exe". Can someone fill me in. Thanks.
1
2375
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 ".txt" file directly. Thanks.in advance.
3
5899
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
1944
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 read "robots.txt" URLs. If the server asks for basic authentication on that file, "robotparser" prompts for the password on standard input. Which is rarely what you want. You can demonstrate this with: import robotparser
5
2341
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 Disallow: /account/myint ...
2
2628
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 unknown browsers. But the Python parser doesn't see it that way. No matter what user agent or URL is specified; for that robots.txt file, the only answer is "False". It's failing in Python 2.4 on Windows and 2.5 on Fedora Core.
2
1704
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 of seats column where when i check the status of that particulat bus no 4324 it is displaying that the "seat is not available" and "available seats are 0" In this code snippet i i face the above problem in the "temp" variable. please help me out.
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7660
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.