COMException in VBA Collection

Dec 30 2008 5:58 AM
 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                          

                          }