|
-
Jul 13th, 2005, 01:33 PM
#1
Thread Starter
Hyperactive Member
error when item does not exist in collection ! ?
When I search an Item in a collection and the item does not exist I get en error instead of "nothing" !?
Don't tell me that that's the way it works - this would be just stupid. Or am I doing any mistake? I do
Dim MyCollection as new collection
MyCollection.add("something","myIndex")
MyCollection.Item("xxx")
This gives an error : The argument 'index' isn't a valid value.
Thank you for any help!
Regards,
Fabian
What I finally did is to create a function that sends back "nothing" instead of throwing an error...
VB Code:
Public Function SearchCollectionItem(ByVal Collection As Collection, ByVal Index As String) As Object
Try
Return Collection.Item(Index)
Catch ex As Exception
Return Nothing
End Try
End Function
Last edited by fabianus; Jul 23rd, 2005 at 01:20 AM.
-
Jul 13th, 2005, 05:12 PM
#2
Re: error when item does not exist in collection ! ?
can't you do the same with a SortedList class?
the Collection class is in the VisualBasic namespace and it's better to avoid that namespace
sorry if I'm not being helpful, but try to give SortedList a try also, I think it works very similarly
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 13th, 2005, 06:02 PM
#3
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Thank you for the tip - SortedList looks interesting.
But why Microsoft tells to inherit CollectionBase?
Is there any problem about inheriting SortedList instead of CollectionBase for typed collections?
Thank you for any suggestion !
Regards,
Fabian
-
Jul 13th, 2005, 06:55 PM
#4
Re: error when item does not exist in collection ! ?
hmm depends what you want to do. Are you making your own collection?
SortedList is good for when you have a list of items, and each item is associated with a key (or with a "myIndex" as you called it in your first post). SortedList makes it easier to search for an item by having its key, and I believe it uses a binary searching so it should be faster too.
I've never had to inherit from that class so I dunno. But I have inherited from CollectionBase in many situations (ie, to make someting similar to an ArrayList that accepts a certain datatype only)
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Jul 13th, 2005, 07:20 PM
#5
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Thank you !
Regards,
Fabian
-
Jul 13th, 2005, 09:23 PM
#6
Re: error when item does not exist in collection ! ?
You derive your class from CollectionBase if you basically want to create a strongly typed ArrayList. If you want to create a strongly typed HashTable or SortedList, you would inherit DictionaryBase instead, which provides key/value functionality. There is also ReadOnlyCollectionBase you can inherit. Three guesses what that does.
-
Jul 13th, 2005, 09:38 PM
#7
Re: error when item does not exist in collection ! ?
I see what you were doing, the Item() property of a collection accepts an index parameter, which must be an Integer, not a string as you had it, hence why it threw that exception. It does return Nothing if it's not found.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Jul 13th, 2005, 09:45 PM
#8
Thread Starter
Hyperactive Member
-
Jul 13th, 2005, 09:51 PM
#9
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Hi Ideas Man,
Collections can take a text-key. I always do this.
Regards,
Fabian
-
Jul 13th, 2005, 10:29 PM
#10
Re: error when item does not exist in collection ! ?
 Originally Posted by fabianus
Hi Ideas Man,
Collections can take a text-key. I always do this.
Regards,
Fabian
Ah, if you provide the method to do that, then yes it will. Sorry about that, I'm way off in the Generics world of VS 2005 lol.
Woohoo, my 1,500th post!
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Jul 13th, 2005, 10:32 PM
#11
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Generics world ? What is that?
-
Jul 13th, 2005, 10:42 PM
#12
Re: error when item does not exist in collection ! ?
Generics provide, amongst other things, the means to create a HashTable with strongly-typed keys and/or values simply by using the desired Types in the declaration. They pretty much spell the end of custom collection classes.
-
Jul 13th, 2005, 10:47 PM
#13
Re: error when item does not exist in collection ! ?
Here's an example of a strongly-typed Dictionary declaration:
VB Code:
Dim myStronglyTypedHashTable As Generic.Dictionary(Of String, Form)
This means that all keys must be of type String and all values must be of type Form. Generics can do much more besides. They are one of the big selling points of .NET 2.0.
-
Jul 13th, 2005, 10:49 PM
#14
Re: error when item does not exist in collection ! ?
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Jul 14th, 2005, 04:59 AM
#15
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
In fact I am hasatating to move to .NET 2.0. I have the BETA version and my hoster offers ASP.NET 2.0 support (that I would need for the web-applications). So I could move to VS 2005.
Should I?
It seems to me that de BETA is not limited in time. In the package there is SQL-Server 2005 and it is limited for one year (written on the DVD), but for VS 2005 they did not write any limit. Do you know if the BETA package of VS 2005 is unlimited in time?
So if it is - should I move to it or is there any major problem ?
Thank you for some advices.
Regards,
Fabian
-
Jul 14th, 2005, 05:12 AM
#16
Re: error when item does not exist in collection ! ?
I seem to recall that there is some limit but don't quote me on that. There may be some restriction with software written with the beta running on the release version of the Framework. That's just conjecture though. If you need to get out a production app this year, I'd say stick with 2003. If your development will extend into next year, though, I'd say make the switch. 2005 is released in November, so once that passes you can test your app on the release version of the Framework and your uncle bob's your uncle. As a last word, 2005 does fairly rock.
-
Jul 14th, 2005, 05:27 AM
#17
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Hi jmcilhinney,
"As a last word, 2005 does fairly rock."
>> That's the problem, I have all sorts of troubles that I would not have with 2005!
In fact production will start in the coming days, but it is a small company (it's an app for hotel-management, with a specific part for meal-management with connection to a balance, etc.). I have also a web-project for food-statistics (people input what they eat and they get out statistics about this), this web-project will be used by an association, so there too it is not a 100% super high relyability request.
When you passed to .NET 2.0 did you have major problems for your apps builded in VS 2003 with framework 1.1 ? Is there a big rewriting to do?
And about ASP.NET 2.0 - did you already passe a 1.1 project to 2.0 ? Is there any major difficulty?
Thank you very much for any information about that, becaus I sens that I could gain a lot of thime with 2.0 - the question is only if I could easyly pass from my existing projects to 2.0.
Thank you very much,
Regards,
Fabian
-
Jul 14th, 2005, 05:38 AM
#18
Re: error when item does not exist in collection ! ?
Many apps written with 2003 will require no rewriting at all. It will be just like upgrading from 2002 to 2003. The project upgrade is a one-way affair, so obviously keep a backup. You will have to make changes to take full advantage of .NET 2.0, but virtually all 1.1 features are still there. I can't speak for ASP as I don't use it, but I'm guessing the deal is the same. If I'm not mistaken, you can release production apps on the beta Framework but you need a special licence from MS to do so. Keep in mind that some things will change between beta 2 and release, but they will most likely be additions rather than subtractions.
-
Jul 14th, 2005, 05:53 AM
#19
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Oh, that's an important information : so you may not produce a "Release" with the BETA version without paying something?
-
Jul 14th, 2005, 06:12 AM
#20
Re: error when item does not exist in collection ! ?
I'm not sure of the details, but I'm sure I've read somewhere that you need special dispensation from Microsoft to legally sell work produced with a beta IDE. I couldn't tell you where exactly, but if I'm correct then I'm sure it wouldn't be too hard to find on the MS web site.
-
Jul 14th, 2005, 06:48 AM
#21
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
I am not interested in "legally" sell, I'll sell it unlegally without any problem :-)
No seriously, I do not need to sell it as it is for organisations that I am involved with (I do it for pleasure). So what I need to know is only if it is technically possible.
Regards,
Fabian
-
Jul 14th, 2005, 06:53 AM
#22
Hyperactive Member
Re: error when item does not exist in collection ! ?
For your information, the VS2005 Betas are time-limited. I've been using Beta 2 of the C# and C++ IDE for some time now but a couple of days ago the time ran out. Nothing from Microsoft is free.
-
Jul 14th, 2005, 07:47 AM
#23
Thread Starter
Hyperactive Member
Re: error when item does not exist in collection ! ?
Hi Parallax,
how may days/weeks/months did you run it?
Thanks,
Fabian
-
Jul 14th, 2005, 08:09 AM
#24
Re: error when item does not exist in collection ! ?
You can play with it, however you are NOT allowed to release any software created in it unless you have a GoLive licence or something like that. Remember it is beta software, I've found 3 bugs in it, one is a real pain in that it locks the code editing controls all the bloody time. You can get around it by running the project and then closing it, other than that, it's fine. You could distribute it i guess if you wish, but remember you need the new framework, which is beta code, and it will require uninstalling when the final is released, so it might be a better idea to just develop in the new one and if possible, hold out on the distribution until it's completed (November 7th 2005).
Also, ASP.NET gets a major face lift in this version, tons of new controls and other new features, like master pages etc. So it's best to explore a bit.
Also, keep a backup copy of your project as previously stated. It does need to upgrade all of your components to the new framework. I didn't get any major problems, only depreciated properties which you will get on your forms, all of your forms, but that's an easy fix.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Jul 14th, 2005, 10:00 AM
#25
Re: error when item does not exist in collection ! ?
 Originally Posted by Ideas Man
only depreciated properties
Sorry to be a pain but this is about the fourth time I've seen this, each time from someone different, and my left eye starts twitching each time: deprecated, not depreciated.
-
Jul 22nd, 2005, 08:10 PM
#26
Re: error when item does not exist in collection ! ?
 Originally Posted by jmcilhinney
Sorry to be a pain but this is about the fourth time I've seen this, each time from someone different, and my left eye starts twitching each time: deprecated, not depreciated.

Lol, whoops, sorry, didn't realise that. I was in a rush when I did that anyway so yeah.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|