[color=Blue][/color]I am using collection from C# to do a ForEach In loop in VB6.The code is as below,
public class DTGFDTCollection : IFdtChannelCollection
{
ChannelEnum channlEnum = new ChannelEnum();
///
/// Construcotr, it initializes the collection list
///
public DTGFDTCollection()
{
}
public void AddChannel(IFdtChannel objChannel, string channelName)
{
channlEnum.AddChannelItems(objChannel, channelName);
}
#region IFdtChannelCollection Members
int IFdtChannelCollection.Count
{
get { return this.channlEnum.objDicChannel.Count; }
}
IFdtChannel IFdtChannelCollection.get_Item(ref object pvarIndex)
{
try
{
if (pvarIndex.ToString().Contains("_"))
{
foreach (string strkey in this.channlEnum.objDicChannel.Keys)
{
if (strkey.Equals(pvarIndex.ToString()))
{
//index = this.objDicChannel.alVariant.IndexOf(Variant);
return (IFdtChannel)this.channlEnum.objDicChannel[strkey];
}
}
}
return null;
}
catch (Exception )
{
return null;
}
}
#endregion #region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator)channlEnum;
}
[DispId(-4)]
public IEnumerator GetEnumerator()
{
return (IEnumerator)channlEnum;
}
#endregion I have implemented the IEnumerator for the ChannelEnum class as below
public class ChannelEnum:IEnumerator
{
internal Dictionary objDicChannel = new Dictionary(3);
string[] strNames = new string[3];
int i = 0;
public void AddChannelItems(IFdtChannel objChannel, string channelName)
{
objDicChannel.Add(channelName, objChannel);
strNames[i++] = channelName;
}
#region IEnumerator Members
int position = -1;
string key;
object IEnumerator.Current
{
get
{
try
{
return objDicChannel[key] ;
}
catch (Exception)
{
throw new InvalidOperationException();
}
}
}
bool IEnumerator.MoveNext()
{
position++;
key = strNames[position];
return (position < objDicChannel.Count);
}
void IEnumerator.Reset()
{
position = -1;
}
#endregion }
Here the AddChannels() is called by other class method and returns the value of type IFdtChannelCollection.I need to do the For Each In loop for this collection in VB6.
If i try to do the foreach for this collection with C# and VB.net, it works fine,but If i try to do the For Each In loop in VB6, after the Current property is called it throws exception 424:Object required. I am clueless what is going wrong here.The Current property returns a valid object ,but still it throws the error.So can anyone help me in this?.