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 tutorial on include files (ssi) - Copyright 2003-2004
residential cleaning services Lincolnshire ..When a user signs up at your website, you may... Read More
Analyzing traffic to a site is a key factor in... Read More
1. As the first step, "Hire a web designer."First create... Read More
With all of the factors involved in designing and building... Read More
Never has competition been so difficult in the Internet world.... Read More
Thousands of people are now making a living online and... Read More
It is an undeniable fact that not everybody is keen... Read More
Are you, like many other website owners, frustrated at the... Read More
In this day and age most businesses consider having their... Read More
Why do some sites succeed while the vast majority of... Read More
Have you ever wondered what challenges are faced by other... Read More
The growth in Internet usage around the world is astounding... Read More
When used to describe a web site, the term "sticky"... Read More
So you've decided to start an online work at home... Read More
One of the best tools you have as a webmaster... Read More
When you started reading this sentence you assumed lo acabar?a... Read More
What is CSS?CSS is a simple file which controls the... Read More
Looks like every client wants a Flash site these days... Read More
Anyone who knows anything about web accessibility knows that images... Read More
We are clearly well past the innocent "golden age" of... Read More
So you want to take a look at a real... Read More
Did you know that hosting companies overcrowd their servers despite... Read More
A website is like an information flow, with you as... Read More
A website is the most versatile and cost-effective marketing tool... Read More
Internet Marketing is not a miracle marketing strategy ? competition... Read More
best cleaning company Highland Park ..The DDA (Disability Discrimination Act) states that service providers must... Read More
The cost of setting up a web site is dirt... Read More
One of my most salient memories from when I sold... Read More
Simply ensuring your website is accessible to screen reader users... Read More
I can't think of any business alive today that couldn't... Read More
--------------------------------Why Should You Create a website?--------------------------------A. What do you want... Read More
Project Safekids provides webmasters a valuable tool which could save... Read More
Dynamically Update Your Web Pages Via E-MailIf you can Send... Read More
Below, I have listed 8 simple steps that you can... Read More
A system development process can follow a number of standard... Read More
The DDA (Disability Discrimination Act) states that service providers must... Read More
A professional online reputation is essential to the flourishing of... Read More
Go to any internet marketing forum you want these days... Read More
Making a web site is easy. Making a good web... Read More
Before you set up any scripts you will need some... Read More
There are many elements that are key to successful web... Read More
Designing an E-commerce Web site is not as simple as... Read More
We are clearly well past the innocent "golden age" of... Read More
Did you know that hosting companies overcrowd their servers despite... Read More
Web sites are not just places to sell things; they... Read More
A website lets you put your products in front of... Read More
The Internet is being used by local service business to... Read More
Many small businesses have the misconception that their business can... Read More
What is web accessibility & why is it important?Web accessibility... Read More
Everywhere you look these days, people are telling you that... Read More
Web Development |