Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is the difference between a function and a subroutine?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 28-02-2009
Member
 
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,

Reply With Quote
  #2  
Old 28-02-2009
Member
 
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.
Reply With Quote
  #3  
Old 28-02-2009
Member
 
Join Date: Apr 2008
Posts: 1,999
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
Reply With Quote
  #4  
Old 28-02-2009
Member
 
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")
Reply With Quote
  #5  
Old 28-02-2009
Member
 
Join Date: May 2008
Posts: 2,005
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.
Reply With Quote
  #6  
Old 28-02-2009
Member
 
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 -
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is the difference between a function and a subroutine?"
Thread Thread Starter Forum Replies Last Post
c# function equivalent to gettime function in javascript Omaar Software Development 4 10-03-2010 09:44 PM
Difference between memcpy() and strncpy() function in C Owen Fernandes Software Development 5 16-01-2010 07:46 AM
How to Call a variable subroutine or function Sayam Software Development 2 16-04-2009 09:33 PM
What is the difference between Msgbox Statement and MsgboxQ function? SamsherR Software Development 2 28-02-2009 09:32 PM
Difference between Sub and Function in Visual Basic and VB.Net Bellamy Software Development 3 21-01-2009 09:11 PM


All times are GMT +5.5. The time now is 07:56 AM.