Announcement

Collapse
No announcement yet.

I'm having a few problems with ARRAY SORT

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    I'm having a few problems with ARRAY SORT

    Hi,

    I have an array of type single which I am trying to sort with ARRAY SORT. I am finding after ARRAY SORT, the whole array is filled with zeroes!!! I am confused...

    My code is this:

    {{GLOBAL VARS DEFINITION FILE}}

    GLOBAL opt_capital() AS SINGLE



    SUB mainloop()

    REDIM opt_capital(200000)

    ... code to populate opt_capital with values ...

    END SUB



    SUB Sort()

    ARRAY SORT opt_capital()

    msgbox(str$(opt_capital(10)))
    msgbox(str$(opt_capital(1000)))
    msgbox(str$(opt_capital(175000)))

    END SUB


    Mainloop() correctly populates opt_capital() with values - I have checked.

    Each msgbox shows "0"


    Can anyone advise please? Thanks.

    #2
    Is ERR returning a value?

    -- Eric
    "Not my circus, not my monkeys."

    Comment


      #3
      Test if there are values present *before* sorting.

      SUB Sort()

      msgbox(str$(opt_capital(10)))

      ARRAY SORT opt_capital()

      [...]

      END SUB

      Comment


        #4
        Is it possible that you've got an array that is not completely filled? In other words, if the array is dimmed to 20 and 0 to 10 are set to > 0 but 11 to 20 are 0, then if you sort without setting the upper element limit, then it will resort so that the 11 to 20 elements are placed in 0 to 8.
        "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

        Comment


          #5
          Hi,

          Err is not returning a value - I tried using TRY/CATCH...

          There are values beforehand:

          msgbox(str$(opt_capital(0))) shows 202843
          msgbox(str$(opt_capital(10))) shows 101234


          And I know that opt_capital() is filled all the way to 200000

          Comment


            #6
            Actually - Russ, you were correct - I just solved it

            There was an error in my SUB filling opt_capital() from 100000 to 200000. Therefore the sort was returning "0" as expected.

            Thanks for your help.

            Comment


              #7
              I think Russ's comment is the key (without seeing the population code).

              Perhaps redimming 1 at a time when populating
              LC%=LC%+1
              REDIM PRESERVE MYARRAY(LC%)
              MYARRAY(LC%)=some value

              then looking at the end values. (from ubound back)
              Client Writeup for the CPA

              buffs.proboards2.com

              Links Page

              Comment


                #8
                Well, redim preserve is a bit slow, so I would not do that except in large chunks. I usually set the top end of the array & when I fill it and get there then I redim preserve to some logical larger amount.
                "There are two novels that can change a bookish fourteen-year old's life: The Lord of the Rings and Atlas Shrugged. One is a childish fantasy that often engenders a lifelong obsession with its unbelievable heroes, leading to an emotionally stunted, socially crippled adulthood, unable to deal with the real world. The other, of course, involves orcs." - John Rogers

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎