|
-
Nov 16th, 2005, 12:49 AM
#1
Thread Starter
Lively Member
StreamReader to List
OK, here's my problem. I have a text file which is tab delimited. So it looks like this:
VB Code:
21 entryA
22 entryB
23 entryC
Anyway, it has a lot of things in it. Instead of putting all items into a listbox collection and then making a casewhere structure in the list's SelectedIndexChanged event to compare the right number to each list entry (To store in a variable), I was thinking that I would use StreamReader to read from the text file and somehow store the numbers seperately from the entries. Using casewhere means that it would be an enourmous ammount of coding (Over 200 entires).
This allows me to:
a) Read the file.
b) Put the entries into the list without their corresponding numbers.
c) When I then click on an entry, it compares it to it's corresponding number.
d) That number is stored in a variable and the user never sees it.
The point is to avoid using a long casewhere structure with over 200 cases. Another advantage is that what if I want to change entires in the list? So much easier. Also, another snag is that the entries in the list ARE NOT arranged according to their number, but arranged alphabetically. So this explains why I can't just get the index number of the entry from the list. I'm also not really experienced in the area of using arrays or records, but I have I feeling I'll be using them to solve this. I do know how to use streamreader though, and 1D arrays.
I have a feeling I haven't explained something well enough or just enough. Thanks in advance.
Last edited by martw; Nov 16th, 2005 at 01:30 AM.
I never know what to put in this section...

So sue me... ... ... I'm just kidding...
www.fat-pie.com Flash Movies... You gotta see 'em to believe 'em!
-
Nov 16th, 2005, 12:55 AM
#2
Re: StreamReader to List
All you need is Strings.Split on the line read in by using streamreader.Readline... The strings.split splits on a desired string or character, in this case, a tab character. This would then return an array of two strings... so the 0 index would be the first column values and the 1 index would be your second column values... You can then do what you want with them.. add them to whichever collections you want...
-
Nov 16th, 2005, 12:57 AM
#3
Re: StreamReader to List
I'm afraid I'm not quite sure what you mean, but I will say that generally the best way to read a delimited file of tabular data is with ADO.NET. You may not be experienced but you have to learn some time. I'd suggest using OleDb. Check www.connectionstrings.com for the appropriate connection string. The trick is that you treat the folder like the database and the files as the tables, so you use file names in place of table name sin your SQL statements.
-
Nov 16th, 2005, 01:29 AM
#4
Thread Starter
Lively Member
-
Nov 16th, 2005, 01:36 AM
#5
Re: StreamReader to List
well strings.split would give you the two values seperated (you code it to loop for each line in the file).. and you can then just add the lines to a datatable, and add the resulting table to a datagrid, and hide the column that shows the numerical value... (thats what I thought you were trying to do from your explanation..)
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
|