0

I am trouble in sorting 2 dimensions array in vb.net. One row has 5 columns. Original array have 3000 rows. How can I get the effective sorting with pdtId. I tried to find googling, cannot get the right answer to me.

(0, 0) = pdtId "string" 
(0, 1) = brand name
(0, 2) = category Id
(0, 3) = url
(0, 4) = date

(1, 0) = pdtId "string" 
(1, 1) = brand name
(1, 2) = category Id
(1, 3) = url
(1, 4) = date

. . 3000 rows anyone could you able to help me, big trouble, :(

3
  • msdn.microsoft.com/en-us/library/cxt053xf.aspx Commented Mar 12, 2011 at 16:49
  • @Jaroslav: the Sort method is for only for one-dimensional arrays. Commented Mar 12, 2011 at 17:45
  • @Doc Brown: He can easily read the data to an array of objects instead the 2d array... Commented Mar 12, 2011 at 18:09

2 Answers 2

1

Don't use a twodimensional array, or an array of arrays. Better create a class for your five fields and put objects of that class into a onedimensional array:

Public Class MyData
    Implements IComparable(Of MyData)

    Public pdtId As String
    Public brand_name As String
    Public category_Id As String
    Public url As String
    Public theDate As Date

    Public Overloads Function CompareTo(ByVal obj As MyData) As Integer _
           Implements IComparable(Of MyData).CompareTo
        Return pdtId.CompareTo(obj.pdtId)
    End Function

End Class


Sub Main()
    Dim myArray(3000) As MyData

    ' Code to fill the array
    ' ...

    Array.Sort(myArray)

End Sub
Sign up to request clarification or add additional context in comments.

5 Comments

thanks a million, i am trying to code. i will back whether ok or not.
i am getting error "value of type of string cannot be converted array.sort.mydata" myArray(0) = "pdtId" myArray(1) = "brandname" myArray(2) = "categoryId" myArray(3) = "url" myArray(4) = "theDate" myArray(5) = "pdtId" myArray(6) = "brandname" myArray(7) = "categoryId" myArray(8) = "url" myArray(9) = "theDate"
please help me more ' Code to fill the array' part. i am really fresh. sorry for that.
anyway thanks you so much, :) I got it as per below java2s.com/Tutorial/VB/0160__Collections/…
@user656760: well, since I don't know anything about where your data comes from or where it goes to I cannot tell you how the "code to fill your array" must look like in your case. If you have any difficulties, please edit your original posting and add the code where your problems arise.
0

You should really be using an array of arrays here - multidimensional arrays are only intended for when the number 'columns' (2nd index) is different between rows (1st index).

If you make this instead an array or arrays, using Array.Sort to solve the problem become really easy.

1 Comment

Thanks your reply. i don't understand very well. i am newbie,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.