Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i leave a open file open?

Status
Not open for further replies.

Gti

Programmer
Jul 23, 2001
99
PT
How can i open a file in a function and print someting in other function?
What i mean is this... is leave the open file for ever... anda just close it in the end!
:eek:)
 
My purpose is to write in the same line many things... through a cycle. So if i open the file every time i pass it will write in another line instead of writing it in front of the line :0)
 
Hi,

The file won't close until you close it!
Open your file when your writing begins.
Do all your writing to the file.
Close the file when you're finished.

it could look like
-----------------------------------------------------
Dim OutFile as byte
private sub WriteMyThings

outfile=freefile
open "c:\tmp\text.txt" for output at #outfile
DoTheWriting
close #outfile
end sub

private sub DoTheWriting
'Loop as many times as you like and write to the file.
print #outfile,"Hello"
end sub
-----------------------------------------------------------

If you don't know when you'll be writing to the file (because it depends on user input), you could open the file in the load event and close it in the unload event, but I would recomment to pick up the values in an array and write everything in the unoad event, so you don't have to have the file open all the time.

Sunaj

 
Sorry Sunaj, but maybe i don't me explain well.
What i need is:

print #outfile,"Hello" -> the "Hello" recibes diferent's strings and i need to put in the same line.
 
Ohh, sorry.

There's 2 ways of doing that:
1) get your strings before you write then to the file:
print #outfile, My1Str & My2Str & ....

2) Open the file for binary and use put to write to the file
Open "c:\tmp\text.txt" for binary as #outfile
put #outfile,,"hello, "
put #outfile,,"my name is sunaj"
close #outfile

would produce a file with one line: "hello, my name is sunaj"

Sunaj

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top