Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-07-30
3
Medium Priority
?
382 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 500 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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