Looping through IHTMLAttributeCollection in J#.

Looping through IHTMLAttributeCollection in J#.

Post by Bob » Wed, 25 Aug 2004 23:43:53


How can I loop through the IHTMLAttributeCollection in J#.
In C#, I can do it as follows:

IHTMLAttributeCollection myAttrColl =
(IHTMLAttributeCollection) myNode. attributes;
IHTMLDOMAttribute myAttr;

foreach myAttr in myAttrColl
{
if (myAttr.specified) //do something
}

But in J#, there is no foreach loop. Using for loop, I
tried the following:

for (int i=0; i < MyAttrColl.get_length(); i++)
{
myAttr = (IHTMLDOMAttribute) oAttrColl.item(i);
//now do something
}

But the syntax for item method is IHTMLDOMAttribute.item
(ref Object name). Hence, I get an error saying: method
IHTMLDOMAttribute.item(int i) not found.

Can someone please help?

Thanks,
Bob
 
 
 

Looping through IHTMLAttributeCollection in J#.

Post by Bruno Jouh » Fri, 27 Aug 2004 01:56:45

Did you try get_Item(i) ?

Bruno.


513801c489e8$c6eee720$ XXXX@XXXXX.COM ...

 
 
 

Looping through IHTMLAttributeCollection in J#.

Post by diganta.vj » Wed, 01 Sep 2004 16:33:20

The loop needs to change to

1. for (int i = 0; i < myAttrColl.get_length(); i++)
2. {
3. System.Object o = (System.Int32)i;
4. myAttr = (IHTMLDOMAttribute)myAttrColl.item(o);
5. //now do something
6. }

Notice that you cannot directly do the cast "System.Object o =
(System.Object)i", you first need to cast the primitive type 'int' to a
System.Int32 and then to System.Object.

Thanks,
Diganta Roy
Microsoft Visual J# .NET team

--------------------
cpmsftngxa10.phx.gbl!TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12
.phx.gbl