469,923 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

defining a flexible PROPERTY

I use one of 2 arrays dependent on the country.

Rather than say:
if exchangeID = 1 then
dim myPlaceBets() as As UK.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
else
dim myPlaceBets() As AU.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
end if

I want to say is something like this:

Public Property myPlaceBets() As
BF4_1_rel_13_4.betfair.UK.exchange.PlaceBets OR as
BF4_1_rel_13_4.betfair.AU.exchange.PlaceBets

Not being able to do this I said

Public Property myPlaceBets() As Object

Defining the property as Object, while the correct array is returned, it
fails in use with the message:

Conversion from type 'Object()' to type 'PlaceBets()' is not valid. Here's
the Property.

Private _myPlaceBetsUK(-1) As UK.exchange.PlaceBets
Private _myPlaceBetsAU(-1) As AU.exchange.PlaceBets
Private _PlaceBets() = {_myPlaceBetsUK, _myPlaceBetsAU}

Public Property myPlaceBets() As Object
Get
Return _PlaceBets(exchangeId - 1)
End Get
Set(ByVal Value As Object)
_PlaceBets(exchangeId - 1) = Value
End Set
End Property

Any help would be appreciated.

Gadya
Mar 8 '07 #1
2 1428
Do UK And AU exposes the same methods ?

See OOP details at :
http://msdn2.microsoft.com/en-us/lib...56(VS.71).aspx (in particular
4.3/4.5 or 4.4).

Basically 4.3 is :
- your classes share come common code. You use an Ancestor class that
implements common behavior. The UK and AU inherits from this common ancestor
their common behavior and can specialize themselves. Using an As Ancestor
array you'll be able to use either UK and AU (as you have the guarantee that
methods exposed by thr Ancestor are also available in UK /AU as they inherit
from Ancestor).

If they have nothing related but still exposes the same classe methodfs you
could see 4.4 that sjust allows to guarantee that they both exposes the same
methods. You can then use an As IMyInterface array.

This is the a very qucik overview. Your best bet is to read on a tutorial
about OOP.

--
Patrice

"gadya" <ga***@discussions.microsoft.coma écrit dans le message de news:
08**********************************@microsoft.com...
>I use one of 2 arrays dependent on the country.

Rather than say:
if exchangeID = 1 then
dim myPlaceBets() as As UK.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
else
dim myPlaceBets() As AU.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
end if

I want to say is something like this:

Public Property myPlaceBets() As
BF4_1_rel_13_4.betfair.UK.exchange.PlaceBets OR as
BF4_1_rel_13_4.betfair.AU.exchange.PlaceBets

Not being able to do this I said

Public Property myPlaceBets() As Object

Defining the property as Object, while the correct array is returned, it
fails in use with the message:

Conversion from type 'Object()' to type 'PlaceBets()' is not valid. Here's
the Property.

Private _myPlaceBetsUK(-1) As UK.exchange.PlaceBets
Private _myPlaceBetsAU(-1) As AU.exchange.PlaceBets
Private _PlaceBets() = {_myPlaceBetsUK, _myPlaceBetsAU}

Public Property myPlaceBets() As Object
Get
Return _PlaceBets(exchangeId - 1)
End Get
Set(ByVal Value As Object)
_PlaceBets(exchangeId - 1) = Value
End Set
End Property

Any help would be appreciated.

Gadya


Mar 8 '07 #2
Patrice thanks for your reply.

Do UK And AU exposes the same methods ?

Yes, they do.

As to ancestors; they both inherit from system.object
Firstly here are the properties

' an arrray of bets
Private _myPlaceBetsUK(-1) As BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets
Private _myPlaceBetsAU(-1) As BF4_1_rel_13_4.betfair.au.exchange.PlaceBets
Private _PlaceBets() = {_myPlaceBetsUK, _myPlaceBetsAU}

Public Property myPlaceBets() As Object()
Get
Return _PlaceBets(exchangeId - 1)
End Get
Set(ByVal Value As Object())
_PlaceBets(exchangeId - 1) = Value
End Set
End Property

' a single bet

Private _PlacebetsUK As New BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets
Private _placebetsAU As New BF4_1_rel_13_4.betfair.au.exchange.PlaceBets
Private Placebet() = {_PlacebetsUK, _placebetsAU}
Public Property myPlaceBet()
Get
Return Placebet(exchangeId - 1)
End Get
Set(ByVal Value)
Placebet(exchangeId - 1) = Value
End Set
End Property

' a betting request

Private _myPlaceBetsReqUK As New betfair.uk.exchange.PlaceBetsReq
Private _myPlaceBetsReqAU As New betfair.au.exchange.PlaceBetsReq
Private _PlaceBetsReq() = {_myPlaceBetsReqUK, _myPlaceBetsReqAU}

Public Property myPlaceBetsReq()
Get
Return _PlaceBetsReq(exchangeId - 1)
End Get
Set(ByVal value)
_PlaceBetsReq(exchangeId - 1) = value
End Set
End Property

Here is the code:

ReDim Preserve myPlaceBets(betCount)
myPlaceBets(betCount) = myPlaceBet

myPlaceBets(betCount).price = myOdds
Here's the result
- myPlaceBets(betCount).price 1.01 {Double} Object
+ Double 1.01 {Double} Double

the next statement FAILS
myPlaceBets(betCount).price =
Decimal.Parse(myPlaceBets(betCount).price.ToString ("#0.00"))

Here's the error message
System.FormatException: Input string was not in a correct format.
at Microsoft.VisualBasic.CompilerServices.Conversions .ParseDouble(String
Value, NumberFormatInfo NumberFormat)
at Microsoft.VisualBasic.CompilerServices.Conversions .ToInteger(String
Value) 08/03/2007 14:59:45 487
Having continued and entered the bet parameters they can be seen here:
- myPlaceBets {Length=1} Object()
- (0) {BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets} Object
- BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets {BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets} BF4_1_rel_13_4.betfair.uk.exchange.PlaceBets
asianLineId 0 Integer
asianLineIdField 0 Integer
betType L {1} uk.exchange.BetTypeEnum
betTypeField L {1} uk.exchange.BetTypeEnum
marketId 20001695 Integer
marketIdField 20001695 Integer
price 1.01 Double
priceField 1.01 Double
selectionId 2002335 Integer
selectionIdField 2002335 Integer
size 2.0 Double
sizeField 2.0 Double

Executing the next statment moving the bet into the request:

myPlaceBetsReq.bets = myPlaceBets

we get the following error:

Conversion from type 'Object()' to type 'PlaceBets()' is not valid.
at Microsoft.VisualBasic.CompilerServices.Conversions .ChangeType(Object
Expression, Type TargetType)
at
Microsoft.VisualBasic.CompilerServices.OverloadRes olution.PassToParameter(Object Argument, ParameterInfo Parameter, Type ParameterType)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.ConstructCallArguments(Method TargetProcedure, Object[] Arguments, BindingFlags LookupFlags)
at
Microsoft.VisualBasic.CompilerServices.Symbols.Con tainer.InvokeMethod(Method
TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateSet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean
RValueBase, CallType CallType)
at
Microsoft.VisualBasic.CompilerServices.NewLateBind ing.LateSetComplex(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean
RValueBase)
at BF4_1_rel_13_4.mainForm.EnterBtn_Click(Object sender, EventArgs e) in
C:\Documents and Settings\victor sperber\Desktop\BF
API5\BFAustralia\BF4_1_rel_13_4\mainform.vb:line 5832
Gadya

"Patrice" wrote:
Do UK And AU exposes the same methods ?

See OOP details at :
http://msdn2.microsoft.com/en-us/lib...56(VS.71).aspx (in particular
4.3/4.5 or 4.4).

Basically 4.3 is :
- your classes share come common code. You use an Ancestor class that
implements common behavior. The UK and AU inherits from this common ancestor
their common behavior and can specialize themselves. Using an As Ancestor
array you'll be able to use either UK and AU (as you have the guarantee that
methods exposed by thr Ancestor are also available in UK /AU as they inherit
from Ancestor).

If they have nothing related but still exposes the same classe methodfs you
could see 4.4 that sjust allows to guarantee that they both exposes the same
methods. You can then use an As IMyInterface array.

This is the a very qucik overview. Your best bet is to read on a tutorial
about OOP.

--
Patrice

"gadya" <ga***@discussions.microsoft.coma écrit dans le message de news:
08**********************************@microsoft.com...
I use one of 2 arrays dependent on the country.

Rather than say:
if exchangeID = 1 then
dim myPlaceBets() as As UK.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
else
dim myPlaceBets() As AU.exchange.PlaceBets
many statements
myPlaceBetsReq.bets = myPlaceBets
end if

I want to say is something like this:

Public Property myPlaceBets() As
BF4_1_rel_13_4.betfair.UK.exchange.PlaceBets OR as
BF4_1_rel_13_4.betfair.AU.exchange.PlaceBets

Not being able to do this I said

Public Property myPlaceBets() As Object

Defining the property as Object, while the correct array is returned, it
fails in use with the message:

Conversion from type 'Object()' to type 'PlaceBets()' is not valid. Here's
the Property.

Private _myPlaceBetsUK(-1) As UK.exchange.PlaceBets
Private _myPlaceBetsAU(-1) As AU.exchange.PlaceBets
Private _PlaceBets() = {_myPlaceBetsUK, _myPlaceBetsAU}

Public Property myPlaceBets() As Object
Get
Return _PlaceBets(exchangeId - 1)
End Get
Set(ByVal Value As Object)
_PlaceBets(exchangeId - 1) = Value
End Set
End Property

Any help would be appreciated.

Gadya


Mar 8 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Harry Pehkonen | last post: by
12 posts views Thread by Matt Garman | last post: by
19 posts views Thread by mehdi.louizi | last post: by
10 posts views Thread by Adam Warner | last post: by
16 posts views Thread by Howard Jess | last post: by
26 posts views Thread by Cliff Williams | last post: by
reply views Thread by =?Utf-8?B?Z2FkeWE=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.