Web Development

  Homes arrow Web Development arrow Functions and Subprocedures
 Webmaster Tools
 
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML to PHP 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
 
Password Strength
 
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB DEVELOPMENT

Functions and Subprocedures
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-08-09

    Table of Contents:

    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
     
     

    SEARCH DEV MECHANIC

    TOOLS YOU CAN USE

    advertisement

    Functionsand Subprocedures

    Thetwo have many similarities:

    - They are both blocks ofcode
    - Both can accept arguments
    - Both can be reused throughoutyour script, thus savingalot of your time. You cancall they from anywherewithin your page

    The difference between afunction and a sub is thata sub will do some stuff(like printing somethingto the screen) and thenquit, while a function runssome code and then returnsthe result back. A Functioncould be used to do a calculationand then return a result.

    How to declare/write each:
    <%
    Sub NameOfSubRoutine(parameter1, parameter2)
    'code goes here...
    End Sub

    %>

    <%
    Function NameOfFunction(parameter1, parameter2)
    'some code
    NameOfFunction = "returnvalue"
    End Function
    %>

    You will notice above parameter1and parameter2. Data ispassed into a procedurethrough the use of thesearguments. Arguments areseparated by commas andput into parenthesis afterthe procedure name.
    If there are no arguments,the procedure would stillhave the parenthesis, butthey would be empty:

    <%

    SubNameOfSubRoutine()
    'code goes here...
    End Sub
    %>

    Belowis subprocedure that printsout details on the page:

    <%
    Sub PrintOut(name,address,country)
    response.write name
    response.write address
    response.write country
    End Sub
    %>


    To call the Sub, I coulddo one of the following:

    <%

    Call PrintOut("michael","34 Hark Avenue","Ireland")
    %>

    OR
    <%
    PrintOut "michael","34 HarkAvenue","Ireland"

    %>

    Note that in each example,the actual argument passedinto the subprocedure ispassed into the subprocedurein the corresponding position.
    Also note that if you usethe Call statement, thearguments must be enclosedin parenthesis. If you donot use call, the parenthesisaren't used.

    Likethe Sub procedure, a Functioncan accept arguments, butunlike the Sub procedure,a Function can return avalue. Functions are especiallygood for doing calculationsand returning a value.

    <%
    Function Total(firstnumber,secondnumber)
    Total=(firstnumber+secondnumber)
    End Function
    %>


    This is how the functionwas called:

    <%Sum=Total(2,100) %>

    Callingthe Total function madethe value of Total equalto the value returned bythe function, which thencan be displayed by doing

    <%response.write Sum %>

    Theoutput of the above is:102

    Notethat the returned valueis named the same as thefunction.
    This is important to remember!You will need to name theoutput value the same asyour function or you willnot get a value returned.

    Codefixer- Tutorials and resourcesfor the beginner to intermediateASP developer.

     

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed

       

    WEB DEVELOPMENT ARTICLES

    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates

     



    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap