eWebProgrammer eweb





ASP   «Prev 

User-defined Subprocedures and Functions

Subprocedures

Subprocedures are small groups of code that carry out a specific action, then return control to the calling statement.
Creating a sub-procedure is simple: start with "Sub <sub-procedure name>," create the block of code you want to repeat later, then end with "End Sub."
To call the sub-procedure, you use type "Call <sub-procedure name>."
Here's an example:

Sub Welcome( )
     Response.Write "Welcome to Ewebprogrammer <BR>"
     Response.Write "Date: " & Date & ", Time: " & Time
End Sub

Call Welcome
(the rest of the page)


Functions

Functions, unlike sub-procedures, return a value after carrying out an action. This is useful when you need to reuse code, but the data it returns isn't always the same. Creating a function is similar to creating a sub-procedure, except before ending the function, a return value is assigned to the name of the function. This statement sends data back to the calling statement.
Here's an example:

Function DaysLeft(dToday)
DaysLeft = DateDiff("d", Now(), dToday)
End Function
    Dim dToday
    dToday="10/05/00"
    Response.Write "Sale ends in " + DaysLeft(dToday)
    & " day(s)."