开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: Help for an old coder. API 10.17 Bar class.


 

开云体育

Sorry Carlos, I’ve been through all this before but I’d forgotten how to do this.

?

IB’s handling of the decimal problem in the ActiveX API is sadly lacking. It has to be supplemented by additional functions which should be in the API but aren’t. If you look at the VBA code in the Excel ActiveX demo, you’ll find a code module called Utils.bas that has a couple of relevant functions, in particular one called SetVariantDecimal. This that takes a string and returns the required object to use in properties like totalQuantity.

?

The following function is based on that, but I think it’s better named and is more applicable because it can take any variant as an argument:

?

Public Function CreateDecimalObject(value As Variant) As Object

??? Dim collection As New collection

??? collection.Add CDec(value)

??? Set CreateDecimalObject = collection

End Function

?

Ideally you’d add this function to a module (not a class module) so that it would be accessible everywhere within your code. But if you only need it within a single class, you could just add it to that class (in which case it should be Private rather than Public).

?

So now your failing piece of code would look like this:

?

??????? O.totalQuantity = CreateDecimalObject(quantity)

?

?

[Comment: if you think this CreateDecimalObject function looks very strange, you’re right! I modified IB’s API code to use a new class called BoxedDecimal, so that everywhere where IB has a Variant to hold a size value, there is instead a BoxedDecimal instead: this is much more documentary, because you can see exactly what you’re dealing with without having to guess. It also makes the ActiveX API much easier to use from C# or Visual Basic .Net. I offered this to IB as an improvement? (see if you have access to the API repository), but they have shown no interest…]

?

?

From: [email protected] <[email protected]> On Behalf Of carlos via groups.io
Sent: 18 August 2022 15:00
To: [email protected]
Subject: Re: [TWS API] Help for an old coder. API 10.17 Bar class.

?

Hi Richard,

Yesterday after I email here I found this option and try that.

The same error happens
O.totalQuantity = CDec(quantity)
returns

Run-time Error '424'

Object required

Somehow I need to create an object that is a C# decimal or so.

If you guys have any other ideas let me know.

Thank you very much for all the help.

Carlos

Join [email protected] to automatically receive all group messages.