Results 1 to 5 of 5

Thread: Copy one dimensional array into two dimensional array?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    37

    Copy one dimensional array into two dimensional array?

    I have a string containing many lines. Each line has many values separated by commas. Basically it's in CSV format. The number of lines is variable but the number of columns is always 7.

    I can get each line into a one dimensional array using Split(Var, Chr(10)).

    I'd like to make it a two dimensional array where the second dimension contains each comma separated value.

    I've got
    Code:
    Dim VarArray1() As String = Split(VarText, Chr(10))
    Dim VaryArray2(0 To VarArray1.Length - 1, 0 To 6) As String
    Is there a quick way to get the contents of VarArray1 into VarArray2. I know I can do the following.

    Code:
    For Counter = 0 to VarArray1.Length - 1
      Dim line as string = VarArray1(Counter)
      Dim Values() as string = Split(line, ",")
         For Counter2 = 0 to 6
           VarArray2(Counter,Counter2) = Values(Counter2)
         Next Counter2
    Next Counter
    But is there a quicker way to do it that doesn't require passing through each element of VarArray1 and then passing through each element of Values.

    The eventual goal in all of this will be to find the highest value in the 3rd column (the arrays are strings at this point because not all columns are numeric). To do that once I get the values into VarArray2 I suspect I have to pass through each element VarArray2, i.e. VarArray2(Counter,2). Unless I can copy the whole third column into a SortedList?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copy one dimensional array into two dimensional array?

    No, there is no quick way.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    37

    Re: Copy one dimensional array into two dimensional array?

    Thanks for the response. I also have realized that a SortedList won't work because the values can be the same. I've decided to just pass through and put the column values into a one dimensional array and then use the Max property to find the highest. Pretty quick as it turns out.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Copy one dimensional array into two dimensional array?

    To be precise, Max is a method, not a property. To be more precise, it's an extension method added to support LINQ. That means that you call it like its a member of your list, e.g. myArray.Max(), but it's actually a member of the Enumerable module and your list gets passed in as an argument. To call it conventionally it would be Enumerable.Max(myArray).
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2009
    Posts
    37

    Re: Copy one dimensional array into two dimensional array?

    Ah ok thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width