Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Passing Arguments in Excell | Excel Worksheet Functions | |||
Passing arguments from VBA to DLL | Excel Programming | |||
Passing arguments to VB Function | Excel Programming | |||
Passing Arguments | Excel Programming | |||
Passing arguments to a sub routine... | Excel Programming |