Public Group

#### Archived

This topic is now archived and is closed to further replies.

# vb question

This topic is 5414 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is there a way in vb6 to create or delete text files? If so please tell me.. thanks.

##### Share on other sites
There is actually several ways of doing this. The most common way is by using the File System Object containted in the MS Scripting DLL - check the MSDN for more details.

Otherwise the most simplest form is by calling the kill() function to delete files and to create them use
open "C:\mytextfile.txt" for output as #1close #1

I think thats how you do it from memory

Extracting Patch....
Initializing Windows XP Update Path 2543663B....
Core Dumped, Now Installing Linux.....

----
Mike
Team AI: Http://members.iinet.net.au/~slyons/teamai

[edited by - Mike737 on August 18, 2003 2:56:56 AM]

##### Share on other sites
ooohh same as BASIC..ty

##### Share on other sites
You should never hard-code the file handle. Try:

Dim iFile As Integer

iFile = FreeFile

Substitute iFile for the two places where the handle is hard-coded. The FreeFile function ensure you get a valid handle.

##### Share on other sites
Yeah... here''s the basics:

to Write to a file:

ff=FreeFile
Open "C:\happy.abc" for output as ff
Write ff, StringThatIWantToWrite
Close ff

to Read a file(note, this only works for the 1st line, cant remember how to read the entire file without repeating the Input line):

ff=FreeFile
Open "C:\happy.abc" for input as ff
Input ff, StringThatIWantToFill
Close ff

And alas, to destroy a file:

Kill "C:\happy.abc"

##### Share on other sites
Yeah... here''s the basics:

to Write to a file:

ff=FreeFile
Open "C:\happy.abc" for output as ff
Write ff, StringThatIWantToWrite
Close ff

to Read a file(note, this only works for the 1st line, cant remember how to read the entire file without repeating the Input line):

ff=FreeFile
Open "C:\happy.abc" for input as ff
Input ff, StringThatIWantToFill
Close ff

And alas, to destroy a file:

Kill "C:\happy.abc"

##### Share on other sites
To read in a file to an array you might use this:

(Modifying Quantum''s code)

ff=FreeFile
Open "C:\happy.abc" for input as ff
While NOT EOF(ff)
Redim Preserve myArray(j)
Input ff, myArray(j)
j=j+1
Wend
Close ff

• 33
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631354
• Total Posts
2999491
×