[Gambas-user] _compare() Type mismatch: wanted Date, Number or String
Fabien Bodard
gambas.fr at ...626...
Thu Aug 2 10:15:42 CEST 2012
Just add a Value to each card
if hplaingCard.Value > hPlayingCard2.Value
'To declare them (class CCard)
What is a card ?
Public Id as integer
Public Value as integer
Public {Picture} as Picture
So to load them
(32 card)
Private AllCards as CCard[]
public sub Main
dim hCard as CCard
dim v as integer
For i = 0 to 31
hCard = new CCard
hCard.Id = i
'here i manage the 7 cards value
hCard.Value = v
inc v
if v > 6 then v=0.
'
hCard.Picture = Picture.Load("img/card & i & ".png")
allCard.Add(hCard)
next
end
then you can compare by comparing value
2012/7/31 Tobias Boege <tobiasboege01 at ...1601...>
> On Tue, 31 Jul 2012, Patrik Karlsson wrote:
> > I'm writing a class for Playing cards and would like to compare them
> with:
> > =,<,>.
> >
> > While hPlayingCard1=hPlayingCard2 works just fine,
> > hPlayingCard1<hPlayingCard2 and hPlayingCard1>hPlayingCard2 do not.
> >
> > The program stops with:
> > #6: Type mismatch: wanted Number, Date or String, got PlayingCard instead
> >
> > My _compare is simple:
> > Public Function _compare(OtherObject As PlayingCard) As Integer
> >
> > Return 0
> >
> > End
> >
> > What can I do to make comparing with <,> possible?
> >
> > /patrik
>
> If I got the documentation[0] right, the <,> are only valid for the native
> classes you are given in the error message: Number, Date, String.
> It is also said[1] that _compare() is used for sorting arrays of objects on
> a class or finding those. It could likely mean - ignoring the "for example"
> in that sentence - that these arithmetic operators are not related to the
> _compare() method.
>
> IIRC, there was discussion[2] about a new special method _operator() on the
> gambas-devel list which will enable you to use any operator on a _native
> class_. Actually, this seems to be implemented in the gb.gsl classes
> already. I don't know if it is intended for classes written in Gambas, too.
> At least, there is no documentation about it (at the usual place) and the
> commit messages didn't show me anything.
>
> [0] http://gambasdoc.org/help/cat/arithop?v3
> [1] http://gambasdoc.org/help/lang/special/compare?v3
> [2] http://old.nabble.com/About-gb.gsl-components-td34130245.html
>
> Regards,
> Tobi
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
--
Fabien Bodard
More information about the User
mailing list