Last updated: August 25, 2026.
VBScript procedures let a Classic ASP page group reusable logic. A Sub performs an action, while a Function returns a value by assigning it to the function’s name.
Write and call a Sub
<%
Sub WriteGreeting(ByVal personName)
Response.Write Server.HTMLEncode("Hello, " & personName)
End Sub
Call WriteGreeting("Sam")
%>Write and call a Function
<%
Function LineTotal(ByVal quantity, ByVal unitPrice)
LineTotal = CDbl(quantity) * CCur(unitPrice)
End Function
Dim total
total = LineTotal(3, 19.95)
Response.Write FormatCurrency(total)
%>Parameter behavior
- Use
ByValwhen the procedure should not replace the caller’s variable. - Use
ByRefonly when modifying the caller’s variable is intentional. - Parentheses are used when a function result is part of an expression.
- Keep database access and HTML output separate when procedures grow complex.
- Encode untrusted output with
Server.HTMLEncode.
Microsoft’s Classic ASP documentation describes procedural processing in ASP.