Solved

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

Posted on 2004-07-30
3
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

696 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