Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Sort Array?

Sort Array?

Scheduled Pinned Locked Moved Visual Basic
helpalgorithmsdata-structurestutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bjblackmore
    wrote on last edited by
    #1

    Hi, I'm having a little problem sorting a 2 dimensional array, and I was wondering if someone could help. I want to sort the information in my array in decending numerical order. An example of my information is as follows: - [50] [Bananas] [10] [Lemons] [30] [Oranges] [100] [Apples] I'd like it to sort the information from highest to lowest. I'm using VB6, is this possible? Any help would be much appreciated. Cheers Ben

    N U 2 Replies Last reply
    0
    • B bjblackmore

      Hi, I'm having a little problem sorting a 2 dimensional array, and I was wondering if someone could help. I want to sort the information in my array in decending numerical order. An example of my information is as follows: - [50] [Bananas] [10] [Lemons] [30] [Oranges] [100] [Apples] I'd like it to sort the information from highest to lowest. I'm using VB6, is this possible? Any help would be much appreciated. Cheers Ben

      N Offline
      N Offline
      Nick Seng
      wrote on last edited by
      #2

      I'm afraid that there's no quick to way to do this, you'd have to do some coding. The best way, of course, if to implement a bubble sort through the first dimension, and change the second dimension accordingly Notorious SMC


      The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning Mark Twain
      Get your facts first, and then you can distort them as much as you please Mark Twain

      1 Reply Last reply
      0
      • B bjblackmore

        Hi, I'm having a little problem sorting a 2 dimensional array, and I was wondering if someone could help. I want to sort the information in my array in decending numerical order. An example of my information is as follows: - [50] [Bananas] [10] [Lemons] [30] [Oranges] [100] [Apples] I'd like it to sort the information from highest to lowest. I'm using VB6, is this possible? Any help would be much appreciated. Cheers Ben

        U Offline
        U Offline
        User 260964
        wrote on last edited by
        #3

        I always sort arrays using For loops. It might be a little slow for large arrays, but it always works for me:

        Dim myNewArray() As String, q As Integer, r As Integer, s As Integer, t As Integer

        ReDim myNewArray(UBound(myOldArray, 0), UBound(myOldArray, 1))

        r = 9999999 'Just a big number (bigger than the biggest number in your array)
        s = 0
        For q = 0 To UBound(myOldArray, 0)
        If myOldArray(q, 0) <= r Then
        For t = 0 To UBound(myOldArray, 1)
        myNewArray(s, t) = myOldArray(q, t)
        Next
        s = s + 1
        r = myOldArray(q, 0)
        End If
        Next

        I haven't tested this code, since I don't have VB6 installed at the place I currently am, but it should work. Just replace myOldArray by your array. You could even put this in a function, returning a String(). "Make peace, not war"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups