Default Function Value

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
 
M

Marina Levit [MVP]

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.
 

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

Members online

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top