Callling a function plus related questions

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Can someone please explain the difference when calling a function between
using the call function and just stating the function/sub name? e.g. Call
fOSUserName and fOSUserName. Both seem to perform the same action. Also
when I see UsersLoginName = fOSUserName, is this method only used when
calling a function and returning a value? Last question, I've seen
functions which return a true or false as to whether the function completed
and the variable that the function is returned to is declared as a integer
and not a boolean, is this correct and why would this be?

Thanks in advance

Mark
 
Functions are intended to return a value. Assuming the fOSUserName function
you're talking about is the one from
http://www.mvps.org/access/api/api0008.htm at "The Access Web", the function
is intended to return a string containing the user's id (or a zero-length
string, "", if it runs into a problem)

Note that in that code, there's at least one line that assigns a value to
the name of the function: that's what causes the function to return a value.

Sometimes you don't care about what value is returned by the function. If
that's the case, you can use the Call keyword to indicate to run the code,
but not return a value. In the case of a function, you cannot simply put the
name of the function to run it: that'll raise an error. In the case of
fOSUserName, I cannot see any valid reason to call it and not have the value
returned.

Subs don't return values. To invoke a sub, you either use the Call keyword,
and use parentheses to enclose the arguments, or you simply use the name of
the routine and do not use parentheses to enclose the arguments:

Call MySub(Value1, Value2)

or

MySub Value1, Value2

Sometimes you'll see people use

MySub(Value1)

when there's only a single parameter, but that's really a fluke that it
works (the parentheses actually change how the value is being passed to the
routine). If you use

MySub(Value1, Value2)

it will not work. However, the following will:

MySub(Value1), (Value2)
 
Thanks for explaining that
Extremely helpful


Douglas J Steele said:
Functions are intended to return a value. Assuming the fOSUserName
function
you're talking about is the one from
http://www.mvps.org/access/api/api0008.htm at "The Access Web", the
function
is intended to return a string containing the user's id (or a zero-length
string, "", if it runs into a problem)

Note that in that code, there's at least one line that assigns a value to
the name of the function: that's what causes the function to return a
value.

Sometimes you don't care about what value is returned by the function. If
that's the case, you can use the Call keyword to indicate to run the code,
but not return a value. In the case of a function, you cannot simply put
the
name of the function to run it: that'll raise an error. In the case of
fOSUserName, I cannot see any valid reason to call it and not have the
value
returned.

Subs don't return values. To invoke a sub, you either use the Call
keyword,
and use parentheses to enclose the arguments, or you simply use the name
of
the routine and do not use parentheses to enclose the arguments:

Call MySub(Value1, Value2)

or

MySub Value1, Value2

Sometimes you'll see people use

MySub(Value1)

when there's only a single parameter, but that's really a fluke that it
works (the parentheses actually change how the value is being passed to
the
routine). If you use

MySub(Value1, Value2)

it will not work. However, the following will:

MySub(Value1), (Value2)
 
Back
Top