473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1648
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Harry Pehkonen | last post by:
I have been defining new class methods when I'm trying to simplify some code. But I'm thinking I should just define functions within that method because they aren't useful from the outside anyway....
0
by: Dotnetified | last post by:
Reposting after about 2 weeks of no response ... thanks if you can help... ---------------------------------------------------------------------------- -------------- To anyone who thinks they...
12
by: Matt Garman | last post by:
I'd like to create a "custom output facility". In other words, I want an object whose use is similar to std::cout/std::cerr, but offers more flexibility. Instead of simply writing the parameter...
19
by: mehdi.louizi | last post by:
Hello, I'm beginning to create a web site but I'm facing a big problem for which I didn't find any solution!! I'm using the 1024*768 screen resolution, and when I change it to 800*600 the page is...
10
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
16
by: Howard Jess | last post by:
All -- I'm trying to solve a problem for which I think the solution will be to *cheat*; but I don't mind doing so for this case. The background is: Given an object constructor, and an instance...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
0
by: DFS | last post by:
Probably someone else has done this, but I figured out a flexible way to use the Leban's calendar, such that you don't have to write code in the DblClick event each time you want to use the...
0
by: =?Utf-8?B?Z2FkeWE=?= | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.