Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Sub calling and passing arguments

I am trying to call a sub within another sub, i'll refer to the main
sub as sub1 and the sub within that as sub2. I want sub2 to perform a
calculation and find result X. How do I then use X in sub1? why is X
not available to sub1?

thanks,
Jacob

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 415
Default Sub calling and passing arguments

Jacob,
Maybe you should read the replies to your previous post before posting
again.

NickHK

"Jacob"
egroups.com...
I am trying to call a sub within another sub, i'll refer to the main
sub as sub1 and the sub within that as sub2. I want sub2 to perform a
calculation and find result X. How do I then use X in sub1? why is X
not available to sub1?

thanks,
Jacob



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Sub calling and passing arguments

Jacob -

By definition, a sub does not return a value. For that use a function.

However, you can get around this by having a sub which fills in the value as
in the following:


Sub sub1()
Dim x As Integer

x = 1

sub2 x

MsgBox x
End Sub

Sub sub2(x As Integer)
x = x+1
End Sub


What value would you expect to be on the messagebox. It is actually 2. You
could achieve the same effect this way also:

Sub sub1()
Dim x As Integer
Dim y As Integer

x = 1

y = func1(x)

MsgBox y
End Sub

Function func1(x As Integer) As Integer
func1 = x + 1
End Function

Hope that clarifies things.

ct60



"Jacob" wrote:

I am trying to call a sub within another sub, i'll refer to the main
sub as sub1 and the sub within that as sub2. I want sub2 to perform a
calculation and find result X. How do I then use X in sub1? why is X
not available to sub1?

thanks,
Jacob


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 Arguments in Excell UB Excel Worksheet Functions 3 February 13th 07 04:08 PM
Passing arguments from VBA to DLL [email protected] Excel Programming 10 August 18th 06 09:08 AM
Passing arguments to VB Function Tom Excel Programming 1 March 29th 06 01:19 AM
Passing Arguments Grant Reid Excel Programming 8 May 24th 04 01:39 PM
Passing arguments to a sub routine... Jeff Harbin[_2_] Excel Programming 2 January 29th 04 03:25 AM


All times are GMT +1. The time now is 12:07 PM.

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

About Us

"It's about Microsoft Excel"