Get values for function

G

Guest

If I call a function, how do I get the values gathered before making a call
to the function if I call the function in the middle of script? I have run
into this several times, as I don't want to have to keep asking for the same
values that may be used inside the function. Exp:

dim x

x = 25

call some function

y = x ' x should be 25


Thanks.

Kou
 
P

pietlinden

If I call a function, how do I get the values gathered before making a call
to the function if I call the function in the middle of script? I have run
into this several times, as I don't want to have to keep asking for the same
values that may be used inside the function. Exp:

dim x

x = 25

call some function

y = x ' x should be 25

Thanks.

Kou

Could you give us an example? If you want to be sure the values are
returned, you can do something like

Dim lngRetVal as long
lngRetVal1 = MyFunction(arg1, arg2, arg3...)
lngRetVal2=MySecondFunction(arg1, arg2)
lngRetVal3=MythirdFunction(lngRetval1, lngRetVal2)
 
M

Marshall Barton

Kou said:
If I call a function, how do I get the values gathered before making a call
to the function if I call the function in the middle of script? I have run
into this several times, as I don't want to have to keep asking for the same
values that may be used inside the function. Exp:

dim x

x = 25

call some function

y = x ' x should be 25


It sounds like you are asking about using arguments to a
procedure?? If so, check VBA Help for:
Function Statement

The basic idea is:

Public Function myfunc(abc As Integer) As Integer
myfunc = abc * 2
End Function

then call it somethng like:

p = myfunc(25) + 4
 
G

Guest

I guess I'm trying to pass an argument from a sub into a function to get a
value back into the sub. Would it just makes things easier, if I just moved
the argument into the function and out of the sub, then pass it into the sub?
I hope I understand what I'm saying now.

Kou
 
M

Marshall Barton

It sounds like you might not understand what you are saying
;-)

This is a very simple concept so if you are having a problem
with it, you should provide enough of your code to
demonstrate whatever issue is causeing trouble. At least
you can then use the names of the arguments/variables to
illuminate your question.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top