473,830 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1153
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.Visua lBasic
(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**@discussio ns.microsoft.co mschreef in bericht
news:5E******** *************** ***********@mic rosoft.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
3643
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 a row. Everything works just fine. BUT I would like to add a button to (for example) the DataGrid header, which when pressed will add a new row to the datagrid. This should then allow the user to enter information into text boxes (in some...
4
13157
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 Nodes?
3
4889
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 the best method? Do you have a sample of how to do this?
0
3000
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 implement those buttons, but I'm not sure what the code should look like. I tried what I thought was obvious code: myCollection.AddNew() and
12
3582
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 field with the type AutoNumber. I can then set this up as a key. Then if I go into the table I will see sequential numbers have been inserted into that field for me. Can I do this through VB.net I'd appreciate any help or alternative suggestions...
47
3906
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 say, C programs consist of variables to store the input and functions to manipulate them. This would make C object-oriented - how cool would that be? Are there any problems with adding the ability to have functions
1
2007
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 the collection (using StringCollectionEditor). Is there any attribute I can use, or perhaps I have to create a new class that inherites from List<Tand subscribe on some event? Any suggestions greatly appreciated. Greetings
4
4848
by: Adam Right | last post by:
How can i add a collection to another collection ? For example : --------------------------------------------- StringCollection strColl= new StringCollection(); //string series Hashtable hshCol= new Hashtable(); // main collection for string series strColl.Add("white"); //first series starting strColl.Add("hot"); strColl.Add("little");
6
2520
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 ?? When adding a new node is there any way to get an handle or something else to be able add the childs to the correct parent ? Thanks!
3
7006
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 different syntax variations. In each case, the receiving function produces the error 'Object Required' when I try to access any property of a control in the collection. If I reference a collection item in the debugger using its ordinal position, I see...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10774
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7746
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6950
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5617
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4411
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.