|
-
Jul 12th, 2012, 08:03 AM
#1
Thread Starter
New Member
Creating Two Dimensional Array
Hello
I am new at Vb and need some help with a problem I have at the moment.
I need to open a text file into a text box object. The Text file contains date and numbers. I need to split the info into an array with the five highest dates and hits(numbers) displayed in a textBox and also the five lowest.
I also need to enable the entering of new values which will be added to the text document that is open and then saved.
Help will be appreciated, I finished all the basic openfiledialog etc but this part is confusing me as I am looking at to many examples and not finding the one that I can use.
Thanks
-
Jul 12th, 2012, 09:43 AM
#2
Re: Creating Two Dimensional Array
Moved From The CodeBank (which is for sharing code rather than posting questions )
-
Jul 12th, 2012, 09:58 AM
#3
Re: Creating Two Dimensional Array
Using a 2D array is almost certainly not a good way to go about this. Arrays are very static in nature, and multiple dimension arrays are worse than single dimension arrays. What you would be doing is one of three things:
1) Create a class and use a List(of that class). The class would have the date and numbers as members. This is probably not the best approach for this particular situation, but is a good general approach whenever a multidimensional array appears reasonable.
2) Use a datatable with a column for the date and a column for the numbers. This has a real advantage, because you can use ADO.NET to query the text file directly as if it was a database, depending on how the text file is organized. This would make it very easy to find your top and bottom items, organize the items, search, group, and so forth. However, in this particular case, you might also consider this:
3) Use a Dictionary (of Date, Integer). Since you only have the two values, you could build up a dictionary object that uses the date as the key and the number as the value. It's an intriguing way to approach the problem, and you could easily use LINQ to get the highest and lowest sets of values, but whether this is better than using a datatable depends on what else you want to do with the data. The dictionary is best if you will be frequently looking up the value based on the key. For instance, if you were to put all the dates in a listbox and find the value when you click on one, or something like that.
My usual boring signature: Nothing
 
-
Jul 12th, 2012, 01:16 PM
#4
Thread Starter
New Member
Re: Creating Two Dimensional Array
Thanks
I will look at these options.
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
|