which this wasn't and I don't have a problem with, and Greg gave TOO
much information. Yikes! I'm not familiar with all that, so it's
lost on me.
Let's try this.
Method, Object and talk like that makes my brain start to glow as a
result of all the thinking to convert into something I can get my
arms around.
Now, I do know about and the difference between Functions and
Procedures and Sub(routines) generally speaking. And I do know that,
in general, there can/may be several ways to pass parameters in
higher level languages.
My question is only about _returning_ variables _from_ a Sub for use
in the _calling_ Sub.
SO… in VBA, if I call a sub, how can I gat a variable OUT OF that
sub, not into? Let's try Ray's code. Look here '****
----start of module
Global str_gl_Colour as String
Global str_gl_Animal as String
Global str_gl_Sentence as String
----
Sub CallString
str_gl_Colour = "Yellow"
str_gl_Animal = "Dog"
MakeString(str_gl_Colour, str_gl_Animal)
'
'**** Right here. How can I get
'**** the value of str_gl_Sentence
'**** Perhaps to do this:
Debug.Print str_gl_Sentence
'
End Sub
----
Public Sub MakeString(myColour, myAnimal)
str_gl_Sentence = "I would love to own a " & myColour & " " & myAnimal
End Sub
----end of module
SO, Is a Global (I thought it was called "Public" in VB) the ONLY
way?
Part of the confusion on my part is that I seem to remember that in
some long past language, (??? Fortran perhaps ??) you put _returned_
variables in the same variable list at the beginning of the sub, as
the passed variables. I keep wanting to have my returned variable in
that list at the start of the sub. Like this:
----------
Dims here or wherever they're needed.
Sub StartHere
A = 4
B = 2
Call DoSomething(A, B, C)
Answer = C ' where Answer now contains 8
End Sub
Sub DoSomething(X, Y, Z)
Z = X * Y
End Sub
-----------
A and B are passed TO and C is returned from, or am I in on the wrong
planet…
Aside from using a spreadsheet cell, do I hafta' make C global and
just do this:
-----------
Public C As…
. . .
Call DoSomething(A, B)
Answer = C ' where Answer now contains 8
End Sub
Sub DoSomething(X, Y)
Private X, Y As. . . ' This may be wrong, but just to show that they
are.
C = X * Y
End Sub