dcsimg
Results 1 to 4 of 4

Thread: Creating Two Dimensional Array

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    2

    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

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Creating Two Dimensional Array

    Moved From The CodeBank (which is for sharing code rather than posting questions )
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    34,562

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    2

    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
  •  



Featured


Click Here to Expand Forum to Full Width