WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE COM ADO CDO ADSI LDAP
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Method with Variant Parameters Explained


Question:

Minor hair-pulling incident last night where I'd done a
TableCollection = br.document.getElementsByTagName("TABLE")

Previously never closed the collection then wasn't able to grab an item in the collection via...

TableCollection.item(ThisNumber)
Later on, it turned out I'm so used to using type-less winbatch that the contents of ThisNumber was a string (like "3")

Peeking at the Object Browser found it was expecting a Variant.

Solved it by using .item(ThisNumber*1.0). However since it was expecting a Variant, and not a floating point, it must have done some conversion. I know you don't have access to all the reasoning behind how MSHTML functions, but just wondering what kind of general logic in this situation ? 20 words or less :)

Answer:

Sorry, no way I can say it 20 words or less.

First, some background. When a method parameter is of type variant, it is usually, but not always, because the parameter can accept more than one type. It may accept more than one type on any given call or it may want different types on different calls based on some internal state. There are other reasons for making a parameter's type variant but I digress.

When WB sees that a parameter has the type of variant, it has no way of know which type of variant to convert the parameter to. So it simple converts the parameter to the variant type that is closest to the existing WIL type.

For example, if you pass 1 as a parameter it is converted to VT_I4 variant. If you pass a "1" it is converted to a VT_BSTR variant.

To get around the method complaining about a type you need to figure out which type of variant the method wants. You can do this by trial and error or, if you are lucky, via written documentation.

Once you have that information you can tell WB which type of variant to use in one of three ways: change the WIL type of the variable being passed as a parameter (only works some of the time); use the ObjectType function to create a variant of the correct type; or specify the correct type in the parameter list of the method.

That syntax for the last approach would look something like this

TableCollection.item(r8:ThisNumber)

I could go on...


Article ID:   W17094
File Created: 2007:07:03:14:28:16
Last Updated: 2007:07:03:14:28:16