Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Clear txt file?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2003, 08:28 PM
Latac Latac is offline
Restricted
 
Join Date: Aug 2003
Posts: 218
Default Clear txt file?


Is there a command that deletes all text of Input #1..

all text in the opened txt file.


thx!
Reply With Quote
  #2  
Old 09-14-2003, 08:36 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

What you can do is to Kill the existing file, open a new file with the same name, and then close it without placing any data into it. This will in effect provide you with an empty file with the same name that was previously used.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #3  
Old 09-14-2003, 08:56 PM
Latac Latac is offline
Restricted
 
Join Date: Aug 2003
Posts: 218
Default

I gave it a shot.. lol i'm confused.. and think I put wrong thing 100%

lol heres my code:

Code:
Private Sub Timer1_Timer() Dim size As String Dim Openf As String ' determin if it has text in it. size = "F:\file.txt" Label1.Caption = FileLen(size) If Label1.Caption > 0 Then Open Text1.Text For Input As #1 Input #1, Openf Label2.Caption = Openf Close #1 Open Text1.Text For Input As #1 Close #1 End If End Sub
Reply With Quote
  #4  
Old 09-14-2003, 09:27 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

I don't see where you are using the Kill() method to destroy the existing file before recreating the file without placing any input into it.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #5  
Old 09-14-2003, 09:31 PM
Latac Latac is offline
Restricted
 
Join Date: Aug 2003
Posts: 218
Default

didn't know you ment the kill function.. i thought you ment kill as in close. 0_0
Reply With Quote
  #6  
Old 09-14-2003, 09:33 PM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

If the file was previously opened, you will need to close it before killing it.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #7  
Old 09-14-2003, 09:36 PM
Latac Latac is offline
Restricted
 
Join Date: Aug 2003
Posts: 218
Default

Thanks.

Last edited by Latac; 09-14-2003 at 09:42 PM.
Reply With Quote
  #8  
Old 09-14-2003, 09:54 PM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,919
Default

You can save yourself a step, since you want an empty file, you don't
have to kill the existing file.

When I use binary files, I often need to "empty" the existing file before
updating, so just open the file for output and then close it, it will be
empty.

Open "c:\trial.txt" For Output As #1
Close #1

trial.txt will now be empty, no need to kill it first. Another advantage,
you don't need to check if it exists before you try to kill it.
If it doesn't exist, it will be created, and if it does exist, it will be
emptied.
Reply With Quote
  #9  
Old 09-15-2003, 10:37 AM
Latac Latac is offline
Restricted
 
Join Date: Aug 2003
Posts: 218
Default

ooooh cool thanks everyone.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installation Problem - PLs help urgenlty dpdsouza Installation / Documentation 4 12-02-2004 08:09 PM
Doesn't want to register! MikeyM Installation / Documentation 5 03-02-2003 09:22 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->