Passing data between Private Sub's

M

Mark

I'm able to pass it to it, but how does in hand it back after the sub routine
is ran.
 
D

David C. Holley

That changes things. If you need to pass values back and forth, you
either have to work with FUNCTIONs and not SUBs (FUNCTIONS execute code
and return the values you designate, SUB simply execute code).
 
M

Marshall Barton

Necause there are often multiple ways to do things, instead
of asking us to explain how to do a half explained
operation, please tell us more about what you are trying to
accomoplish so the answer can be tailored to your problem.
 
J

John Nurick

That changes things. If you need to pass values back and forth, you
either have to work with FUNCTIONs and not SUBs (FUNCTIONS execute code
and return the values you designate, SUB simply execute code).

But executing code can have side-effects - especially in
VB/VBA/VBScript:

Sub Exchange(A As String, B As String)
Dim strTemp As String
strTemp = A
A = B
B = strTemp
End Sub

Sub TestExchange()
Dim str1 As String
Dim str2 As String

str1 = "first"
str2 = "last"
Call Exchange(str1, str2)
MsgBox "The " & str1 & " shall be " & str2
End Sub
 
D

David C. Holley

Yes executing code ALWAYS has an effect. Its up to the developer to
determine when/how to execute code. My answer was geared toward the
question of passing values between SUBs. Granted, I did omit
module-level variables and globals.
 
J

John Nurick

The point I was trying to make is that passing values between Sub
procedures is trivially easy: you just pass arguments by reference and
modify them as required.
 
Top