Public クラスメンバ

クラスのスコープの外でアクセスできるのは、クラスの Public メンバだけです。Public クラスメンバは、ドット表記を使用して参照します。

次の例では、Customer クラスのメンバ変数 balance@ と custName$ にアクセスできます。

Class Customer
  Public custName As String
  Public balance As Currency

  Sub CheckOverdue
    If balance@ > 0 Then
      Print "Overdue balance"    ' Send an overdue letter.
    End If
  End Sub         
End Class

Dim X As New Customer
Dim newBal As Currency

' This is a legal statement, because custName is Public.
X.custName$ = "Acme Corporation"
X.balance@ = 14.92	             ' Balance@ is Public.

' Assigns the value of the Public member variable balance
' to the variable newBal@.
newBal@ = X.balance@
Print X.balance@; newBal@        ' Prints 14.92  14.92

延滞金を調べるには、次の例のように、Public サブルーチン CheckOverdue を呼び出すことができます。

Dim Y As Customer
Set Y = X
Y.CheckOverdue     'Prints "Overdue balance"
Print Y.balance@; X.balance@     ' Prints 14.92  14.92