Passing data between Private Sub's

  • Thread starter Thread starter Guest
  • Start date Start date
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).
 
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.
 
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
 
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.
 
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.
 
Back
Top