Class Statement (VBScript)
Updated: March 2009
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.
Class name
statements
End Class
Within a Class block, members are declared as either Private or Public using the appropriate declaration statements. Anything declared as Private is visible only within the Class block. Anything declared as Public is visible within the Class block, as well as by code outside the Class block. Anything not explicitly declared as either Private or Public is Public by default. Procedures (either Sub or Function) declared Public within the class block become methods of the class. Public variables serve as properties of the class, as do properties explicitly declared using Property Get, Property Let, and Property Set. Default properties and methods for the class are specified in their declarations using the Default keyword. See the individual declaration statement topics for information on how this keyword is used.
The following example illustrates the use of the Class statement.
Class Customer
Private m_CustomerName
Private m_OrderCount
Private Sub Class_Initialize
m_CustomerName = ""
m_OrderCount = 0
End Sub
' CustomerName property.
Public Property Get CustomerName
CustomerName = m_CustomerName
End Property
Public Property Let CustomerName(custname)
m_CustomerName = custname
End Property
' OrderCount property (read only).
Public Property Get OrderCount
OrderCount = m_OrderCount
End Property
' Methods.
Public Sub IncreaseOrders(valuetoincrease)
m_OrderCount = m_OrderCount + valuetoincrease
End Sub
End Class
Dim c
Set c = New Customer
c.CustomerName = "Fabrikam, Inc."
MsgBox (c.CustomerName)
c.IncreaseOrders(5)
c.IncreaseOrders(3)
MsgBox (c.OrderCount)