|
-
Apr 17th, 2003, 12:31 PM
#1
Thread Starter
Addicted Member
Sort Array
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
-
Apr 17th, 2003, 02:54 PM
#2
Fanatic Member
Although I haven't used them yet, I know both an Array and and Array List have sort methods. Try it out.
-
Apr 17th, 2003, 03:02 PM
#3
Thread Starter
Addicted Member
If I use Array List how do I get the data out of the list one by one?
Chong
-
Apr 17th, 2003, 03:05 PM
#4
Thread Starter
Addicted Member
I think I got it. Thanks again!
Chong
-
Apr 17th, 2003, 03:10 PM
#5
Fanatic Member
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
-
Apr 17th, 2003, 03:17 PM
#6
Thread Starter
Addicted Member
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
-
Apr 17th, 2003, 03:21 PM
#7
Fanatic Member
You shouldn't have to import anything else, as it should be contained in the default System or System.Data references.
-
Apr 17th, 2003, 03:28 PM
#8
Thread Starter
Addicted Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|