例: Sub New

' Define a class.
Class textObject
   ' Declare member variables.
   backGroundColor As Integer
   textColor As Integer
   contentString As String
   ' Define constructor sub.
   Sub New (bColor As Integer, tColor As Integer,_
          cString As String)
      backGroundColor% = bColor%
      textColor% = tColor%
      contentString$ = cString$
      Print "Creating new instance of text object ..."
      Print "Text object state:"
      Print "Background color:" ; Me.backGroundColor% ; _
         "Text color:" ; Me.textColor%
   End Sub
   ' Define destructor sub.
   Sub Delete
      Print "Deleting text object."
   End Sub
   ' Define a sub to invert background and text colors.
   Sub InvertColors
      Dim x As Integer, y As Integer
      x% = backGroundColor%
      y% = textColor%
      Me.backGroundColor% = y%
      Me.textColor% = x%
   End Sub
End Class
' Create a new object of class textObject.
Dim zz As New textObject(0, 255, "This is my text")
' Output:
' Creating new instance of text object ...
' Text object state:
' Background color: 0 Text color: 255
' Invert the object's background and text colors.
zz.InvertColors
' Delete the object, first running the destructor sub.
Delete zz
' Output: Deleting text object.