Pick Last 1000 Elements From A Generic Collection?

Mar 1, 2011

Say a collection grow. Once it's size reach 10k, I want to get rid the first 9k. How to do so?Oh ya I could use removeRange.Is there another function that will output say, the last 1k of the element, say if I do not want to remove anything? Something like tail or something.

View 7 Replies


ADVERTISEMENT

Generate A Random Word But Pick One From A Collection

Jul 11, 2010

So what I'm trying to do is not so much generate a random word but pick one from a collection. I was thinking on generating a random number since that is very easy, then picking a word acording to the number generated. Is there a more efficient way of doing this?

View 9 Replies

Get Elements From Collection Containing Value?

Dec 5, 2009

I have a collection (a Dictionary, actually) of strings as the key and strings as the value. The value strings are filenames. I wish to find which elements contain a certain filename as the value, returning the Key so that I can modify the Value (change the filename).[code]....

View 4 Replies

Individual Elements In A Collection?

Jan 7, 2010

I'm converting a library from C# to VB.net which so far hasn't been too difficult. One class though implements IEnumerable and IEnumerator and contains a block of code like this:

public class MyClassCollection
{
// Assume all other necessary code is in place

[code].....

View 2 Replies

C# - Selecting Distinct Elements From A Collection?

Dec 14, 2011

I need to select distinct highways from a roads collection.

I suppose I could use LINQ for this.

I have (stub code)

Dim roads As List(Of Roads) = myRegion.Roads
Dim highways As New List(Of Highway)
For Each road In roads

[Code]....

View 5 Replies

XML Feed - How To Get Collection Of Elements (Assets) Via LINQ

Mar 9, 2011

I have the following XML which I load via XDocument.Load(uri) or XElement.Load(uri). I am having trouble getting a collection of <asset> elements via LINQ.

Here is a snippet of the XML I'm trying to query:
<assetCollection xmlns="tag:aisle7.net,2009:/api/1.0">
<title>All Assets</title>
<description>Collection containing all assets in the system</description>
<resourcePath>/us/assets/~all</resourcePath>
[Code] .....

View 2 Replies

Convert One Generic Collection To Another?

Jan 23, 2010

I have the below code and it works fine, it's this way because I need to manually calculate some data before adding it to the Listview control.

Code:
Dim mList As List(Of ListViewItem) = mDataBase.GetRecords(LvwChecks, "CheckGroups", <Query>, GetType(CheckItem))
If mList.Count > 0 Then

[Code].....

View 6 Replies

InvalidOperationException Generic Collection?

Sep 14, 2011

I know its generally a big No-No to modify a collection that you are iterating through but unfortunately i didn't design the code that i'm trying to modify. All over the place the following is done:

for each log in Logs
logs.Delete(log.LogId)
Next

Delete pretty much just deletes the log from the database and removes it from the collection. Previously the Logs object was using a Non-Generic collection. I changed it to use a Collection(Of Log) so i can LINQify the object. Now every time i call next/.MoveNext is called after the first delete the following error happens:

InvalidOperationException:"Collection was modified; enumeration operation may not execute."

I understand why i'm getting the error but i don't understand why it never happened with the Non-Generic version. Is there anyway to get around this error? There really is no way i can take the time to change every place where the delete logs like this (codebase is large). Id like to just remove the code in the Delete function where it removes it from the current collection because i'm assuming no code does anything with the collection after its done but you know what happens when you assume.

View 3 Replies

See Properties Of A Generic Collection Object?

Apr 8, 2009

I have a class which extends HashSet(Of T).I am trying to evaluate some custom properties of this HashSet during execution and make decisions based on those values.

During debugging, I am pausing execution and adding a Watch on my instance of this HashSet.

The Watch only provides me with a view of the Count of the HashSet and the objects contained by the HashSet.How can I get the Watch to show me the other properties of the HashSet?

View 1 Replies

Serializing A Generic Collection With XMLSerializer?

Jul 11, 2009

Why won't XMLSerializer process my generic list?

Sub Main()
Serializing()
End Sub

[Code]....

I get an exception on the "Dim ser" line, saying "Testing.Module1 is inaccessible due to its protection level. Only public types can be processed." ("Testing is the name of the application, and "Module1" is the name of the module; this is a console application).

View 1 Replies

VS 2010 Generic Collection Queue?

Apr 16, 2011

Ok say I have this Dim MyQueueOfClients as new Queue (Of TcpClient) I also have two threads.

In thread one a TcpListener waits for connections then adds a connected TcpClient to MyQueueOfClients.

MyQueueOfClients.Enqueue (TcpClient)In thread two I then check to see if there are any Clients in MyQueueOfClients. If so I then remove them from the MyQueueOfClients.

MyTcpClient = MyQueueOfClients.Dequeue I think the question Im asking is this thread safe?

Can I Enqueue and Dequeue at the same time from different threads?

Well it helps if you read everything. I have just read this as well

A Queue(Of T) can support multiple readers concurrently, as long as the collection is not modified. Even so, enumerating through a collection is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you can lock the collection during the entire enumeration. To allow the collection to be accessed by multiple threads for reading and writing, you must implement your own synchronization.

View 4 Replies

Index Out Of Range Exception In Custom Generic Collection?

Feb 25, 2009

I wrote a class which imports System.Collections.ObjectModel. For the management of the collection, I've written:

Default Public ReadOnly Property Item(ByVal vntIndexKey As Integer) As ItemType
Get
Return CType(mCol.Item(vntIndexKey), ItemType)

[code].....

View 4 Replies

VS 2008 Transfer A Custom Event Through The Generic Collection?

Dec 22, 2009

To the point: I need to transfer a custom object's event through a generic collection object containing these items so that any class using the collection can see that changes were made to one of the items in the collection.

I.E. An item event that triggers a collection event

[Code].....

Due to the application requirements, I need the Collection and Items to send immediate notice of various changes that occur to the Collection Class and its items. I've already got my events set-up regarding for the Collection Class, but I'm struggling with coming up with a workable solution for raising events for the items.

I've got an event for the DeviceLayer item set-up, but how do you transfer that event through the CollectionClass so that any other class using it will see that there was a change to one of the items in the collection?

View 3 Replies

Working With System.collection.generic.Ienumerable/XML Linq Queries?

Oct 22, 2009

This is really a continuation from my earlier post. I've never worked with this datatype/collection (system.collection.generic.Ienumerable) before so I'm struggling to declare the query globally so I can reference the results within other sub routines/functions. I also am struggling to convert it to other types.how I can convert the collection of xml elements/system.collection.generic.Ienumerable into an xmltextreader (I know I will have to change the query below as it select the value of the node and not the node itself) I imagine by converting the query result to system.IO.stream My first port of call was MSDN but I find the material very difficult to understand for this particular subject.

[Code]...

View 3 Replies

Alter Items Added To Generic Collection (as Property Of Custom Class)

Jun 19, 2009

I have several custom classes in a VB.NET (VS2008) project which are related to each other through generic list collections. The lower tier classes refer directly to some of the parent classes (to make it easier to refer backwards up the chain). My question is, is it possible to add the reference to the parent class when the item is added to a collection, when that collection is a property?

Below is some sampling of code to illustrate.
Public Class FlexServer
Private m_FlexLicenses As List(Of FlexLicense)
Private m_Modules As List(Of FlexModule)
Public Property FlexLicenses() As List(Of FlexLicense)
[code] .....

In the code above I have the FlexServer class which refers has two lists as properties, one for FlexLicense and one for Modules. The FlexLicense class has a property to refer back to the FlexServer class that "owns" it. In order to update this property in code, I have to add the FlexLicense to the FlexServer.FlexLicenses list AND set the FlexLicense.FlexServer property. What I am looking for is, is there a way (in the property definition or wherever) to both add the item to the list and alter it at the same time?

View 1 Replies

Request For Peer-Review KeyedBindingList (Of TKey / T) Generic Collection Concept

Aug 18, 2011

There are a lot of different generic collections available, so the wisdom in creating a new one may be questionable right from the start.However, I often find myself wanting the same features from my custom generic lists, but cannot quite find all of those features in an existing object; namely, I would like to have a generic collection which works like a List or Dictionary (much like the System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue)), but also works like a BindingSource does when it is bound to an ADO object (that is, it supports full sorting and filtering as well as currency).A feature I almost never need however, is transactional adds (the BindingSource's ability to 'cancel add-new').Again, with so many existing collections out there, I should take a moment to go over the reasons why none of them quite meet my needs.There is the System. ComponentModel. BindingList(Of T) which would provide some of the functionality of a BindingSource, but has strict requirements about the type {T} implementing IComparable in order to support sorting, and does not provide filtering (it is not an IBindingListView).It also only maintains a base item list by index, so does not provide keyed access.We could use simple databinding with a custom list inheriting from System.Collections. ObjectModel. Keyed Collection(Of TKey, TValue) bound to a BindingSource, but again TValue would have to implement IComparable to support sorting and we would still not have filter support.So to get all the features I was after, I decided that the best thing would be to create a new generic collection object which implemented IList, IDictionary, IBindingList, and IBindingListView (along with a few others) and would be capable of serving as a simple list, or as a binding source while providing full sorting and filtering over any newable object type.

To that end, I've created the KeyedObjectModel which contains the KeyedBindingList(Of TKey, T) generic collection/binding source. This collection can be used as a typical list, or as a binding source (you do not need an additional BindingSource component between the collection and UI controls, although you could certainly have one).Various constructors are provided in order to initialize an instance of the collection as either an enhanced list-dictionary, or as a complete BindingSource.Any object that has a public constructor which takes no arguments can be used at type {T}, providing that the object has a property of type {TKey} which will contain unique values for each entity in a given collection.If the object implements System.ComponentModel.NotifyPropertyChanged then the collection will also bubble up property changes on the current item to the collection's CurrentItemChanged event.An implementation of IComparable on type {T} is irrelevant because sorting and filtering are performed on the property values of {T} based on the type of the specified property.The current design of KeyedBindingList(Of TKey, T) is in an 'alpha' stage.The class is mostly complete from a feature implementation standpoint, however, the code has not yet been optimized and the base collections of values, keys, and view are being maintianed in generic lists of their own, rather than raw arrays.However, even without performance tuning, the collection appears to be performing quite well, up to a few thousand entries, given the amount of flexibility and funcitonality it provides.At this stage, I would really love to get some peers to try using the compiled DLL and beat up the collection a bit.Once the code has been proven and optimized, I will publish it as an example.It is a fairly complex class though (currently made up of eleven or so partial classes) so I don't really want to post the code until it has been optimized. [code]

View 4 Replies

Is There A Concept Of "Generic Structure" Similar To Generic Collections, Generic Classes

Dec 16, 2009

We have migrated our Vb6 application to VB.NET using a third party tool. Now we are in a process of Refactoring and introducing object oriented concepts in the application.

In VB6, we were using structures in many places. As a part of introducing object oriented programming,

1. is it a good idea of changing all Structures to Classes? or Is there a concept of "Generic Structure" similar to Generic collections, Generic classes?

2. Can some one guide me any source containing guide lines or best practices for applications that are migrated to VB.NET from VB6 and implementing object oriented programmaing.

View 3 Replies

Html - Dynamically Created Elements From Codebehind Need To Be Inserted Between Specific Elements

Sep 17, 2010

I created a method and pass the element type, id, and any inner text that instantiates a new html element. The last statement: Me.Controls.Add(element) adds it to the end of the page, but I would like it to be inserted in a specific position (between 2 divs within a form). What I am describing is very similar to this post on SO here, although it was for javascript.

View 1 Replies

.net - Can A Generic Version Of A Derived Class Override A Base Method Using The Generic Type

Apr 13, 2012

Consider:

Public MustInherit Class Column
Public ReadOnly Property ReturnSomethingUseful() As Object
Get
'return something useful

[code]....

But this gives the following error:

Public Overrides Function ParseValue(sValue As String) As Boolean'
cannot override 'Public Overridable Function ParseValue(sValue As String) As Object'
because they differ by their return types.

I accept that you can't do this, but I'd like to be able to preserve the semantics of what I'm. trying to do, which is to have an untyped version that deals with Object, but a typed version in derived classes that knows about the specific type T.

View 2 Replies

How To Put Comma In Value (1000)

Mar 22, 2012

I have a textbox named txtWith (Amount where cash should be inputted) and I want the input to have comma. Example, if I input 1000, I want it to be like this 1,000. By the way, this is my code in the textbox.

///THIS CODE WILL DISABLE CHARACTER///
Private Sub txtWith_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtWith.KeyPress
'////////////////LETTERS DISABLED ONLY///////////////////////
If (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or Asc(e.KeyChar) = 8 Then
e.Handled = False
Else
e.Handled = True
MsgBox("Please input numbers only!", vbCritical, "Error!")
End If
End Sub

View 4 Replies

.net - Determining A Generic Type At Runtime In Non-Generic Class

Aug 14, 2010

I have a Journal that records entries for different types: Journal(Of ParentT)

[Code]....

View 2 Replies

Construct A Generic Interface Class With Generic Functions

Nov 25, 2011

I am trying to construct a generic interface class with generic functions. My goal was to use this to implement multiple worker classes for database interaction that have the same basic functionality. Each class will deal with different object for example, category, product or supplier but unless the the functions in the interface are generic that this won't work.This is the interface code that I have but I don't know if I have done it correctly. [code]

View 2 Replies

Extracting Number Out Of A=1000?

Mar 15, 2011

I am trying to extract whichever number is next to a=. I hardwired a value of 1000 for testing purposes.I keep getting an error saying Index and length must refer to a location within the string.Parameter name: length when I try and use substring.

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim text As String = TextBox1.Text
Dim comp(9) As String

[code]....

View 3 Replies

How To Add Comma In 1000, 100000

Mar 26, 2012

I always have this problem. I have a textbox but is disabled and you can only input through a button. So, I want the input number "1000" to be like this, "1,000" but I don't know what code to put. Same thing with 100000 = 100,000

View 1 Replies

Insert In A Form A ProgressBar (Max Value 1000)?

Aug 5, 2011

If I insert in a Form a progressBar (Max value 1000) and I write this very simple example

For x = 0 To 990 Step 10
ProgressBar1.Value = x
Threading.Thread.Sleep(5)
Next
Me.Close

If I run the code with Windows7 setted as Windows Classic I can see the progress bar value go to the max value and after few time the Form Closes (same with Windows XP).But If I run the program with Windows7 setted as Windows7 Basic the progress bar value ONLY goes to the HALF max value and after half time the form Closes.

The code is the SAME, the PC is the same, Seven is the same (only personalized with different theme) but under Windows7 Basic it seems that For x = 0 To 990 Step 10 becomes For x = 0 To 550 Step 10..The INCREDIBLE thing is that if I insert in the For... Next a row like:

Debug.Print(ProgressBar1.Value.ToString)I obtain right values until 990... but for my eyes the progress bar only goes to half value in half time, then the Form closes.

View 10 Replies

Set My Timer Interval To 1000 And Enabled It?

Feb 12, 2011

I am trying to write a simple code that will essentially change the background oclor of a form from say red to green, like every five seconds.(Actually, it will be green 4 and red 6 seconds). I set my timer interval to 1000 and enabled it. So when I write my if/then statements in the timer area, would I be using timer.interval <=4, or timer.interval <=4000 to count off four seconds?

View 1 Replies

UI Hangs While Updating 1000 Labels?

Oct 5, 2010

I have a windows form where i try to update a form which has 1000 labels. By update i mean i try to set the color of the labels. And i am doing this update in windows form timer every 1 sec.

My problem is the UI freezes. I tried using a thread. In the thread i tried to call the update code, but still the UI hangs.

View 1 Replies

.net - Creating A Generic List Of A Generic Type

Jun 30, 2011

I am trying to create a list of a generic type in vb.net 2.0 framework.
This is the generic type definition:

Public Class GenericParamMap(Of T)
Public Sub New(ByVal pParamName As String, ByVal pPropValue As T)
mParamName = pParamName

[Code]....

The compiler does not allow a "T" in the method's parameter because it's not defined, but I'm not sure how or where to define it. I thought it was okay to have a generic method definition.

View 2 Replies

Generic Cannot Instantiate Instance Of The Generic Type With New?

Feb 8, 2012

I am trying to write a generic method, to avoid code duplication, which will create or activate a Form as an MDI children, based on its type. But I have to lines in error (see comments).

[Code]...

View 4 Replies

Code - Putting 0 To 1000 Via Thread In Listbox

Apr 18, 2009

I want to write code that complete task of putting 0 to 1000 via thread in listbox. I want to start 10 threads at startup and complete task.

All threads should work equally. Each thread will write 100 numbers. First start from 0 to 100, second from 100 to 200, third from 200 to 300, so on upto 10th.

I have written code but it has problem.

Dim num As Int16
Dim startLoop As Int16
Dim endLoop As Int16

[CODE]...

View 1 Replies







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