Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

ForEach In Loop throwing exception 424:Object Required

v_vijay12v_vijay12 Posts: 1Member
[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?.



Sign In or Register to comment.