Results 1 to 6 of 6

Thread: What is the difference between a function and a subroutine?

  1. #1
    Join Date
    Feb 2009
    Posts
    7

    What is the difference between a function and a subroutine?

    Hi!

    What is the difference between a function and a subroutine in vb dot net?

    Regards,

  2. #2
    Join Date
    Feb 2009
    Posts
    5

    Re: What is the difference between a function and a subroutine?

    A function returns a value whereas a subroutine does not. A function should not change the values of actual arguments whereas a subroutine could change them.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,010

    Re: What is the difference between a function and a subroutine?

    I think you've got it...

    VBScript is considered "messy" anyhoo...

    I often see functions used just like a subs...the functions just don't return anything and you don't store the return value in the call:

    ...some code...
    foo barred, up ' call to a function like a sub...not trapping the return value
    ...some more code...

    function foo(param1, param2)
    ' some code
    end function

  4. #4
    Join Date
    May 2008
    Posts
    115

    Re: What is the difference between a function and a subroutine?

    VB6 function calls vs. subroutine calls

    In VB6, there is a difference between the syntax for a subroutine call and
    a function call. The function call is a method with arguments in parentheses,
    such as:

    success = zip.UnzipMatching("unzipDir","*.jpg",1)

    You could also call it as a subroutine, but you *must* leave off the parens:

    zip.UnzipMatching "unzipDir", "*.jpg", 1

    A function with one argument might seem confusing, because both seem to work:

    zip.OpenZip ("test.zip")

    and

    zip.OpenZip "test.zip"

    However, VB6 recognizes the function parameter list by the commas, so the ("test.zip") is just
    an expression. You’ll notice that VB6 will insert a space between the method name and
    the left paren. However, if you call it as a function, no space is inserted:

    success = zip.OpenZip("test.zip")

  5. #5
    Join Date
    May 2008
    Posts
    2,015

    Re: What is the difference between a function and a subroutine?

    A function accepts any number of parameters (possibly zero), does something with them, and returns a value. A subroutine is performs an action, but doesn't return a value.

    There are two differences between a function and a subroutine: A)How they are invoked. B)How they are accessed.

    A function call has the following syntax ::
    function(arg1, arg2, ...)
    where: function Is the name of the function. arg1, arg2, ... Are the arguments.

    A subroutine call has the following syntax
    ::subroutine (arg1, arg2, ... {outputfield|'format'})
    where: subroutine -->Is the name of the subroutine. arg1, arg2, ... Are the arguments. {outputfield|'format'} Is the name of the output field or its format.

    In addition, on some platforms, the functions are available immediately; whereas, the subroutines are available in a special subroutine library that you must access.

  6. #6
    Join Date
    May 2008
    Posts
    72

    Re: What is the difference between a function and a subroutine?

    Let's start with properties. Properties are characteristics of an object. Examples of objects? Textbox, label, form, RadioButtons, etc. Objects can also be defined through class definitions and are instantiated when called upon and used in a program.

    Methods are tasks that are tied directly to an object. They occur when an action takes place upon that object. They do not exist without the presence of that object.

    Sub Routines (otherwise known as Independent Sub Functions) are functions that are completely INDEPENDENT of OBJECTS. That means that they can be called from anywhere in the program. They do not have a "return value," though they can return information to the calling function via parameter passing by reference.

    Functions are code blocks thay create change on some variable or object. They are not necessarily tied to an object (though all methods are functions) and usually have a "return value" that is caught and used somehow in the calling function. Most often, this return value is stored in a variable, though the function call itself can be used in a subsequent function call (example:
    Dim sum as Integer = Add(getnumber() + 2) )

    I hope that is a help to you -

Similar Threads

  1. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 09:44 PM
  2. Difference between memcpy() and strncpy() function in C
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 07:46 AM
  3. How to Call a variable subroutine or function
    By Sayam in forum Software Development
    Replies: 2
    Last Post: 16-04-2009, 09:33 PM
  4. Replies: 2
    Last Post: 28-02-2009, 09:32 PM
  5. Difference between Sub and Function in Visual Basic and VB.Net
    By Bellamy in forum Software Development
    Replies: 3
    Last Post: 21-01-2009, 09:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •