![]() |
Passing parameters between functions
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 -- Message posted from http://www.ExcelForum.com |
Passing parameters between functions
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. -- Regards, Tom Ogilvy Gaston wrote in message ... I'm trying to do a macro that'll get data from a spreadsheet and print 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 to output, but I don't know how I can pass in #1(the open text file) to these functions to let them be able to write to the file. I tried closing the file before running the function, and then within 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. --- Message posted from http://www.ExcelForum.com/ |
Passing parameters between functions
|
Passing parameters between functions
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 -- Message posted from http://www.ExcelForum.com |
Passing parameters between functions
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 -- Regards, Tom Ogilvy Gaston wrote in message ... 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 a function and change the values of all three... when i return to my main function... do the values of the changed integers remain the same? If not, how can I make the function do this? Thanks once again. --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 06:25 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com