vb Asp.net - difference between Sub and Function ?!?

Hey what's the difference?

If i wanted the piece of code (procedure or Function) to return 2 values (eg getCustomerInfo())
What should i use

<Currently I used a sub which passed values in ByRef >
Who is Participating?
jrandallsextonConnect With a Mentor Commented:
A sub does not return values.  A function does.

If you need to return two values, yes, a sub using ByRef is the bestway.

However, you could use a Function that returns a collection of values such as an arraylist.

Public Function MyFunc(someVal, someVal2) as arraylist
crescendoConnect With a Mentor Commented:
If you need to return two values, then either a sub or a function will work. Functions are useful in this scenario where one of the returned values indicates a status, because it makes the coding neater, for example:

    If SomeFunction(ParameterA) = 0 Then
        ' do one thing
        ' do something else
   End If

as opposed to

    SomeSub(PameterA, ParamaterB)
    If Parameter B = 0
        ' do one thing
        ' do something else
   End If

It's just a matter of readability.
MargusLehisteAuthor Commented:
Excellent - answers both.

Now I just need to figure out where to stick those subs and function which i need to use in every webForm
(Have another post for that)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.