|
VBScript 5 Highlights by Charles
Carroll
Subroutines can save you having to repeat blocks of code.
This code illustrates how we can build tables with minimal code in the main script and by
including a file with a convenient subroutine.
Eval function
filename=/learn/test/vbs5eval.asp
<html><head>
<title>vbs5eval.asp</title>
</head>
<body>
<%
x="2+2*3"
response.write eval(x)
%>
</body>
</html>
Classes:
filename=/learn/test/vbs5classes.asp
<html><head>
<title>vb5classes.asp</title>
</head>
<body>
<%
' Create a myCustomer variable
Dim myCustomer
' Create a new instance of the Customer Class
' and set the value of myCustomer to be that instance
set myCustomer = new Customer
' Add a new customer
myCustomer.Add "Charles","Carroll"
' Set their Email address
myCustomer.EmailName = "charlescarroll@aspalliance.com"
' Set their credit limit
myCustomer.CreditLimit = 5000
' Display the customers fullname
response.write myCustomer.FullName
Class Customer
Public FirstName, LastName
Private nCreditLimit
Private strEmailName
Property Get EmailName
EmailName = strEmailName
End Property
Property Let EmailName ( strName)
StrEmailName = strName
End Property
Property Get FullName
FullName= FirstName & " " & LastName
End Property
Property Let CreditLimit ( s )
if s >= 0 then
nSalary = s
End If
End Property
Property Get CreditLimit
Salary = nSalary
End Property
Sub Add( First, Last )
FirstName = First
LastName = Last
End Sub
Function RaiseCreditLimit( Amount )
nCreditLimit = nCreditLimit + Amount
RaiseSalary = nSalary
End Function
End Class
%>
</body>
</html>
Execute Function:
filename=/learn/test/vbs5execute.asp
<html><head>
<title>vbs5execute.asp</title>
</head>
<body>
<%
S = "Sub Hi" & vbCrLf
S = S & " Response.write ""Hi""" & vbCrLf
S = S & "End Sub"
Execute S
Call Hi()
%>
</body>
</html>
Regular Expressions
filename=/learn/test/vbs5reg.asp
<html><head>
<title>vbs5reg.asp</title></head>
<body>
<%
address="joe@aol.com"
validmail=checkemail(address)
IF validmail THEN
response.write address & " is good!"
ELSE
response.write address & " is bad!"
END IF
address="sallyaol.com"
validmail=checkemail(address)
IF validmail THEN
response.write address & " is good!"
ELSE
response.write address & " is bad!"
END IF
FUNCTION CheckEmail(parmaddress)
set myRegExp = new RegExp
' Set the pattern to check for a word followed by
' an @ followed by a word
myRegExp.pattern = "\w+\@[.\w]+"
if myRegExp.Test(parmaddress) then
CheckEmail=True
else
CheckEmail=false
end if
END FUNCTION
%>
</body>
</html>
With
filename=/learn/test/vbs5with.asp
<html><head>
<title>vbs5with.asp</title>
</head>
<body>
<%
with response
.write "Hi<br>"
.write "how are you doing?<br>"
.write "see you around"
end with
%>
</body>
</html>
|