Procedures/Functions

A

Anil Gupte

Hopefully this list is newbie-friendly. I have a conceptual questions. I am
learning VB and came across the description in a book I am using that
describes procedures vs. functions. I understand the difference, but my
question would be - why use procedures at all if functions do everything
that procedures do, and in addition return a value?

Thanx,
 
T

Tom Shelton

Anil said:
Hopefully this list is newbie-friendly. I have a conceptual questions. I am
learning VB and came across the description in a book I am using that
describes procedures vs. functions. I understand the difference, but my
question would be - why use procedures at all if functions do everything
that procedures do, and in addition return a value?

Because you don't always need or want to return a value. There is
nothing stopping you from always using a function. It's just sometimes
it doesn't really make sense.
 
M

Miro

Anil,

I was exactly in your boat about 3 weeks ago or a tad more.
I am new to vb.net and posted the same question.

To answer your question quick, you are correct. A Function is the same as a
Sub except a Function
returns a value.

===now for the long

I come from a programming concept where everything is programmed in a
function and always returns
a value of .T. or something else if needed. So I asked,
why not make everything a function instead of using subs and functions.

The answer given to me ( and I cant find the old post here ) is that you
can, but there is no point.
A Sub procedure can be changed to a function very simply if it is required
to be for one ( which was an answer given to me ).

It is just is simpler and proper programming.
I have since then tried to program with subs, and functions when needed. It
does seem cleaner reading code following
some VB standards.

But I think you might be coming from the same place I was. Always a
function.
Hard to break the habit, but im happier for it.

M.
 

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

Top