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! )
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)
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.
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"
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.