Function AS Boolean

  • Thread starter Thread starter Rob Meade
  • Start date Start date
R

Rob Meade

Hi all,

Quick question if I may...

I have a function which depending on whether it was succesful to do
something or not returns True or False as a boolean.

I have another function which call this function (infact there are two
functions as described above)...

function myFunction() as Boolean

CallFunction1
CallFunction2

End Function

Ok - the above is not actually the code (its a bit better written than
that) - but you get the idea....

Now, although CallFunction1 and CallFunction2 are set to return a Boolean, I
dont actually do anything with the result when it comes back, and myFunction
doesn't return True/False either, at least not with me saying:

Return True
Return False
or
Return <my boolean variable as state> etc etc

What I was wondering was whether or not that fact that one of these inner
function calls returns true then automatically returns myFunction as
true/false even though I'm not explicitly setting it to do so...I'm getting
some odd "alternating" values in my database each day, ie, 20,30,20,30,20,30
and the only thing I could come up with was some odd behavious in this
code..

Any explanation regarding the Function / Boolean stuff would be
appreciated,

Regards

Rob
 
The default value for the datatype will be returned if you don't explicitly
return something.

For a Boolean, that is False.
For an integer, that is 0. For a class type, that is Nothing.

So, there is always a return value regardless - it may not be the one you
want. It is bad practice to not explicitly make sure that all code paths
return a value.
 
It will return only what you told your function to return. Not sure what you
want but if you want to return true if they are both returning true it would
be something like :

function myFunction() as Boolean
Dim f1 as Boolean
Dim f2 as Boolean
f1=CallFunction1
f2=CallFunction2
Return f1 and f2
End Function
 
Hi thanks for your repies...

The two inner functions do have explicit values being returned depending on
successful database updates, and that plan would be to add some code around
these calls obviously to deal with the outcomes...

What I was after was to know whether or not either or both of these two
inner functions could be "returning" the outer function with their value...

ie, if inner function one comes back as true, does that immediately return
the outer function with the value of true because of the way I've left the
code?

Does that make sense?

Regards

Rob
 
I should have added...

So, by the inner function 1 returning a value and then returning the outer
function, this could prevent the second inner function from running?

Rob
 
Back
Top