You simply need to create a class. We can also harness one of .Net's built-in datastructures, the SortedList. In order to use the sorted list, your class needs to implement iComparable, which I will cover below.
Class Product
public Item as string
public Descrip as string
public Price as decimal
public Bin as string
end class
Now, your class needs to implement iComparable
We'll modify the class as follows
Class Product
Implements IComparable
public Item as string
public Descrip as string
public Price as decimal
public Bin as string
Public Overloads Function CompareTo(ByVal obj As Object) As Integer
if obj is nothing then return 1
Dim otherObj As Product = TryCast(obj, Product)
If otherObj IsNot Nothing Then
if me.bin < otherObj.bin then
return -1
else if me.bin = otherObj.bin andalso me.item < otherObj.item then
return -1
elseif me.bin = otherObj.bin andalso me.item = otherObj.item then
return 0
else
return 1
Else
Throw New ArgumentException("Object is not a Product")
End If
End Function
end class
Now, you should use a SortedList(of Product)
You add elements to it like this
Dim MyProduct as NewProduct
MyProduct.bin = "test"
MyProduct.price = 12.0D
MyProduct.item = "test"
MyProduct.descrip = "test"
Dim MySortedList = new SortedList(of Product)
MySortedList.add(NewProduct)
MySortedList always keeps its elements in order.
The code above can be optimized some, but I think you get the picture.
References
List(Of MyClass). Have you considered this? You could then implement a comparer that specifies how to sort.