You never used tmp_stuff inside foo(). As posted, you just used the global stuff variable.
In any case, tmp_stuff (as a parameter in the function statement's parameter list) is just a
reference to whatever the function was with. By default, VBScript passes by reference (ByRef) just
like VB/VBA. That means whatever change you make to tmp_stuff inside foo() is actually changing
whatever variable was passed (stuff in this case). To prevent changes to tmp_stuff from affecting
the variable passed, you pass by value (ByVal).
An example,
stuff = "foo"
msgbox foo(stuff) & " " & stuff
stuff = "bar"
msgbox bar(stuff) & " " & stuff
function foo(tmp_stuff)
tmp_stuff = ucase(tmp_stuff)
foo = tmp_stuff
end function
function bar(byval tmp_stuff)
tmp_stuff = ucase(tmp_stuff)
bar = tmp_stuff
end function
--
Michael Harris
MVP Scripting
I have a function (example) ...
--
stuff = "whatever"
new_stuff = foo (stuff)
function foo (tmp_stuff)
dim a, b ' scope of a, b limited to the function
a = left (stuff, 2)
b = right (stuff, 2)
foo = a & b
end function
--
But tmp_stuff is not local to foo, and in fact persisted in a very
unexpected way. Generally not a big deal unless successive foo()'s are
made from within another function. Is there a way to make tmp_stuff
local? Or should I always plan on a set of temporaries to use and
destroy on every call to function x?
Thanks,
Scott