Solved

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

Posted on 2004-07-30
3
363 Views
Last Modified: 2008-03-04
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 >
0
Comment
Question by:MargusLehiste
3 Comments
 
LVL 4

Accepted Solution

by:
jrandallsexton earned 125 total points
ID: 11680926
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
0
 
LVL 9

Assisted Solution

by:crescendo
crescendo earned 125 total points
ID: 11681009
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
    Else
        ' do something else
   End If

as opposed to

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

It's just a matter of readability.
0
 
LVL 1

Author Comment

by:MargusLehiste
ID: 11681470
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)
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question