クラスの配列とリスト

オブジェクトのグループを操作する場合、オブジェクトを要素として含む配列またはリストを作成できます。

次の例では、Fruit クラスのオブジェクトの配列とリストの両方を作成します。

' Declare an array of references to base class: a Fruit Basket.
Dim Basket( 1 to 4 ) As Fruit
Set Basket(1) = New Apple(0.86, "Green", "Macintosh", 24)
Set Basket(2) = New Apple(0.98, "Red", "Delicious",33)
Set Basket(3) = New Banana(0.32, "Yellow")
Set Basket(4) = New Apple(1.2, "Yellow", "Delicious",35)

' Declare a list of references to base class: a Fruit Bucket.
Dim Bucket List As Fruit
Set Bucket("1") = New Apple(0.86, "Green", "Macintosh", 24)
Set Bucket("2") = New Apple(0.98, "Red", "Delicious",33)
Set Bucket("3") = New Banana(0.32, "Yellow")
Set Bucket("4") = New Apple(1.2, "Yellow", "Delicious",35)

' Prepare all of the fruit in the Basket.
ForAll YummyThing in Basket
  YummyThing.Prepare   ' Call each object's Prepare sub.
End ForAll

' Prepare all of the fruit in the Bucket.
ForAll FruityThing in Bucket
  FruityThing.Prepare   ' Call each object's Prepare sub.
End ForAll