VBScript Class Objects
Create reusable objects with properties, methods, events
Person Class
A class with private fields, property get/let, methods, and constructor.
| p.Name | Alice |
|---|---|
| p.Age | 25 |
| p.Greet() | Hello, my name is Alice and I am 25 years old. |
| p.IsAdult() | True |
Multiple Instances
Each instance has independent state.
| p1 (Bob) | p2 (Charlie) | |
|---|---|---|
| Name | Bob | Charlie |
| Age | 17 | 42 |
| IsAdult | False | True |
Calculator Class
Stateful object with operations. Try clicking the buttons.
10
current total
Added 10
Class Lifecycle Events
Class_Initialize— called whenSet obj = New ClassNameexecutesClass_Terminate— called whenSet obj = Nothingexecutes (or object goes out of scope)- Properties declared with
Publicare readable/writable directly - Use
Privatefields +Property Let/Get/Setfor controlled access - Methods can return values via
Functionor perform actions viaSub