Solved

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

Posted on 2004-07-30
3
360 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now