defining a flexible PROPERTY

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Do UK And AU exposes the same methods ?

See OOP details at :
http://msdn2.microsoft.com/en-us/library/aa711856(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 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.OverloadResolution.PassToParameter(Object Argument, ParameterInfo Parameter, Type ParameterType)
at
Microsoft.VisualBasic.CompilerServices.NewLateBinding.ConstructCallArguments(Method TargetProcedure, Object[] Arguments, BindingFlags LookupFlags)
at
Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method
TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object
Instance, Type Type, String MemberName, Object[] Arguments, String[]
ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean
RValueBase, CallType CallType)
at
Microsoft.VisualBasic.CompilerServices.NewLateBinding.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
 
Back
Top