If you read our Tutorial on Include Files (SSI) then you learned how to encapsulate ASP code within include files and the benefits it brings us.
As developers, we should endeavour to make our lives easier wherever possible... no one wants to re-invent the wheel after all.
Functions and Subroutines exist to not only save us time, but to bring power to our ASP.
They are just another way of encapsulating code, but have a lot more functionality than just 'saving some code for later'.
First, let's look at Functions... Imagine a balloon salesman in the street. We've all seen them they require one piece of information when you buy a balloon, the colour.
Let say we asked for a red balloon... The balloon salesman armed with this 'information' then does a pretty basic action... he hands you the balloon. The balloon you received is a direct result of the information you gave the balloon seller.
Functions are just the same... they return to you a value based on the information you provided. Lets look at an example Function: -
A Function is passed some information. The information we pass a Function, is known as an 'argument'. The information we get back from a Function is known as the 'return value'. Whilst a Function can have many arguments, it can only have one return value.
Let us look at one more example: -
Again, another basic example. We should notice this time that the Function accepts two arguments.
By now, we have some idea of how to write a Function. How do we use one?
Let me show you now how we can use the calcTax example.
Above you see the example function in action... easy huh!
I have tried to make understanding Functions as easy as possible... Understanding a Subroutine (Sub) is now going to be easy for you. Imagine a block of code that performed some instructions based on information you gave it...
Sounds very much like a function, doesn?t it? Well this time, we do not get anything back. A sub does NOT pass back information it just uses the data we give it for some purpose.
I will use only one example of a Sub, and in the same example make use of the sub: -
The above Sub, demonstrates my point. We put something in, it performs an action (in this case writing to the screen), but nothing is returned to us in the code. One thing that REALLY IS important when using a sub, is that we do not put brackets around the arguments... Because we do not have a return value we do not need brackets and in this case, if we try we will get an error.
Well, that just about concludes this article. We should by now be writing efficient code with the use of Functions and Subs. Don?t forget that if you use your functions and subs in multiple pages then you should really store them within include files for reasons of easy maintenance and better performance.
Rob Collyer, experienced with 20 years programming knowledge and site administrator of www.webforumz.com - Copyright 2003-2004
The first thing my business consultant (read brother-in-law) asked me,... Read More
Visitors to your site come looking for information or solutions... Read More
1. The first page appears quickly.It's a good way to... Read More
The internet is a sea of knowledge. Getting your information... Read More
One of the best tools you have as a webmaster... Read More
Today it seems everyone is jumping on the entrepreneur bandwagon,... Read More
As increasing numbers of people search for information on the... Read More
If you ever want to create a state directory, article... Read More
"Don't Sell the Steak, Sell the Sizzle."Have you heard of... Read More
The process of Web application development is critical to the... Read More
Anyone who knows anything about web accessibility knows that images... Read More
An automated accessibility tool is a piece of software which... Read More
"If you build it, they will come"; is an age... Read More
Starting a business online is no longer as difficult as... Read More
Like wine cars get more attractive to collectors as years... Read More
Although CSS layouts have been around for years, they haven't... Read More
Have you ever thought the secret behind the success of... Read More
Starting and maintaining a business is challenging enough without the... Read More
If your company own one or more stores, you might... Read More
You don't believe in astrology but you check your horoscope... Read More
Design and layout can make your communication come alive and... Read More
One of the things that many people overlook when building... Read More
--------------------------------Why Should You Create a website?--------------------------------A. What do you want... Read More
Building a website and getting it online is easy. Driving... Read More
Globalize Your WebsiteThe Internet has unlocked a wide array of... Read More
A website is the most versatile and cost-effective marketing tool... Read More
Now that you have got your domain name registered, your... Read More
In about the Time it takes to Watch a Reality... Read More
The popular search engine Google indexes over 8 billion websites.... Read More
Many of site owners still don't realize all advantages of... Read More
I can't think of any business alive today that couldn't... Read More
It is an undeniable fact that not everybody is keen... Read More
If one more business owner tells me their website sucks... Read More
So you want to take a look at a real... Read More
It may come as some surprise to a traditionally off-line... Read More
Functions and Subroutines in ASP If you read... Read More
While most marketers are beginning to understand the critical importance... Read More
The definition of the phrase "Content Management" depends on what... Read More
Your ObjectiveYour small business needs an appealing and professional website... Read More
Simply ensuring your website is accessible to screen reader users... Read More
Making money with your web site is the dream and... Read More
Your business website is a critical aspect of being able... Read More
Getting a Targeted Visitor to a website is a waste... Read More
We've all seen those messages on some websites warning not... Read More
You want to give your site's visitors a way to... Read More
If you have your own business website and you are... Read More
Did you know that hosting companies overcrowd their servers despite... Read More
Now that you have got your domain name registered, your... Read More
The following is a list of patterns that many visitors... Read More
Psychology is a long word which everyone thinks, "no, that's... Read More
My life's greatest passion is a safari hobby. And what... Read More
Understanding and using web analytics.In recent years, website marketers were... Read More
Creatively marketing your corporate site takes time in the set... Read More
1. SiteSpinner V2 - On Sale www.deprice.com/sitespinner.htmSiteSpinner is a user-friendly... Read More
One of the most important parts of establishing a new... Read More
Designing and creating your own website does not have to... Read More
What happened on your website yesterday? What about last week... Read More
If you like the Internet and surfing through the billions... Read More
What to do if you are an artist after you... Read More
There's been widespread speculation about the new legislation being introduced... Read More
A lot has changed in the way sites are optimized... Read More
It amazes me how many people try to build serious... Read More
People often come to me in a state of crisis... Read More
In my previous life.....Actually, my previous JOB life, I was... Read More
They might not be wearing a mask and carrying a... Read More
When a user signs up at your website, you may... Read More
Web Development |