Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading a property that takes an argument? 1

Status
Not open for further replies.

EvanK

Technical User
Nov 18, 2003
21
I'm just getting back into using VB6 after a very long time, and am working with the iTunes COM interface...I'm having trouble getting an object reference from a property, because the property takes an index and I guess I'm writing it as method.

The object browser gives me a property, and it takes an index:

Code:
Property Item(Index As Long) As IITSource
    read-only
    Default member of iTunesLib.IITSourceCollection
    Returns an IITSource object corresponding to the given index (1-based).

I can get a reference to the parent object just fine:
Code:
Dim Collection as IITSourceCollection
Set Collection = iTunesApp.Sources

But reading from the property with an argument (the index):
Code:
Dim SourceObj as IITSource
SourceObj = Collection.Item(1)

throws the error "Invalid procedure call or argument". am I just missing something obvious?

I would appreciate any help anyone could give me, thanks for taking the time to read this!
 
It probably needs to be a Function (i.e. Method) rather than a property.

The format for a Property definition is
Code:
Property Let PropertyName(x As SomeDataType)
or
Code:
Property Set PropertyName(x As SomeDataType)
or
Code:
Property Get PropertyName() As SomeDataType
Your code has both a calling argument and a return type that's not compatible with its being a property.
 
No, it is definately a property, as this screenshot from the object browser shows:

Keep in mind, this isn't something I built and can change, this is the public API for iTunes. Could the property perhaps be returning some kind of array or enumeration that i then need to supply an index to? If so, what would the syntax be to access an individual element?
 
Try this:
Code:
Dim SourceObj as IITSource
[COLOR=red]Set[/color] SourceObj = Collection.Item(1)

Also, is the collection zero-based or one-based?

 
gah, that was it! thanks a bunch. (its 1-based, by the way)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top