ASP
  Home arrow ASP arrow Page 3 - The Real Basics of Functions in ASP
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

The Real Basics of Functions in ASP
By: John Puddifoot
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 257
    2004-12-21

    Table of Contents:
  • The Real Basics of Functions in ASP
  • Simplemaths
  • Customer Spec Part 2
  • A Common ASP Task
  • Calling the Function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    The Real Basics of Functions in ASP - Customer Spec Part 2


    (Page 3 of 5 )

    Customer Spec part 2: "Ok John, that’s great, now we need to do it for all of these numbers too…."

    You suddenly need to work out the result of hundreds of sums. But because we have a function that does all of the dirty work (okay,  perhaps it’s not that dirty) you only need to add one line of code per calculation:

    <%
    function simplemaths(var1, var2)
      result=var1+var2
      ' Add a new line to do the multiplication
    result=result*10
      response.write result & "<br />"
    end function

    call simplemaths(1, 2)
    call simplemaths(1, 9)
    call simplemaths(3, 4)
    call simplemaths(1, 5)
    %>

    So you’re happily coding away, putting the final sum together when the customer calls you again:

    "Erm, I’ve just realized – I need you to multiply all of the numbers by ten before you write them to the screen! Sorry!"

    If you had hundreds of individual calculations then that could be a big task. If you have one function that does it all, then it’s easy!

    <%
    function simplemaths(var1, var2)
      result=var1+var2
      ' Add a new line to do the multiplication
    result=result*10
      response.write result & "<br />"
    end function

    call simplemaths(2, 2)
    call simplemaths(1, 2)
    call simplemaths(1, 9)
    call simplemaths(3, 4)
    call simplemaths(1, 5)

    input1=10
    input2=20
    call simplemaths(input1, input2)

    %>

    Pretty compelling, eh? So functions are the bee’s knees and re-usable, maintainable code will save us all. The functions that developers have as a resource act as the foundations for the applications that they produce and the ability to control these functions is a valuable one. The concept relies upon the fact that you and your code shouldn’t really have to worry about how to achieve the specific task – because after you’ve coded it once you never need to code it again. It’s a little black-box of code and all you need to know is how to use it (not how it works inside). This description is edging us gently towards the concepts of Object-Orientated (OO) Design and if you’d like to stick with me through the series of articles we’ll attempt to cover this in more detail – by developing more real-life examples and ideally code that we all can use and re-use!

    More ASP Articles
    More By John Puddifoot


       · The code works great to add new records to a database. However, if you need to...
       · Here is the most valuable function for asp. Place this into global.asas or a...
       · function db_dropdown(sTable, sId, sDropdownName, sBoundfield,...
       · What does the value of "sID" represent? Is it the value of the field from Table1 in...
       · ' Create a suitable connection object for a given connection string. Function...
       · ' Create a suitable connection object for a given connection string. Function...
       · This is very good but i don't why this doesn't work???
       · simple... but VERY cool.
       · I have problem to seek them, because I don't have this software...?
       · function db_dropdown(tablename, bound_field, display_field,order_field,...
     

    ASP ARTICLES

    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application
    - Easy Error Management

    Iron Speed




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway