COMException in VBA Collection

Author Topic
cool coder
Member

Joined: 16 Nov 2007
Country:
Posts: 5

Posted: 30 Dec 2008 13:18:57

Hi All,

I am converting a Visual Basic 6.0 application to C#.

I need to use VBA Collection object(that is cliect requirements).But sometimes while getting the items from collection object as "

objCollection.Item(ref objclsBOMPresentations)" ,it is giving COMException.So I need to give one if else block to get the type of the item index.

As you can see in the code,that is hardcoded.So I am giving try catch exception to make the control go on.Please suggest me how can I implement IF-Else here.



object rObj ;

object objcls1 = "cls1 ";
object objcls2 = "cls2";

VBA.Collection objCollection = (VBA.Collection)myToolFrame.ActiveObjects;


try
{
rObj = objCollection.Item(ref objcls1);
m_windowDistributor_ActivateCurrent(ref rObj);
}
catch (COMException exception)
{
//Giving exception here if the item is not cls1 type
}

try
{
rObj = objCollection.Item(ref objcls2);
m_windowDistributor_ActivateCurrent(ref rObj);
}
catch(COMException exception)
{

//Giving exception here if the item is not cls2 type

}




Hi All,

I am converting a Visual Basic 6.0 application to C#.

I need to use VBA Collection object(that is cliect requirements).But sometimes while getting the items from collection object as "

objCollection.Item(ref objclsBOMPresentations)" ,it is giving COMException.So I need to give one if else block to get the type of the item index.

As you can see in the code,that is hardcoded.So I am giving try catch exception to make the control go on.Please suggest me how can I implement IF-Else here.



object rObj ;

object objcls1 = "cls1 ";
object objcls2 = "cls2";

VBA.Collection objCollection = (VBA.Collection)myToolFrame.ActiveObjects;


try
{
rObj = objCollection.Item(ref objcls1);
m_windowDistributor_ActivateCurrent(ref rObj);
}
catch (COMException exception)
{
//Giving exception here if the item is not cls1 type
}

try
{
rObj = objCollection.Item(ref objcls2);
m_windowDistributor_ActivateCurrent(ref rObj);
}
catch(COMException exception)
{

//Giving exception here if the item is not cls2 type

}




Follow us on twitter Subscribe to our RSS feed
Activate your free membership today | Login | Currency