Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well basically im having a problem in this line below

CartItem = CType(CartEntry.Value, CartItem)

It says - Unable to cast object of type 'CartItem' to type 'CartItem'.

This is the public cart item coding

Public Class CartItem
    Public Product As Productpage
    Public Quantity As Integer

End Class


and this is my add to cart item class

VB
Private Sub DisplayCart()
        ListBox1.Items.Clear()
        Dim CartItem As CartItem
        Dim CartEntry As DictionaryEntry
        For Each CartEntry In Cart
            CartItem = CType(CartEntry.Value, CartItem)
            ListBox1.Items.Add(CartItem.Display)
        Next
    End Sub


Thanks for help in advance ;-)
Posted

hiyakaru wrote:
Dim CartItem As CartItem

I hope its just a logical error you missed...

you are defining a variable that is same as classname! It should not be done... Try anything other than CartItem as your variable name..

Lets say Go ahead and make as:
VB
Dim myCartItem As CartItem
 
Share this answer
 
v2
hmm i jus tried it , but the same error reappears again,

Unable to cast object of type 'CartItem' to type 'CartItem'.

myCartItem = CType(CartEntry.Value, CartItem)
 
Share this answer
 
Please dont click answer, if not's an answer. Update your question pls.

Now,
hiyakaru wrote:
CartItem = CType(CartEntry.Value, CartItem)


What are you trying to do here? Is the casting correct? Check the classes. Can you convert CartEntry.Value as you are trying to?
 
Share this answer
 
prob solved, i got mixed up with the function names, i shud try to change the function name and class name from now on
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900