VS 2010 Error When Removing From List(Of String)

May 8, 2010

For Each s As String In list

If s.Contains("Hello") Then
list.Remove(s) 'ERROR Collection was modified; enumeration operation may not execute.
End If
Next

Why do i get that error?

View 22 Replies


ADVERTISEMENT

Forms :: Error In Removing Items From The List Box?

Oct 17, 2011

Imports System.Collections.Generic
Imports System.Net
Imports System.IO

[Code]...

View 3 Replies

VS 2010 - Removing Items From A List (of T) With For Each

Dec 14, 2010

Public Structure ReportOrderType
Public ReportName As String
Public ReportDate As Date
Public SaveFile As String
End Structure
[Code] ....

Basically, I have a list of reports. In one place they get ordered, and later on the program looks to see which ones have come back -- see if the .SaveFile exists on disk. If it exists, then that report gets processed, and then I want to remove that item from the list of reports-on-order. However, I get an error message back that by doing the .Remove(R), I've changed the list itself & things won't go well with the rest of the For Each loop, which makes some sense.

When I get to this routine, the list of ordered reports will be something from a couple of dozen or less, and some number of them (perhaps zero, perhaps all, probably a few) will exist & be processed & then should be removed from the list. How should I go about accomplishing this? This is my first time working with List(of t) as a Visual Basic tool; everything I've used in the past has been with arrays, and I can do this there.

View 15 Replies

VS 2010 List (of T) Removing Items?

Mar 7, 2012

I have the following

Public itemArray As New List(Of ItemArrayStructure)
Public Structure ItemArrayStructure
Dim DisplayText As String
Dim Checked As Boolean
End Structure

If I know the DisplayText of an item in this array, how can I remove it?

View 2 Replies

VS 2010 : Removing Characters From A String?

Nov 22, 2011

I need to parse an alphanumeric string leaving the characters "0-9", ".", "/" and space & remove everything else. I use "[^0-9./ ]" as my regex string and it works well. But now I have a couple other conditions that I dont know how to handle with my regex string. I actually only want to keep the "." character if it falls between two digit characters (ie. 3.5), otherwise remove it. And also I need to replace any "-" characters with a space if it falls between two digit characters (ie. 2-1), otherwise remove it.

View 1 Replies

VS 2010 Removing Characters From A String

Oct 23, 2011

If I want to remove 2 characters, or a specific letter or character from a string in VB, how would I accomplish this?

A usual input would be

"63.0" in string format

and I want it to be

"63"

View 6 Replies

VS 2010 Removing Part Of String?

Oct 9, 2010

I have a file location as a string. How can i remove the path from the string and just use the file name? For example:c:filesfile.zip - is the stringhow can i just make it so it's file.zip?keep in mind that the location is found by using anpenfiledialog(), so it needs to be able to remove the location wherever the file is.

View 6 Replies

VS 2010 - Removing Exact Data In A String?

Mar 23, 2012

I have been using the following code to remove text from strings so far;

String = Replace(String, "TextToChange", "")

However, I now would like to remove two words only when the occur consecutively for example, I would like to remove "Task 1", not all instances of the word "Task" and value "1".

View 2 Replies

VS 2010 Removing Line From Either String Or Textbox

Aug 3, 2011

I have strMyString that contains about 5000 lines of data. There are some lines of data that need removing if they contain a certain string, such as "http", "www.", ".com", "cat", "fish", etc. The whole line needs removing. Each line is separated by a vbNewLine or similar.

How can I do that? Does it need pasting into a rich textbox first before processing?

View 8 Replies

VS 2010 List(of Class) - System.NullReferenceException Error When Add The Info To The List

Jan 27, 2011

I'm getting System.NullReferenceException error when I try to add the employee info to the Employees list.

[Code]...

View 4 Replies

Removing A Font From Windows Font List (2010)?

Jun 8, 2011

I am trying to make a program that basicly, on the click of a button, removes a font from the windows font list (Un-installs it) Is there a way to do this using VB.NET (2010)The reason I want to do this is to make a program to remove the 'Comic Sans MC' font from all computers I use my pendrive on?

View 9 Replies

VS 2010 : Fill A "gap" After Removing A KVP In A Sequential String Key Based Dictionary?

Jan 2, 2012

I need to remove an instance in a class for which I also created a dictionary with a string key type. Like this...:

vb
'Declare dictionary
Public PersonsList As New Dictionary(Of String, Person)
'At the bottom of frmMain.vb

[code]....

As you see, I end having 120 instances of the class Person, each assigned with a string key consisting in "student1" to "student120".

At other parts of the program I repeatedly refer to PersonsList("student" & n) to set values at those class entries, mainly with a For n ... Next block.

Now... I need a routine to remove one of those instances for good, including its entry at the dictionary, so my first bet is this...:

vb
Public Sub ExpellStudent(ByVal student_index As Integer)
PersonsList.Remove("student" & selected_student_index)
students_count -= 1
End Sub

I assume this is good enough to remove the KVP at the dictionary AND the class instance proper... right?Well, even if that is ok, I foresee one problem... Let's say I removed "student46". Next time I run a For n = 1 to students_count I would bet that I'll receive an exception due to having a gap at "student46" KVP... and that without saying that students_count will be 119, so it will never reach "student120".In short, I need a way to reassign the KVP of the now 119 Person entries, so they're consecutive again (I don't care about them changing their string key values), so I still could use my For n = 1 to students_count ... Next blocks without problems... but I cannot figure out how.

View 9 Replies

.net - Function To Accept List(Of String), Array & String And Similarly Return List(Of String)?

Jul 29, 2011

I want the Function to accept List(Of String), Array & String and similarly return List(Of String), Array & String respectively. The Function simply adds a string (month) to the input collection. I just want to use it for string, array and list with needing to think of conversions.

[Code]...

View 2 Replies

Error On Returning List Of String 2008 Desktop Application

Nov 22, 2010

I'm trying to create a ntier desktop application using vb.net 2008.I'm trying this [code]...

View 6 Replies

Error On Returning List Of String Program Desktop Application

Nov 22, 2010

I'm trying to create a ntier desktop application using vb.net 2008.[code]...

By the way what i want to achieve is how to get the data as a List(Of String),because if i put the getMenu function into the presentation layer directly,it gives me the data as i expected..Also if i return as a string instead of List(Of String),it gives me the single data.

View 2 Replies

Removing A Delimiter From The End Of A List?

Jun 28, 2009

I've been working on this program all week and I've been able to finally get it to work except for one problem. The program is suppose to parse strings from a text box to a list box and then from a list box to a text box using the users choice of delimiters. I can't seem to figure out how to get the last comma off the end of the list. ie cat,dog,elf,It seems it should be easy, but since I've worked on this program so long I believe I can't see the forest for the trees. I don't want for you to do my work for me.

[Code]...

View 1 Replies

Removing Item From List?

May 10, 2011

My code is supposed to remove item from list but its not removing item.

[Code]...

View 2 Replies

Removing Items From A List Box?

Jun 8, 2011

I have button that adds items to a list box and a button that removes it...the one that adds it works great but when i select an item to remove it doesn't remove it..i don't know if there's something wrong with the code or not..

Private Sub btn_Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Remove.Click
list_MyOrder.Items.RemoveAt(list_MyOrder.SelectedIndex)
prices(list_MyOrder.SelectedIndex) = 0
MsgBox("Select any item to remove")
End Sub

View 5 Replies

After Change Text Of A Listbox Item Error Can't Cast String To List

Apr 20, 2010

Function runs fine on the listbox until i use the btnUp_Lanemgr click event

throws an exception in function (below in bold) "Unable to cast object of type system.string to type namespace.myitem"

what i can do to make this work?

'Button moves selected listbox item up
Private Sub btnUp_Lanemgr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp_Lanemgr.Click

[Code]....

View 1 Replies

Removing Item From TimeSpan List?

Sep 26, 2010

I'm trying to remove an item from a TimeSpan list but I need a TimeSpan for the index? If I use a List(Of String) it works fine if I use an integer for the index, but if I use List(Of TimeSpan) it wants a TimeSpan for the index. I have declared a variable like so:

vb
Dim TempTime, TimeRemover As List(Of TimeSpan)

but when I try to remove an item from the timespan it says it needs a Timespan and not an integer. Say I have:

vb
For x = 0 To 3TempTime.Remove(x)Next

That doesn't work, but if I have:

vb
For x = 0 To 3TempTime.Remove(TimeRemover)Next

It will work How can I just remove an item from a TimeSpan list?

EDIT: Figured it out, RemoveAt was what I was looking for.

View 1 Replies

Removing Items From A List View?

Jan 31, 2010

I have a form with 2 listview's and I want to remove that items in the listview1 that area duplicated on the listview2.

View 8 Replies

Removing Items From A List(Of T) Failing?

Dec 17, 2009

I have a generic list that I'm removing items out of using List.Remove(Object). I have been removing items but whenever I get to the fifth item I'm removing it fails and does not remove it from the list. It doesn't seem to matter what I'm removing but everytime I try to remove five items it fails on the fifth item.

View 4 Replies

Removing Multiple Items From A List Box At Once?

May 2, 2010

If I have 3 times selected and when I click "submit" for example I want all my selected items to be removed, but when I try to do this only my first selected item is removed.

ListBox.Items.Remove(ListBox.SelectedItems)

How do I remove all 3 items from the list box at the same time?

View 2 Replies

Removing Multiple Selection From List Box?

Mar 19, 2009

How can I remove multiple Item selection from list box ?

Private Sub rf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rf.Click
If Not (pb.Image Is Nothing) Then

[code].....

View 1 Replies

Removing URL From List In Text File

Nov 12, 2009

I am attempting to get my program to store its, in this case, a Url list in a text file. This should be relatively simple and so far it has been, writing to the document has been easy and it has all worked well, however, I have been trying to get my program to remove a url from this list too. To achieve this I have created a temporary text file, named 'FavouritesTemp.txt' and write the content of a listbox (with the target of the delete command removed from it) and then replace the old text document with the new one. But I keep getting an error from this - saying that a process is already accessing this file, even though I have just created it! I have attached a picture of my error and the code I am using underneath.

Code:
System.IO.File.Create(My.Settings.ProgramInfoStorePath & "FavouritesTemp.txt")
MsgBox("Created FavouritesTemp.txt")
Dim FavouritesWriter As New System.IO.StreamWriter(My.Settings.ProgramInfoStorePath & "FavouritesTemp.txt", True)
For Each Item In FavouritesListBox.Items
[Code] .....

View 8 Replies

Toolbox List Removing And Adding?

Jul 26, 2011

i am a starter on VB(you can see that in the name),and i removed the RadioButton from the list.

View 5 Replies

VS 2008 - Removing Item On The End From List Box

Aug 31, 2009

I have a button that when pressed I want it to remove all the ending urls that have ending with / just to remove / item on the end so it will live me a url with out / on the end if u know what I mean. [Code]

View 26 Replies

VS 2010 Error Checking With List Box?

Jan 24, 2012

I am working on a program that gathers test scores from the user in the form of a list box (array preferably). I need to be able to check the user's entries to validate they are between 0-100. I have tried using If statements with a messagebox.show() error message.When the user enters an invalid entry the error messagebox pops up but after selecting ok the program moves on to the next test score.

The GetTestScores procedure gathers the students test scores from the user
Sub GetTestScores(ByRef intTestScores() As Integer)
Dim intCounter As Integer = 0

[code].....

View 1 Replies

Forms :: Removing Items From Binding List?

May 24, 2011

have a binding list which i want to be able to add and remove items.This is the class im using

Friend Class ExecutableItem
Public Property Text() As String
Public Property Method() As Action

[code].....

View 2 Replies

Removing Items From A List Box After Setting The DataSource

Sep 29, 2010

I have a small requirement and that is as follows:

I am populating a ListBox using stored procedures and the ListBox is populated as follows:

lstItems.DisplayMember = "emp_name"
lstItems.ValueMember = "login_id"
lstItems.DataSource = accessFunction.getEmployees

The ListBox gets populated correctly. After it is populated, i have a CommandButton and on the click event of the button, i want to remove selected items from the ListBox. So in the click event of the CommandButton, i have written the following code:

lstItems.Items.Remove(lstItems.SelectedItem)

After selecting an item from the ListBox and when i click the CommandButton, i get an error as "Items collection cannot be modified when the DataSource property is set".

how i can delete items from the ListBox.

View 2 Replies







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