Getting An Error With  A For....Each Loop For A Collection Class?

Sep 1, 2010

I decided to go back to the VB6 book, "Learn to Program Visual Basic Objects", so I can code it in VB2010. This has been a great learning experience. However I've run into a problem. I'm getting an error with a For....Each loop for a collection class. The error message states, Expression is of type 'China.Order', which is not a collection type." From what I've deduced the problem deals with an enumerator. I could be wrong.

View 2 Replies


ADVERTISEMENT

For Each Loop Error: Collection Was Modified; Enumeration Operation Might Not Execute

Oct 15, 2011

I am encountering an error when looping through datarows. I searched SO and tried the solutions, but no luck. Collection was modified; enumeration operation might not execute.

Dim dRow As DataRow
For Each dRow In dt.Rows
dt.Rows.Add(dRow("CustNum"), dRow("SalesRepName"), dRow("mgrid"), "=""" & dRow("midValue") & """", dRow("dba"), dRow("sysDate"), dRow("statusID"))
Next

The error occurs the first time the code hits "Next". What would be causing Collection was modified; enumeration operation might not execute.How can I resolve this error?

View 2 Replies

C# - Edit List Collection : Error Note Collection Was Modified - Enumeration Operation May Not Execute?

Sep 7, 2011

I have the following classes:

Product, Service and OrderItem

Product and Service must inherit OrderItem. So basically I want to store OrderItem object in my shopping cart and these object are store in a list.

Public MustInherit Class OrderItem
Private m_enuItemType As TypeOfItem = TypeOfItem.None
Private m_strUserID As Integer[code].....

View 1 Replies

Adding A List (of Class) Or Collection As Another Class's Property

Apr 2, 2010

I'm looking for a tutorial on how to Adding a list(of Class) or Collection as another Class's Property.What I am after is something like the Columns Collection for the DatagridView control.I would like to add Items in the graphics screen. Where the item list is displayed in the left panel and the selected Item properties are displayed in the right panel.

View 4 Replies

Base Class Collection With Sub Class Objects

Jul 19, 2010

[code]The reason that this is a problem is that this is a collection of EventBase objects, but I'm trying to populate it with child classes instead. For example, I might have a JumpEvent class that inherits EventBase, and this is being put into the EventBaseCollection. That means that value.GetType() returns the type of JumpEvent, which as you might guess does not equal the type of EventBase.The goal of course is to simply loop through all of the various events without having to know anything about the sub-classes. Is there a way to determine the type of the base class so that the OnValidate call will work? Or is this just the wrong way to go about it altogether?

View 2 Replies

Passing List / Collection From Class To Class

Apr 28, 2009

I seem to have problem with passing a collection/sorted list/ list of strings from one class to another.I am using property procedure to pass it, however nothing is sent to another class. There isn't any error messages either.[code]

View 3 Replies

.net - Changing A Collection From Within A Loop?

Apr 13, 2010

I have a simple Dictionary(of String, Object) that I need to iterate through and change items depending on some conditions.As I can't modify a collection that I'm iterating through, how do I achieve this?For example, the following obviously causes an Invalid Operation Exception:

Dim mOptions As New Dictionary(of String, Object)
mOptions.Add("optA", "A")
mOptions.Add("optB", "B")
mOptions.Add("optC", "C")

[code]....

View 3 Replies

Loop Through A Collection Of Controls?

Feb 24, 2010

Im trying to loop through a collection of controls see code:

Private Sub addZeros()
For Each ctrl As Control In Me.Controls
If TypeOf ctrl Is GroupBox Then

[Code]....

View 4 Replies

Loop Through Object Collection

Jan 5, 2011

In an application I am working on I have created a product class which represents an inventory item. I have also created an inventory class which represents a collection of product objects. In the constructor of the Inventory class I load 4 products into a product collection. Each product consists of a code, description price and quantity.

[Code]...

View 3 Replies

Wpf - Loop Through A Xml And Add Data To Collection

Feb 9, 2012

I'm trying to just iterate through this xml and grab all of its data and add it to my collection(_personOC). Right now it's not working. How can I do this without having to specify the id? All I did was make a dataset with a person table and saved it as a xml.

Public Property personOC As ObservableCollection(Of Person)
Get
Return _personOC

[Code]....

View 1 Replies

How To Loop Through DGV Selected Rows Collection

Apr 1, 2009

how to loop through DGV selected rows collection?

View 2 Replies

Loop Through A Collection Object In VB 2010

Aug 30, 2010

I'm trying to loop through a collection object in vb2010.The code was originally used in Vb6 The book said that I needed to code a NewEnumerator method first in order to be able to loop through my collection. I coded the following:

[code]...

It gives an error for IUnknown, staging that IUnknown is not accessible in this context because it is a 'Friend'.In the line in the function I removed the Set since it's no longer needed.The error message for this line is '_NewEnum' is not a member of 'Microsoft.VisualBasic.Collection'What are these messages and how do I fix this in VB 2010?m_colCourse is not a system collection.

View 1 Replies

VS 2005 Loop Through Collection Of Collections

Jul 23, 2009

I have a Collection, the keys are strings and the values are Collections. In the sub Collections the keys are strings and values are Singles/Floats. How would I loop through all of the data? I need to get the keys and values not just the values. I've tried this but it produces a cast error:

[Code]...

View 3 Replies

VS 2008 Can't Loop Through Items In A Collection

Apr 15, 2010

CAUTION: Noob using Win32 API ahead

I want to display a list of open windows on my computer in a rich text box. So, I'm trying to store the names of all windows in myString, and then set RichTextBox1.Text = myString.

Here's the code

Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

[Code].....

View 15 Replies

Infinite Loop When Json Serializing A Collection

Sep 1, 2010

I am trying to use a Web Service to return Json for a Collection of Users from a Database Table. I'm only new to .NET (< 1 week experience), and I don't want to use the UpdatePanel for AJAX. I have tried using the JavaScriptSerializer as well as Json.NET to serialize. Both cases seem to spawn an Infinite Loop.[code]

View 1 Replies

Listbox: Only Loop Through SELECTED Values Collection

Mar 17, 2009

Is there a way to to combine line's 1 and 2? I only want to loop through a list of the selected items in this listbox. This works just fine, I just wondered if there was a collection of selected values returned that I could use to avoid having to do it this way.

For Loop1 = 0 To MyListBox.Items.Count - 1
If MyListBox.Items(Loop1).Selected = True Then
...
End
Next

View 2 Replies

VS 2005 Erasing Items In A Collection Using A Loop?

Jul 1, 2009

I often use a for/next loop to cycle through a collection to find a particular member of that collection based on some criteria. This works fine in every case except one: when I want to then erase the very member of the collection I just found. For example, if I wanted to give the heave-ho to every obect in a collection class that has a member veriable Color equal to Red:

[Code]...

The problem is once the collection class member is erased it makes to loop invalid because taking out the member reduces the total count of the collection in the middle of the loop. Eventually I get a "Index is out of range" error.This circumstance has bothered me every so often; I bet more experienced programmers have a different type of loop system that works better than this when you want to erase a collection member.

View 2 Replies

Foreach - .NET For Each Steps Into Loop Body For An IEnumerable Collection?

Mar 11, 2010

This is weird. I have a class that inherits from IEnumrable whose Count property is reporting 0 (zero) elements but the For Each loop steps into the loop body and tries to use the variable where it should just be moving on. My code:

On Error Resume Next
Dim d As Foo
For Each d In fooCollection
' use d and throws an exception
Next d

Weirder still, every time d is accessed i get an exception thrown in the output window:

A first chance exception of type 'System.NullReferenceException'

but i'm not stopping on the exception (not in a try/catch block).Is "On Error Resume Next" causing this weirdness?

Weirdness found:Per Rowland's and JohnH's comments i checked the Foo class:The GetEnumerator method inside of Foo didn't actually return anything! It had an empty body. That coupled with the On Error Resume Next before the loop caused the havoc! Wow this was ugly.

View 3 Replies

Saving Items In A Collection To A Database Using A Loop Function?

May 12, 2011

I would like to be able to save to a db and send task to email or as text msg for instance nevermind that.. I have two variables of type ArrayList they are "_mList1" , "_mList2" and "_mList3"

_mList1 stores the list of Telephonenumbers , _mList2 stores the list of StaffIDs and _mList3 Some concatenated string.

theses variable lists will hold some data in runtime as explained and i would like to use them to populate a DB table again mentioned

tblTask (TaskID(PK), Action, StaffID(FK), AssignedBy, TelephoneContacted, NotesCotent)
tblStaff (StaffID(PK), FirstName, Surname, Telephone, Address etc..)

[Code]....

View 1 Replies

VS 2005 - Controlcollection - Make A Collection Of Controls That I Can Loop Through

Mar 2, 2010

I am trying to make a collection of controls that I can loop through. So I have this code in my form... Dim WizardFrameCollection As New Control.ControlCollection(Nothing)

I then try to add controls to the collection by I get a error "Object reference not set to an instance of an object." WizardFrameCollection.Add(Me.GroupBox1) I am not sure why I am getting this error. Groupbox1 is a groupbox that is on the form.

View 2 Replies

Bug In Collection Class VB?

Aug 16, 2009

The following code creates a Collection where every Item is assigned a value equal to the last item added. At the end of adding for example seven items all the entries are identical to the last one added, although each has the correct key

The parameter passed to the function - aCOA() - is a comma delimited string of three strings.

The code is as follows
Public Function myCOA(ByVal aCOA() As String)
Dim thisCOA As New Collection
Dim keyCOA As String

[Code]....

Is this a bug in the code or in the Collection Class. I have traced the operation of the code and all seems OK until the second entry is added at which time the first entry Item get the same value as the second entry Item and so on.

View 2 Replies

Collection, Class .. Which Is Best For Example

May 25, 2009

I have worked some with classes and collections in the past but seek some direction before I start on this project as to the best method to use.I will be reading 20,000 or so lines from a text file. partno, desc and loc Each will contain 3 elements to be collected and stored temporarily.There are 2 results that I desire that relates to selling of products

First Result: Sorted list of most used partno, desc
2,234 partno (most sold)
1,345 partno (2nd most popular)
etc.

2nd Result: Sorted list by specific loc., partno, desc
loc. 45 - 234ea partno, desc
loc. 45 - 143ea partno, desc

Maybe end up with the top 500 selling products in the list. This data will then be added to a dataviewgrid for printing and then deleted.So, to temporary store and sort should I use some type of collection or classes? I know how to fight my way to either but which would be the best method?

View 3 Replies

Composite Key With Class Collection?

Jun 17, 2011

I want to be able to get an instance of a class based on two fields in that class. I was hoping to use something like a dictionary, because I thought indexing would be the best for performance. Should I just use LINQ or go back to a strongly typed dataset? Here's an example of what I'm trying to do[code]...

View 2 Replies

.net - Set An Incrementing ID Property To A Class' Collection?

Nov 15, 2011

I have some nested objects arranged like this:

Process
Persons
Workflows
Tasks

So you have one Process. Then multiple Persons can be added to and multiple WorkFlows can be added Process as well. Multiple Tasks can be added to each WorkFlow but I need a way to tie which Person is doing each task. I basically need a way that for each Person added to the Process it, in it's constructor, assigns a Person.ID property that can then be assigned into each Task's PersonID property...

Dim myProcess as New Process()
Dim myPerson as New Process.Person()
myProcess.AddPerson(myPerson)

[code]....

View 2 Replies

2010 Collection Class Oddity

Sep 28, 2010

I converted a project from 2008 to 2010 to be able to use the TPL.I've updated the compile target to .NET 4. Everything seems good, including the .NET 4 specific TPL stuff...except that:[code]

View 7 Replies

A Property In A Class Is A Collection Of Objects

Jan 29, 2009

Thought I had got this sorted earlier but unfortunately not. A property in a class is a collection of objects.

[Code]...

View 4 Replies

Retrieve A Property Of A Class As A Collection?

May 26, 2012

I'm working on a small project and got into some troubles trying to keep it OOP.I have a global variable:

Public Stations As New Microsoft.VisualBasic.Collection()
And 2 classess: Station & Unit:
Public Class Station

[code].....

View 1 Replies

Sort Of A Collection Of Class Objects?

Feb 28, 2012

I'm having problems doing a sort of a custom collection. The collection is Device Classes which is a collection of Device Class. My sort does not produce an error but the treeview control shows nothing. I am not sure what I am missing. I'm guessing just a simple sort won't work here but I don't know what I'm missing in my code. Here's the code that creates the collection

[Code]...

Simply sorting the treeview will not work because it throws off the display of related info for a given device in listview controls. The collection itself needs to be sorted before the data is added to the treeview.

View 6 Replies

XmlSerializer To Serialze A Class With A Collection?

May 26, 2010

I have a custom class that has one property as a collection.For some reason XmlSerializer doesnt like the class having a collection property and the Serialize Fails!If I remove the collection property it works! Is there a special way of getting the collection in the class to work?

View 1 Replies

C# - Create A Collection Of Variable Binding In A Class?

Apr 15, 2010

I'm trying to create a collection of variable binding in a class.It is intended to look something like this:

Dim x as integer, s as string
Dim c as new VBindClass
x = 1
s = "Hello"

[code]....

Is there some function that allow us to retrieve a unique ID for a given variable and also get/set based on variable?

Update:At last, I've managed to found the answer. Here's the code:

Dim gh As Runtime.InteropServices.GCHandle = Runtime.InteropServices.GCHandle.Alloc(obj)
Return Runtime.InteropServices.GCHandle.ToIntPtr(gh).ToInt64

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved