Visual Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 17974
Number of posts: 55343

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
ForEach In Loop throwing exception 424:Object Required Posted by v_vijay12 on 23 Jan 2012 at 11:53 PM
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();

/// <summary>
/// Construcotr, it initializes the collection list
/// </summary>
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<string, IFdtChannel> objDicChannel = new Dictionary<string, IFdtChannel>(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?.



Thread Tree



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.