value of type sales.cakes cannot be converted to integer

Jamesc

Member
Joined
Oct 26, 2011
Messages
7
Programming Experience
Beginner
I have a project that you enter someone's name, home town and initials saves it to an array which later is produce into a pie chart.
The question is:
The class has one method called addCompetitor that takes String parameters to indicate a name, home town and initials, and an Integer to indicate the position in the tournament. The method creates a Competitor object and stores it in the corresponding element of the position array.

VB.NET:
Public Class Cakes

 Dim position(7) As Integer
    Dim amountSold(7) As Double
    Dim noOfCompetitors As Integer
    


    Public Sub New()
        noOfCompetitors = 0
    End Sub


    Public WriteOnly Property inputSold() As Double
        Set(ByVal value As Double)
            amountSold(noOfCompetitors) = value
        End Set
    End Property


    Public ReadOnly Property getNoOfCompetitors() As Integer
        Get
            Return noOfCompetitors
        End Get
    End Property


    Public ReadOnly Property getCompetitor() As Integer
        Get
            Return position 
        End Get
    End Property




   


[COLOR=#ff0000]    [/COLOR]


    




End Class

Any help?
 
Last edited:
You don't have a storage for Competitor objects, 'position' array is type Integer.
For storage you could use a List(Of Competitor) collection.
 
So what are you asking for help with? I'm guessing you've been given this as an assignment to complete. We get a lot of postings here from visitors wanting their homework completed for them - pretty much all of them get the same response....try to work out the solution yourself, ask for help if you run into a problem.

So, where is your code failing when you try it and what do you need help with?
 
The only part I'm stuck on is.
I keep on getting a blue line and can't figure out why.
The code is meant to save the competitors name, home-town, initials into an arrays along with the position they finished. These are all in-putted via text-boxes.
E.g Tom Smith, Manchester, TM, 3rd also amount of cakes sold. This will then produce a pie or bar chart with the data saved in the arrays.

VB.NET:
[LEFT][COLOR=#FF0000]  Private Sub addCompetitor(ByRef name As String, ByRef country As String, ByRef iocCode As String, ByRef position As Integer)[/COLOR][/LEFT]
[COLOR=#ff0000][COLOR=#333333]        position() = New Competitor(name, homeTown, initials)[/COLOR][/COLOR][COLOR=#ff0000][COLOR=#333333]    
End Sub
[/COLOR][/COLOR]

As the post title says i keep on getting this message and don't know why.
 
I told you why, position array is a storage for Integer values.
 
Lets break this down.

Your array is an integer array. Therefore, it is looking for an integer and is not going to accept anything else.

Your class is an object, not an integer.

You are trying to save an object to an integer array.

It's not going to be accepted.
 
Back
Top