open file for append and pass file on

S

Sjef

I am opening a textfile for append (open Filename for append as #textfile). I
understand that #textfile is a number reference to the file opened.
I want to pass the opened file to a function, while it is still open, so I
can write to it inside the function. Something like:
private function functionname(textfile as ...) as boolean
print textfile, "text goes here
end function
Is this possible. What's the datatype of the parameter,...
Thanks, Sjef
 
S

Sjef

OK, I found out that I should close the textfile and reopen it over and over
again. Then there is no problem.
Sjef
 
S

Steve Rindsberg

I am opening a textfile for append (open Filename for append as #textfile). I
understand that #textfile is a number reference to the file opened.
I want to pass the opened file to a function, while it is still open, so I
can write to it inside the function. Something like:
private function functionname(textfile as ...) as boolean
print textfile, "text goes here
end function
Is this possible. What's the datatype of the parameter,...
Thanks, Sjef

It seems to work fine like so:

Sub OpenFile()

Dim iFileNum As Integer

iFileNum = FreeFile()
Open "C:\Temp\TestFile.TXT" For Append As iFileNum
Print #iFileNum, "Written by OpenFile"

Call AppendToFile(iFileNum, "Appended by AppendToFile")

Close iFileNum

End Sub

Function AppendToFile(iFileNum As Integer, sStringToAppend As String)

Print #iFileNum, sStringToAppend

End Function
 
K

Karl E. Peterson

Sjef said:
OK, I found out that I should close the textfile and reopen it over
and over again. Then there is no problem.

That's highly inefficient. Do as Steve suggests, and pass the file handle rather
than the filename to the function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top