PureBytes Links
Trading Reference Links
|
Hello,
You are correct.
VBScript and VB behaves differently than JScript in this area
and indeed it uses VT_BSTR | VT_BYREF as a variant type
instead of simple VT_BSTR (like JScript).
I will adjust AmiBroker so CStr or () operator is no longer needed.
Thank you for pointing this out.
Best regards,
Tomasz Janeczko
amibroker.com
----- Original Message -----
From: "Email" <romadd64@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Monday, August 18, 2003 4:52 PM
Subject: [amibroker] Re: Help with ActiveX component (PLEASE TOMASZ READ THIS)
> Thanks Gordon,
>
> I think to have found where it's the problem (I'm sorry if it's too
> much technical):
>
> When VB pass a VARIANT parameter to an automation method, if possible
> it passes the parameter by REFERENCE (like pointers in C), otherwise
> it passes by VALUE. String variables are passed by reference.
> TJ's code expect only the parameter by VALUE, so
> the VariantChangeType failed the conversion. String constants (like
> the result of a CStr) are passed by value, so it works. You can
> obtain the same result using the () operator, that converts a value
> to a constant, so it's passed by value. The call could be like this
> (look at the innatural double (), the inner is the () operator):
>
> Set oStk = oStocks.Item((Ticker))
>
>
> You can see this Microsoft's document (it refers to VB 4, by I think
> that it's the same for other versions) :
> http://support.microsoft.com/default.aspx?scid=kb;en-us;142223
>
> I think that TJ should modify Amibroker's code (it's explained at the
> above link) to get over this problem, that surely will happen again
> to others.
>
>
> Regards,
>
> romadd64
>
>
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Gordon" <amibroker@xxxx> wrote:
> > Hi,
> >
> > Snip from 45607:
> >
> >
> > ***************
> > The CSTR thing was mentioned by TJ to me:
> >
> > As for this CStr(): the real reason for such strange behaviour is
> > that Stocks.Item( ticker) accepts VARIANT
> > as a TICKER. This is so to allow the user to reference ticker by
> both
> > number and symbol.
> > As you probably know Variant can hold any type.
> >
> > AmiBroker does the following:
> > struct StockInfo * AStocks::FindStockInfoByVariant(const VARIANT
> > &Item)
> > {
> > struct StockInfo *si = NULL;
> >
> > if (Item.vt == VT_BSTR)
> > {
> > si = FindStock( CString( Item.bstrVal ) ) ;
> > }
> > else
> > {
> > // coerce to VT_I4
> > VARIANT va ;
> > VariantInit( &va );
> > if (SUCCEEDED(VariantChangeType( &va, (VARIANT FAR*)&Item,
> 0,
> > VT_I4 )))
> > {
> > si = StockInfoFromIndex( (int)va.lVal );
> > }
> > }
> >
> > return si;
> > }
> >
> > - it checks if variant is of string type (VT_BSTR) and then treats
> it
> > as a symbol,
> > otherwise it tries to coerce it to the 32bit integer index (this is
> > because numbers passed in variant
> > may be floats R4, real R8, short, long integers, etc).
> >
> > Strangely enough if you do not use explicit conversion VB puts some
> > strange variant (I didn't checked it yet it is)
> > instead of simple string as anyone may think.
> > ***********
> >
> > - Gordon
> >
> > --- In amibroker@xxxxxxxxxxxxxxx, "Email" <romadd64@xxxx> wrote:
> > > Gordon,
> > >
> > > I have searched for CStr, but I haven't seen messages from Tomasz
> > > about that (beyond the message on this thread).
> > > Can you kindly show me that message ?
> > >
> > > Thanks, romadd64
> > >
> > >
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Gordon" <amibroker@xxxx> wrote:
> > > > This is explained just a few days ago. It basically has to do
> > with
> > > > the fact that the collection takes a string or number as the
> key.
> > A
> > > > search in the newsgroup on CStr should get you to Tomasz'
> precise
> > > > explanation.
> > > >
> > > > Gordon
> > > >
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Email" <romadd64@xxxx> wrote:
> > > > > Tomasz,
> > > > >
> > > > > why we must convert the var Ticker (it is already a string
> > type),
> > > > to
> > > > > another string via CStr ?
> > > > >
> > > > >
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "au99991" <auttley@xxxx>
> > wrote:
> > > > > > Tomasz,
> > > > > >
> > > > > > Your experience is as invaluable as ever! Many thanks.
> > > > > >
> > > > > > Andy.
> > > > > >
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko"
> > > > > <amibroker@xxxx>
> > > > > > wrote:
> > > > > > > Hello,
> > > > > > >
> > > > > > > You have to call CStr as follows:
> > > > > > >
> > > > > > > Set oStk = oStocks.Item( CStr( Ticker ) )
> > > > > > >
> > > > > > > Best regards,
> > > > > > > Tomasz Janeczko
> > > > > > > amibroker.com
> > > > > > > ----- Original Message -----
> > > > > > > From: "au99991" <auttley@xxxx>
> > > > > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > > > > Sent: Saturday, August 09, 2003 1:10 PM
> > > > > > > Subject: [amibroker] Help with ActiveX component
> > > > > > >
> > > > > > >
> > > > > > > > I'm trying to access the Amibroker object collection
> from
> > a
> > > > VB
> > > > > > > > activex function. Please ignore what the function is
> > > doing -
> > > > > I'm
> > > > > > > > just trying to get the basic function-calling correct.
> > > > > > > >
> > > > > > > > The function in VB reads:
> > > > > > > >
> > > > > > > > Public Function StockFN() As Variant
> > > > > > > >
> > > > > > > > Dim Ticker As String, oAB As Object, oStocks As
> > Object,
> > > > > oStk
> > > > > > As
> > > > > > > > Object
> > > > > > > >
> > > > > > > > Set oAB = CreateObject("Broker.Application")
> > > > > > > >
> > > > > > > > Ticker = oAB.ActiveDocument.Name
> > > > > > > >
> > > > > > > > Set oStocks = oAB.Stocks
> > > > > > > >
> > > > > > > > Set oStk = oStocks.Item
> > (Ticker) '!!
> > > > > Error
> > > > > > line
> > > > > > > >
> > > > > > > > StockFN = oStk.Fullname
> > > > > > > >
> > > > > > > > End Function
> > > > > > > >
> > > > > > > > I call it in a guru commentary with the following code:
> > > > > > > > myAB = CreateObject("MyAB.Common");
> > > > > > > > myAB.StockFN();
> > > > > > > >
> > > > > > > > This gives an 'Object variable not set error' in VB.
> > > > However,
> > > > > I
> > > > > > know
> > > > > > > > that the Ticker variable is correctly loaded and if I
> > > replace
> > > > > > Ticker
> > > > > > > > for a hardcoded ticker value in the error line above,
> the
> > > > > > function
> > > > > > > > returns a value albeit obviously for the hardcoded
> ticker
> > > > > value.
> > > > > > > > Would much appreciate a pointer on what I'm doing wring
> > as
> > > > I'm
> > > > > > > > getting no where!
> > > > > > > >
> > > > > > > > Many thanks
> > > > > > > >
> > > > > > > > Andy.
> > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > Send BUG REPORTS to bugs@xxxx
> > > > > > > > Send SUGGESTIONS to suggest@xxxx
> > > > > > > > -----------------------------------------
> > > > > > > > Post AmiQuote-related messages ONLY to:
> > > > > amiquote@xxxxxxxxxxxxxxx
> > > > > > > > (Web page:
> > http://groups.yahoo.com/group/amiquote/messages/)
> > > > > > > > --------------------------------------------
> > > > > > > > Check group FAQ at:
> > > > > > http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> > > > > > > >
> > > > > > > > Your use of Yahoo! Groups is subject to
> > > > > > http://docs.yahoo.com/info/terms/
> > > > > > > >
> > > > > > > >
> > > > > > > >
>
>
>
> Send BUG REPORTS to bugs@xxxxxxxxxxxxx
> Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
> -----------------------------------------
> Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
> (Web page: http://groups.yahoo.com/group/amiquote/messages/)
> --------------------------------------------
> Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
|