Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is variable name re-use. You're using the same variable name, <code>OrderItem</code>, for two different types here. Although in your mind the variable is scoped to that block, by assigning it a type you've fixed it at the method level.</p> <pre><code>For Each OrderItem As CartProduct In g_objUserShoppingCart.ListOfItems objlist = New CartProduct(Global.OrderItem.TypeOfItem.Product) objlist.ProductId = OrderItem.ProductId arr.Add(objlist) Next For Each OrderItem As CartService In g_objUserShoppingCart.ListOfItems objServiceList = New CartService(Global.OrderItem.TypeOfItem.Service) objServiceList.ServiceName = OrderItem.ServiceName arrService.Add(objServiceList) Next </code></pre> <p>There's two solutions, either drop the type declaration (might not work in older versions of VB) or just rename the loop variable.</p> <p>1)</p> <pre><code>For Each OrderItem In g_objUserShoppingCart.ListOfItems objlist = New CartProduct(Global.OrderItem.TypeOfItem.Product) objlist.ProductId = OrderItem.ProductId arr.Add(objlist) Next For Each OrderItem In g_objUserShoppingCart.ListOfItems objServiceList = New CartService(Global.OrderItem.TypeOfItem.Service) objServiceList.ServiceName = OrderItem.ServiceName arrService.Add(objServiceList) Next </code></pre> <p>2)</p> <pre><code>For Each pOrderItem As CartProduct In g_objUserShoppingCart.ListOfItems objlist = New CartProduct(Global.OrderItem.TypeOfItem.Product) objlist.ProductId = pOrderItem.ProductId arr.Add(objlist) Next For Each sOrderItem As CartService In g_objUserShoppingCart.ListOfItems objServiceList = New CartService(Global.OrderItem.TypeOfItem.Service) objServiceList.ServiceName = sOrderItem.ServiceName arrService.Add(objServiceList) Next </code></pre> <p>A more generic example of your problem is below. This will compile but fail with the same basic error.</p> <pre><code> Dim Ints As New List(Of Integer) Dim Strings As New List(Of String) Ints.Add(1) Strings.Add("Bob") For Each V As Integer In Strings Trace.WriteLine(V) Next For Each V As String In Ints Trace.WriteLine(V) Next </code></pre> <p>Also, while you're in there, change the definition of the sub-classes, there's no need for a caller to even be aware of the enum:</p> <pre><code>Public Class Product Inherits OrderItem Public Sub New() MyBase.New(Global.OrderItem.TypeOfItem.Product) End Sub End Class </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload