Subroutines and Functions

Pluralsight courses
LinkedIn Premium uses PayScale to estimate job salaries

Premium (Not Free) Video Tutorials

Free Video Tutorials & Free Tools

Well I am writing this tutorial in which i wil tell you about subroutines and functions in

Note: This tutorial can also apply for other languages because the basic programming fundamentals are the same .


And you can also take a look at this page in which this concept is explained clearly –

So first start from the easiest concept.

We all know that in our form class there are many subroutines like

a subroutinethat appears when we double click an command button in design view.

That is a subroutine because of the keyword sub which means it is a subroutines.

Subroutines and Functions are called procedures .

Remember procedures are jsut self contained blocks of code and are of 2 types

1. Subroutines

2. Functions

Now let's see the procedure(subroutine) that appears in code view when you double click an button in desig view.

In this screenshot errorcheck is a subroutine.


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

End Sub

This is a self contained block of code which means it contains code inside itself (in this case it dosnt because we havnt enter anything inside it)

So the first time you look at it you can say it is a self contained block of code it contains code inside

sub statements and end sub statement

Now we also see that sub keyword in the first line which obvyously means it is a subroutine .

So now comes the time when you should know the defination of subroutine .

A subroutine is a procedure which does some thing(someprogramming task) but it dosnt return any value.

example : the command1_click sub

we can call subroutines by just entering their name like take the example of this sub.

public sub dosomething()


Now to call it simple type in



And Now let's discuss about functions .

Functions are same as subroutines . They also perfom some task but they have a special property that they return values inside the calling variable .

verify postal code is a function as it returns an string value to a variable that calls it

confusing?? Dont worry

i will show you what i mean

when you have written this function and you know that a function is a procedure that returns a value then you have to store this value somewhere when you call it

so in this case it returns a string value so we will declare a new variable as string

dim test as new string

now we will calll the function

test=verifypostalcoe(arguments )

The function will return a value after calculations and store it inside the test variable.

Things that functions and sub's have common in them

1. both of them are self contained blocks(procedures)

2. Both of them do some task


Have any doubt dont hesitate to ask me in the idealpogrammer forums or via comment.

Here are the videos which are related to this topic -





Related posts:

  1. Update Resources of dll,exe files Do You want to update the resources which are present...
  2. Movefilex function In this article i will tell you about movefilex function...
  3. Build a bluetooth Chat Application Bluetooth is one of today's most exciting technologies. It...
  4. Learn in 24 hours Yes that's right you can actually learn in 24...
  5. environment class The .net framework provides this useful class which can retrieve...

Related posts brought to you by Yet Another Related Posts Plugin.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

Powered by WP Hashcash

This blog uses the cross-linker plugin developed by Web-Developers.Net