Passing parameters between functions

  • Thread starter Thread starter Gaston
  • Start date Start date
G

Gaston

I'm trying to do a macro that'll get data from a spreadsheet and prin
it out to a txt file. I use the following:

Open "test.txt" For Output As #1
'some code
Write #1, "This is some test data"
'more code
Close #1

My problem is that I've written a few functions to write more data t
output, but I don't know how I can pass in #1(the open text file) t
these functions to let them be able to write to the file.

I tried closing the file before running the function, and then withi
the function using the following:
Open "test.txt" For Append As #1
But that does nothing. Anybody know how I can do it then?
Thanks in advanced
 
Dim fnum as Integer
fnum = freefile
Open "test.txt" For Output As #fnum
'some code
Write #fnum, "This is some test data"
mySpecialFunction fnum
'more code
Close #fnum



Sub myspecialfunction( fnum as integer)

Write #fnum, "this is another line

End Sub

---- from help on freefile - - - -

Returns an Integer representing the next file number available for use by
the Open statement.
 
Sorry to bother you guys again, but another question has popped up
Simple one, but I'm just wondering, if I pass 3 integers into
function and change the values of all three... when i return to my mai
function... do the values of the changed integers remain the same? I
not, how can I make the function do this?
Thanks once again
 
If you pass them byRef, then if you change them in the function they are
changed in the calling routine. If you pass them byVal then they are not.
byRef is the default and if you don't specify byVal specifically, then they
are passed byRef.

Sub Macro1()
A = 1
B = 2
C = 3
MsgBox "A=" & A & vbNewLine & _
"B=" & B & vbNewLine & _
"C=" & C & vbNewLine

Macro2 A, B, C
MsgBox "A=" & A & vbNewLine & _
"B=" & B & vbNewLine & _
"C=" & C & vbNewLine
End Sub

Sub Macro2(AA, BB, CC)
AA = AA + 10
BB = BB / CC
CC = CC / BB
End Sub

as an example
 
Back
Top