title: Creating an Array of Objects in Classic ASP
body: <p>I am trying to create a class in Classic ASP and am getting close to what I am looking for but it is not quite there. I have yet to find any examples that solve my problem.</p>
  
  <p>In the example I need the LineItem class to be stored in the Order class as an array so there can be multiple line items for an order. Currently it works but only allows a single instance of LineItem. Can someone give me an example showing me how to make it into an array? I understand how to create an array of obects, but not how to store them in the parent object. My apologies, but it has been over 15 years since I have done any programming in Classic ASP and I have forgotten most of what I knew back then.</p>
  
  <pre><code>&lt;%
      Class LineItem
  
      Private LineNumberVar
      Private ItemCostVar
      Private QuantityVar
      Private ItemCodeVar
      Private ItemDescriptionVar
  
      ' Line Number
      Public Property Get LineNumber()
          LineNumber = LineNumberVar
      End Property
  
      Public Property Let LineNumber(lineNumberParam)
          LineNumberVar = lineNumberParam
      End Property
  
      ' Item Cost
      Public Property Get ItemCost()
          ItemCost = ItemCostVar
      End Property
  
      Public Property Let ItemCost(itemCostParam)
          ItemCostVar = itemCostParam
      End Property
  
      ' Quantity
      Public Property Get Quantity()
          Quantity = QuantityVar
      End Property
  
      Public Property Let Quantity(quantityParam)
          QuantityVar = quantityParam
      End Property
  
      ' Item Code
      Public Property Get ItemCode()
          ItemCode = ItemCodeVar
      End Property
  
      Public Property Let ItemCode(itemCodeParam)
          ItemCodeVar = itemCodeParam
      End Property
  
      ' Item Description
      Public Property Get ItemDescription()
          ItemDescription = ItemDescriptionVar
      End Property
  
      Public Property Let ItemDescription(itemDescriptionParam)
          ItemDescriptionVar = itemDescriptionParam
      End Property
  End Class
  
  
  Class Order
  
      Private CustomerIDVar
      Private OrderIDVar
      Private EmailVar
      Private ItemsVar 
  
      'CustomerID
      Public Property Get CustomerID()
          CustomerID = CustomerIDVar
      End Property
  
      Public Property Let CustomerID(customerIDParam)
          CustomerIDVar = customerIDParam
      End Property
  
      'OrderID
      Public Property Get OrderID()
          OrderID = OrderIDVar
      End Property
  
      Public Property Let OrderID(orderIDParam)
          OrderIDVar = orderIDParam
      End Property
  
      'Email
      Public Property Get Email()
          Email = EmailVar
      End Property
  
      Public Property Let Email(emailParam)
          EmailVar = emailParam
      End Property
  
      ' Line Items (needs to be an array of LineItem class objects)
      'Items
      Public Property Get Items()
          Set Items = ItemsVar
      End Property
  
      ' must use Set for objects
      Public Property Set Items(itemsParam)
          Set ItemsVar = itemsParam
      End Property
  
      Private Sub Class_Initialize
          ItemsVar = Array() ' initialize to empty dynamic array
      End Sub
  
      Function AddLineItem(itemArray, item)
          ReDim Preserve itemArray(UBound(itemArray) + 1)
          itemArray(UBound(itemArray)) = items
          AddLineItem = itemArray
      End Function
  End Class
  
  
      Dim ItemsVar
      Set ItemsVar = new LineItem
  
      ItemsVar.LineNumber = 1
      ItemsVar.ItemCost = 25.00
      ItemsVar.Quantity = 1
      ItemsVar.ItemCode = "42667"
      ItemsVar.ItemDescription = "Software"
  
      Dim OrderVar
      Set OrderVar = New Order
  
      Set OrderVar.Items = ItemsVar
  
      OrderVar.CustomerID = "0937263"
      OrderVar.OrderID = "2348725"
      OrderVar.Email = "nobody@gmail.com"
  
      %&gt;
  
      &lt;%= OrderVar.CustomerID %&gt;&lt;br /&gt;
      &lt;%= OrderVar.OrderID %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Email %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Items.LineNumber %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Items.ItemCost %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Items.Quantity %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Items.ItemCode %&gt;&lt;br /&gt;
      &lt;%= OrderVar.Items.ItemDescription %&gt;&lt;br /&gt;
  </code></pre>