Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing parameters between functions

Thanks, that solves my problems

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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/





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters Cel Ref) to Sum function Shamshad Butt Excel Discussion (Misc queries) 4 October 26th 05 10:46 AM
Passing parameters Eleanor[_2_] Excel Programming 0 February 4th 04 05:21 PM
Passing parameters to UDF mbobro[_3_] Excel Programming 5 January 2nd 04 04:25 PM
Passing Parameters to Userdefined Functions Peter M[_3_] Excel Programming 3 December 13th 03 07:56 PM
Passing Parameters through OnAction Mark Bigelow Excel Programming 3 September 10th 03 12:53 AM


All times are GMT +1. The time now is 02:40 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"