Announcement

Collapse
No announcement yet.

Array Sort Issue

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

  • Array Sort Issue

    For the life of me, I can't seem to figure this one out and I've been doing some forum searches ("array sort" and "array sort single" thinking that perhaps the issue is sorting real numbers) that have thus far been unhelpful.

    Here's the relevant code:

    Code:
    LOCAL sSortArray() AS SINGLE
          
    REDIM sSortArray(1 TO UBOUND(player()))
    
    FOR x = 1 TO UBOUND(player)
        IF player(x).iOutsAtPosition(1) > 10 THEN
            sSortArray(x) = ((13 * player(x).iHomeRunsAllowed + 3 * player(x).iWalksAllowed - 2 * player(x).iStrikeOutsAllowed) / (player(x).iOutsAtPosition(1) / 3)) + 3.2
        ELSE
            'sSortArray(x) = (0.72xNIBB + 0.75xHBP + 0.90x1B + 0.92xRBOE + 1.24x2B + 1.56x3B + 1.95xHR) / PA
             sSortArray(x) = (0.72 * player(x).iWalks + 0.90 * (player(x).iHits - player(x).iDoublesTotal - player(x).iTriplesTotal - player(x).iHomeRunsTotal)  _
             + 1.24 * player(x).iDoublesTotal + 1.56 * player(x).iTriplesTotal + 1.95 * player(x).iHomeRunsTotal) / (player(x).iAtbats + player(x).iWalks)
        END IF
    NEXT x
    
    ARRAY SORT sSortArray()
    
    FOR x = 1 TO UBOUND(sSortArray())
        WRITE #iFileNum(1), sSortArray(x)
    NEXT x
    I'm basically taking an array of my "player" UDT and storing a key to "sort by" in the array called sSortArray(). Admittedly, the majority of players don't have a value - there are a ton of 0's in this array. However, there are a few players who have a value that's a real number between 0 and 1 and others that have a value above 0 and approximately 7 to 8. However, when I view my file with the printed sSortArray, I get this:

    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    .072
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    0
    3.496296

    and then more zeros, and then some more numbers, out of order. I know this must be something ridiculous that I'm not seeing right now. I'd be grateful if anyone has any idea what I'm missing. Eventually, I want to attach player() as a TAGARRAY on this list, but I'm in the midst of troubleshooting and have removed that from the equation.

    Thank you!
    Last edited by Craig Scarborough; 6 Jan 2009, 12:22 AM.

  • #2
    Is #DEBUG ERROR turned ON?

    If so, what does ERR tell you?

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

    Comment


    • #3
      Craig--

      I'd suggest you create a simple example which can actually be compiled and executed. That way, folks can actually see what's happening and point out a fix for you.

      Bob Zale
      PowerBASIC Inc.

      Comment


      • #4
        Because the fly in the ointment is not likely ARRAY SORT, but may be something else
        Code:
        #COMPILE EXE
        #DIM ALL
        
        FUNCTION PBMAIN () AS LONG
            DIM sSortArray(1 TO 33) AS SINGLE
            'the posted values put in the array
            ARRAY ASSIGN sSortArray() =  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _
                                        .072,0,0,0,0,0,0,0,0,0,0,0,0,3.496296
        
            ? FORMAT$(sSortArray(32)) + ", " +FORMAT$(sSortArray(33))  'is 0,3.496296
            ARRAY SORT sSortArray()
            ? FORMAT$(sSortArray(32)) + ", " +FORMAT$(sSortArray(33))  'now is .072,3.496296
            OPEN "sorted.txt" FOR OUTPUT AS #1
            PRINT #1,sSortArray()
            CLOSE       
        END FUNCTION
        Last edited by Richard Angell; 6 Jan 2009, 08:38 AM.
        Rick Angell

        Comment


        • #5
          Thanks, I'll give it a shot. I'll have to "un-FireFly" my code first.

          Comment


          • #6
            Originally posted by Richard Angell View Post
            Because the fly in the ointment is not likely ARRAY SORT, but may be something else
            Code:
            #COMPILE EXE
            #DIM ALL
            
            FUNCTION PBMAIN () AS LONG
                DIM sSortArray(1 TO 33) AS SINGLE
                'the posted values put in the array
                ARRAY ASSIGN sSortArray() =  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, _
                                            .072,0,0,0,0,0,0,0,0,0,0,0,0,3.496296
            
                ? FORMAT$(sSortArray(32)) + ", " +FORMAT$(sSortArray(33))  'is 0,3.496296
                ARRAY SORT sSortArray()
                ? FORMAT$(sSortArray(32)) + ", " +FORMAT$(sSortArray(33))  'now is .072,3.496296
                OPEN "sorted.txt" FOR OUTPUT AS #1
                PRINT #1,sSortArray()
                CLOSE       
            END FUNCTION
            Interesting, I didn't even know you could just print the entire array to the file - I thought you had to cycle through each element. Learn something new every day.

            I agree that ARRAY SORT isn't the problem, I'm just not seeing what I'm doing wrong at this point. I'm sure whatever it is, I'll have an "ah hah!" moment. Thanks for your help.

            Comment


            • #7
              Interesting, I didn't even know you could just print the entire array to the file - I thought you had to cycle through each element. Learn something new every day
              See also: JOIN$() function
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Thanks to those that helped.

                I think I was having multiple problems, and they can all be traced to odd data. First, I think I had the possibility to have a division by zero issue (though I never received an error for it). I removed that, and if any of the data was "empty" I designated my sort key to equal 0 for that player. After doing these things, the sort on sSortArray worked, but it still didn't tag along my player() UDT when I set that as the TAGARRAY. After creating a bogus array solely for the purpose of a tag along, it seemed to work fine.

                Again, thanks for everyone's help with this.

                Comment


                • #9
                  First, I think I had the possibility to have a division by zero issue (though I never received an error for it).
                  Neither numeric overflow nor numeric underflow (division by zero =underflow) errors are detected by compiler. Send New Feature Suggestion to [email protected] to join the list of those who have requested same.
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Done!

                    Comment

                    Working...
                    X