Is there an easy way to sort Array in VB .NET? For example, the array of aryRank contains: [red]|5|2|9|7|10|3|10|[/red] and I want to sort them but largest number to smallest. What's the best way to do it?
Many thanks in advance!
Chong
Printable View
Is there an easy way to sort Array in VB .NET? For example, the array of aryRank contains: [red]|5|2|9|7|10|3|10|[/red] and I want to sort them but largest number to smallest. What's the best way to do it?
Many thanks in advance!
Chong
Although I haven't used them yet, I know both an Array and and Array List have sort methods. Try it out.
If I use Array List how do I get the data out of the list one by one?
Chong
I think I got it. Thanks again!
Chong
VB Code:
Private arrlist As New ArrayList(5) Public Sub MySub() 'Get item at index 3 - might want to check count first to make sure you have something in 3 Dim index3item As Integer = arrlist(3) 'or arrlist.Item(3) 'Loop through and get each integer Dim intTotal As Integer Dim intCounter As Integer For intCounter = 0 To (arrlist.Count() - 1) 'Do something here to the current item - I am just adding intTotal += arrlist(intCounter) Next End Sub
What other Imports do I need to import for me to use the array list properly. I tried to the arraylist.count() and the .Count() wasn't listed as an option.
Chong
You shouldn't have to import anything else, as it should be contained in the default System or System.Data references.
Thanks! I got it. The problem was I didn't declare it as Private arrylist as new arraylist. Instead, I used Dim and that's why the problem.
I got it now.
Chong