July 21, 2006. Posted August 27, 2016

My first VBScript Test Class

<%
Option Explicit

'// My first VBScript Test Class
Class TestClass

Public a

Public b

Private internal_Factor

Public Property Get TheSum
TheSum = a+b
End Property

Public Property Get ATimes
ATimes = a*internal_Factor
End Property

Public Property Get BTimes
BTimes = b*internal_Factor
End Property

Public Property Let SetFactor(ByVal varFactorIn)
If IsNumeric(varFactorIn) Then
internal_Factor = varFactorIn
Else
internal_Factor = 1
End If
End Property

Public Property Get SetFactor
SetFactor = internal_Factor
End Property

Public Property Get PrintMyself
Response.Write "<br>"
Response.Write a & " + " & b & " = " & TheSum
Response.Write "<br>"
Response.Write "The factor is " & internal_Factor
Response.Write "<br>"
Response.Write "Factorized: " & ATimes & " " & BTimes & " = " & TheSum
End Property

End Class

%>

And testing it out

<%

Dim oTestClassObject
Set oTestClassObject = New TestClass
oTestClassObject.a = 12
oTestClassObject.b = 5

oTestClassObject.PrintMyself
oTestClassObject.SetFactor = 100
oTestClassObject.PrintMyself
oTestClassObject.SetFactor = 0
oTestClassObject.PrintMyself
oTestClassObject.SetFactor = 10
oTestClassObject.PrintMyself

%>

Results

12 + 5 = 17
The factor is
Factorized: 0 0 = 17
12 + 5 = 17
The factor is 100
Factorized: 1200 500 = 17
12 + 5 = 17
The factor is 0
Factorized: 0 0 = 17
12 + 5 = 17
The factor is 10
Factorized: 120 50 = 17