Announcement

Collapse
No announcement yet.

Array Sorting

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

  • Mike Burgett
    replied
    Thanks Ian! I'll try your code in the morning.




    ------------------
    Michael Burgett

    Leave a comment:


  • Ian Cairns
    replied
    Mike, an index is probably what you want.

    Code:
    DIM Box%(1:4)
    DIM Operator$(1:4)
    DIM Btime$(1:4, 1:25)
    DIM bWeight$(1:4,1:25)
    DIM boxIndex$(1:4), boxTag%(1:4)  ' Temporary holder + Index Array boxTag()
    'Example raw data:
    Box%(1) = 4
    Operator$(1) = "121"
    BoxTime$(1,1) = "10:15"
    BoxTime$(1,2) = "08:05"
    BoxTime$(1,3) = "14:22"
    BoxTime$(1,4) = "11:32"
    BoxWeight$(1,1) = "2333"
    BoxWeight$(1,2) = "2123"
    BoxWeight$(1,3) = "1288"
    BoxWeight$(1,4) = "2276"
    
    FOR i% = 1 TO 4
      boxIndex$(i%) = BoxTime$(1,i%)
      boxTag%(i%) = i%
    NEXT i%
    ARRAY SORT boxIndex$() FOR 4, TAGARRAY boxTag%()
    cls
    PRINT "Unsorted:"
    FOR i% = 1 TO 4
      PRINT BoxTime$(1,i%),BoxWeight$(1, i%)
    NEXT i%
    PRINT
    PRINT "Sorted"
    FOR i% = 1 TO 4
      PRINT BoxTime$(1,boxTag%(i%)), BoxWeight$(1, boxTag%(i%))
    NEXT i%
    regards,

    ------------------
    [email protected]

    Leave a comment:


  • Mike Burgett
    started a topic Array Sorting

    Array Sorting

    I have several arrays that I would like to sort. I am not sure of the
    easiest/best technique to use. Any advice would be great.

    Array List: Operator$(n) ; Box(n) ; BTime$(n,x) ; BWeight$(n,x)

    n variable represents the current operator
    x variable represents current box for operator n

    Operator$ represents an operators 3 digit ID as a string (ex. 345)
    Box(n) represents the number of boxes to sort for operator n (up to 25)
    BoxTime$(n,x) would look like this n = "345" x = "13:25"
    Boxweight$(n,x) would look like this n = "345" x = "2543"


    I need to sort the BoxTime$ by it's x value (Lowest to highest)
    and as I sort this part of the array, I must be sure that the array
    BoxWeight$ is sorted with BoxTime$.


    Example raw data:

    Box(1) = 4
    Operator$(1) = "121"
    BoxTime$(1,1) = "10:15"
    BoxTime$(1,2) = "08:05"
    BoxTime$(1,3) = "14:22"
    BoxTime$(1,4) = "11:32"

    BoxWeight$(1,1) = "2333"
    BoxWeight$(1,2) = "2123"
    BoxWeight$(1,3) = "1288"
    BoxWeight$(1,4) = "2276"


    Should come out as:

    Box(1) = 4
    Operator$(1) = "121"
    BoxTime$(1,1) = "08:05"
    BoxTime$(1,2) = "10:15"
    BoxTime$(1,3) = "11:32"
    BoxTime$(1,4) = "14:22"

    BoxWeight$(1,1) = "2123"
    BoxWeight$(1,2) = "2333"
    BoxWeight$(1,3) = "2276"
    BoxWeight$(1,4) = "1288"


    Any help would be greatly apprieciated.


    Thanks

    ------------------
    Michael Burgett
Working...
X