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
move in cleaning service Wilmette ..Psychology is a long word which everyone thinks, "no, that's... Read More
A simple website stats counter is not enough if you... Read More
The needs of screen magnifier users are overlooked when implementing... Read More
When used to describe a web site, the term "sticky"... Read More
Recently, a friend asked "What's the deal with those DIY... Read More
Visitors to your site come looking for information or solutions... Read More
When you publish a content site there are times when... Read More
The internet is a sea of knowledge. Getting your information... Read More
If one more business owner tells me their website sucks... Read More
When we review the sites of potential clients, there are... Read More
URL rewriting are major needs for your sites that produce... Read More
How do you decide on the content, products and or... Read More
D.zigns dzignerwebs The Basics Before starting on... Read More
The art of turning website visitors into paying customers depends... Read More
Never has competition been so difficult in the Internet world.... Read More
A PHP Redirect automatically transfers a web user from one... Read More
Your content is what gets you in search engines, speaks... Read More
Cost Effective Advertising. Online selling. Increased geopgraphic range. Wider... Read More
Think up a name and check if yourname.com is available.... Read More
Every business needs to know how it is doing. That's... Read More
This simple question can take on several different forms, but... Read More
There are lots of HTML editors on the market, however,... Read More
So what do you do if need to get a... Read More
It may seem like the publishing industry's equivalent of Beanie... Read More
There is an ongoing debate about web copy. Some say... Read More
green cleaning service Lincolnshire ..Never has competition been so difficult in the Internet world.... Read More
You've just finished congratulating your marketing team. After six months... Read More
There was a time not long ago when setting up... Read More
Customer service questionnaires can help your clients better understand their... Read More
Installment 1Developing State-enabled Applications With PHPWhen a user is browsing... Read More
When visitors add your web site to their Favorites or... Read More
If you're looking for better web site ROI, chances are,... Read More
While it may seem like a "quick and easy" task,... Read More
RIVERSIDE, CA August 4, 2004 ?- "Historically, small business owners... Read More
Are bloated images slowing down your web site and causing... Read More
With more and more countries around the world passing laws... Read More
A simple website stats counter is not enough if you... Read More
In about the Time it takes to Watch a Reality... Read More
Most web sites are more like stage sets than real... Read More
An additional benefit of website accessibility is an improved performance... Read More
Wow, we`ve already taken a domain and chosen a web... Read More
Running an effective website is a continuous process. I have... Read More
Better Web Site ROIHow to increase your business profitability by... Read More
Right after the thought, "I need a website," people usually... Read More
With search engines putting a damper on direct reciprocal links,... Read More
1. As the first step, "Hire a web designer."First create... Read More
No matter the size of your business, having a web... Read More
There are lots of HTML editors on the market, however,... Read More
1) Word of Mouth The single most powerful form of... Read More
So you finally decided to invest in a web presence... Read More
Web Development |