473,324 Members | 2,548 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,324 software developers and data experts.

Problem with SortedList

I am trying to make a SortedList using the following code:

Dim Poems As New SortedList(47)

Dim poemfiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("poetr y/poems/"))

For Each poemfile As String In poemfiles

Poems.Add(System.IO.File.OpenText(poemfile).ReadLi ne(), poemfile)

Next


My application makes it through all this code fine, and I have tested that
both parameters in the Poems.Add() method are Strings. However, when I try
to access the SortedList I recieve an error about the IComparer. I use the
following expression inside a loop to attempt to access it (j is the loop
control variable):

CStr(CType(Global.Poems(j), DictionaryEntry).Key)
Because I am somewhat unfamiliar with the IComparer class and the help files
didn't seem to be of much help, could someone tell me what I am doing wrong?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Nov 21 '05 #1
1 1065
Try looping through it with:
For Each entry As DictionaryEntry In poems
Dim key As String = CStr(entry.Key)
Dim value As String = CStr(entry.Value)
Next

Also note that you aren't closing your openfile handlers...

For Each file As String In
IO.Directory.GetFiles("C:\karl\2005\HtmlClassGener ator\HtmlClassGenerator",
"*.cs")
Dim sr As StreamReader = IO.File.OpenText(file)
poems.Add(sr.ReadLine(), file)
sr.Close()
Next

AND that if two files start with the same line, you'll get an exception
because you can't add entries with the same key...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:u$**************@tk2msftngp13.phx.gbl...
I am trying to make a SortedList using the following code:

Dim Poems As New SortedList(47)

Dim poemfiles As String() =
System.IO.Directory.GetFiles(Server.MapPath("poetr y/poems/"))

For Each poemfile As String In poemfiles

Poems.Add(System.IO.File.OpenText(poemfile).ReadLi ne(), poemfile)

Next


My application makes it through all this code fine, and I have tested that
both parameters in the Poems.Add() method are Strings. However, when I try
to access the SortedList I recieve an error about the IComparer. I use the
following expression inside a loop to attempt to access it (j is the loop
control variable):

CStr(CType(Global.Poems(j), DictionaryEntry).Key)
Because I am somewhat unfamiliar with the IComparer class and the help
files didn't seem to be of much help, could someone tell me what I am
doing wrong? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Nov 21 '05 #2

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

Similar topics

3
by: Michael C | last post by:
Hi all, I'm using a SortedList to store data, and want the keys to be compared in case insensitive order, so that mySList is the same as mySList
2
by: Pekka | last post by:
Could somebody say why the piece of code below does not work? My purpose is to renumber keys in a SortedList (after removal of an item) so that the keys would always contain an unbroken sequence of...
2
by: Curious | last post by:
Hi, I am using SortedList, but I am having problems with indexing. SortedList x = new SortedList(); x.Add(0, "zero"); x.Add(1, "one"); x.Add(3, "three"); Console.WriteLine(x.ToString());
4
by: john conwell | last post by:
So you pass in the Key and it returns the array index of the key. but you cant do array index lookups. the indexer of the sortedlist does a binary search based on the key. So whats the pointof...
2
by: Prez | last post by:
I started writing .net code yesterday and I am grasping it well enough. I have a few questions about SortedLists. I am using managed C++ if that makes any difference. Of the examples I...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
4
by: sck10 | last post by:
Hello, I have a method in my codefile that builds a sorted list (see CodeFile). I am trying to create a class that does the same thing (see App_Code). CodeFile...
4
by: aeshiels | last post by:
Hello, I have a SortedList defined as... SortedList<CUser, CUseruserList = new SortedList<CUser, CUser>(); ....and which to copy it to another sorted list SortedList<CUser,...
1
by: raylopez99 | last post by:
I seem to get name collision between the Generic collection SortedList and C++.NET Framework collection SortedList. How to resolve? Here are the libraries that seem to clash:...
1
by: asem0525 | last post by:
Hello guys, I have this kind of problem: first, the textBox tbISBN has a value that is read from the text file, but then after pressing the "Clear" button, it should be realized, and when I enter...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.