Topic: ASP Function and Subroutines 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. Example-1 <% Function calcTax(amount, taxrate) Dim Tempvar Tempvar = amount * (taxrate / 100) CalcTax = Round(Tempvar, 2) 'round the result to 2 decimal places End Function %> Again, another basic example. We should notice this time that the Function accepts two arguments. Let me show you now how we can use the calcTax example. <%shoppingbill=goodsTotal + calcTax(goodsTotal,17.5) Response.Write "Your shopping came to £" & goodsTotal Response.Write " VAT amount = £" & calcTax(goodsTotal) Response.Write "Total Amount Due = £" & shoppingbill %>
|
|