Results 1 to 8 of 8

Thread: Sort Array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question 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

  2. #2
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    Although I haven't used them yet, I know both an Array and and Array List have sort methods. Try it out.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    If I use Array List how do I get the data out of the list one by one?

    Chong

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    I think I got it. Thanks again!

    Chong

  5. #5
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    VB Code:
    1. Private arrlist As New ArrayList(5)
    2.  
    3.     Public Sub MySub()
    4.  
    5.         'Get item at index 3 - might want to check count first to make sure you have something in 3
    6.         Dim index3item As Integer = arrlist(3) 'or arrlist.Item(3)
    7.  
    8.         'Loop through and get each integer
    9.         Dim intTotal As Integer
    10.         Dim intCounter As Integer
    11.         For intCounter = 0 To (arrlist.Count() - 1)
    12.             'Do something here to the current item - I am just adding
    13.             intTotal += arrlist(intCounter)
    14.         Next
    15.  
    16.  
    17.     End Sub

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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

  7. #7
    Fanatic Member VBCrazyCoder's Avatar
    Join Date
    Apr 2003
    Posts
    681
    You shouldn't have to import anything else, as it should be contained in the default System or System.Data references.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question

    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
  •  



Click Here to Expand Forum to Full Width