Default Function Value

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have a function as follows:

Public Function myF() As String

....

End Function

Is it possible to define a default value that the function would return
if no "return" command is executed?

Thanks,

Miguel
 
The way you would usually do that, is have a variable with the return value.
So you declare a variable, assign it the default return value. Then, in the
rest of the code, assign the variable other values where appropriate.

At the bottom of the function have just 1 return statement that returns your
variable. If you never assigned it a new value, it will contain the default.

In VB, you can also treat the function name as a variable, and assign 'myF'
a value. Personally, I don't like that kind of code. It's not portable to
other languages, and it just looks ugly. I prefer to declare my own
variable.
 
Back
Top