473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Adding to a collection in Net vs VB6 ...

Checking whether an item exists in a collection before adding it ... (Key is
always a string and in this case is the value as well)

As Net has a Contains method ... is the following a safe alternative to the
VB6 On Error Resume Next?

If Not colDs.Contains(sKey) Then
colIDs.Add(sKey, sKey)
End If

Thanks,
Mike
Feb 5 '08 #1
5 1139
Mike,

In VB6 you have one collection (which is as well in VB for Net and not in
C#). However most of us here have the opinion that it is the only thing that
should be as possible avoided from the Net namespace Microsoft.VisualBasic
(this is a true part of Net).

In .Net there are endless collections, lists, special collections, generic
collections etc.

In this case you can start with the arraylist, however better is a simple
List(of String) because then the strings are easier to use.

http://msdn2.microsoft.com/en-us/lib...19(vs.80).aspx

Cor
"Mike" <Mi**@discussions.microsoft.comschreef in bericht
news:5E**********************************@microsof t.com...
Checking whether an item exists in a collection before adding it ... (Key
is
always a string and in this case is the value as well)

As Net has a Contains method ... is the following a safe alternative to
the
VB6 On Error Resume Next?

If Not colDs.Contains(sKey) Then
colIDs.Add(sKey, sKey)
End If

Thanks,
Mike
Feb 6 '08 #2
With .NET 3.5 Linq queries were added as feature. Maybe you can
benefit:

Linq to objects is used for your object (string):
http://www.hookedonlinq.com/LINQtoObjects.ashx
Feb 6 '08 #3
Thanks very much for all the replies.

The code which I'm converting from VB6 uses a number of simple collections
and the On Error Resume Next statement to handle duplicate keys. As I'm sure
you know, this was a common VB6 practice.

What I was wondering is whether the Net methods Contains/ContainsKey are
regarded as a safe alternative to the Resume Next error handling. It seems a
little too simple, so I was wondering if I'm missing some gotcha here ...

Feb 6 '08 #4
Mike,

The Resume next has *seldom* been a good handling of known situations
(As the try and catch are as well not).

The one you use now is preventing not wanted situations, whereabout you have
full control.

Cor

Feb 7 '08 #5
Absolutely agree with you.

Thanks again,
Mike

"Cor Ligthert[MVP]" wrote:
Mike,

The Resume next has *seldom* been a good handling of known situations
(As the try and catch are as well not).

The one you use now is preventing not wanted situations, whereabout you have
full control.

Cor
Feb 7 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clayton Hamilton | last post by:
I have a DataGrid on a webform bound to a Datasource and can successfully use <ItemTemplate> to create edit/update/cancel functionality for user maintenance of data. I use separate logic to delete...
4
by: Chuck Bowling | last post by:
I have a serialized TreeNodeCollection that I want to initialize a TreeView with. Is there a simple assignment I can use for this or do I have to iterate thru the collection and add individual...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Adam J. Schaff | last post by:
Hello. I have a custom collection that implements IBindingList (allownew and allowremove are both true). I have bound it to a datagrid. I have add and remove buttons on the screen. I want to...
12
by: Art | last post by:
Hi everyone I was hoping someone might be able to help me with this. I'm just starting to try to work with MS Access tables through VB.net. In Access I can take an existing table and add a new...
47
by: Albert | last post by:
So structures are useful to group variables, so you can to refer to a collection as a single entity. Wouldn't it be useful to also have the ability to collect variable and functions? Ask K&R...
1
by: 12jumper | last post by:
Hi All :) I've created an UserControl, which has a couple of properties that are collections (generic lists of some objects). It would be nice, if control refreshed each time I add a new item to...
4
by: Adam Right | last post by:
How can i add a collection to another collection ? For example : --------------------------------------------- StringCollection strColl= new StringCollection(); //string series Hashtable...
6
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
3
by: Nunzio | last post by:
I am trying to add specific form controls to a VBA collection, so that I can pass the entire collection to another function, and access the individual controls later. I have tried several...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.