Results 1 to 3 of 3

Thread: Coding Help (only Ideas)

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    102

    Coding Help (only Ideas)

    Lo all, Just need some general ideas on how to code something.
    Right in the application im making I need to find the lowest 'paid' 20% of people in a certain group. i.e if there are 100 people in group 1 then 20 people (same as 20%) who are paid the lowest are in Band A, then the 20.1% - 39% of the lowest paid are in Band B.
    The way how I thought of doing it would be to say sort through every person in the array and if they are in group 1 then add their serial/id number to another array, once the loop has found everyone in group 1 then sort that array in range of lowest to highest. Then..... lol divide the ubound of the array which is now sorted by 100 to get how many people per %. Mulitply that by 20 to get the 0 to 20% point on the array. next multiply the 1st number by 39 then add the 20% number as the starting point then the 39% as end point which gives then the 20% - 39% number lol.

    Right thats how I though initially of doing it, any fast way people know of??

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Coding Help (only Ideas)

    this may help:
    it is code to sort an array it works very fast

    so you could dump into the array, pass the arry in and sort it...

    then like you said divide the ubound to find the ranges for each percent

    VB Code:
    1. Private Sub QuickSort(C() As String, ByVal First As Long, ByVal Last As Long)
    2.     Dim Low As Long, High As Long
    3.     Dim MidValue As String
    4.    
    5.     Low = First
    6.     High = Last
    7.     MidValue = C((First + Last) \ 2)
    8.    
    9.     Do
    10.     While C(Low) < MidValue
    11.     Low = Low + 1
    12.     Wend
    13.    
    14.     While C(High) > MidValue
    15.     High = High - 1
    16.     Wend
    17.    
    18.     If Low <= High Then
    19.         Swap C(Low), C(High)
    20.         Low = Low + 1
    21.         High = High - 1
    22.     End If
    23. Loop While Low <= High
    24.  
    25. If First < High Then QuickSort C, First, High
    26. If Low < Last Then QuickSort C, Low, Last
    27. End Sub
    28.  
    29. Private Sub Swap(ByRef A As String, ByRef B As String)
    30.     Dim T As String
    31.    
    32.     T = A
    33.     A = B
    34.     B = T
    35. End Sub
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    Lively Member
    Join Date
    Sep 2005
    Location
    Florida
    Posts
    107

    Re: Coding Help (only Ideas)

    You could do this in Excel in less time than it took to type your question.

    Anyway, get your data in an array. Sort the array on the income column, lo to hi.

    For however many people you have in the array, N, each band B will be N * .20, or N / 5.

    The first B entries in the sorted array are the lowest band. The next B entries are the next band. etc.

    Example: N = 155, B = 31
    Sorted array = A(i) or A(c,i) for multiple columns.
    Band 1 = A(0) thru A(B-1) 'Note that VB defaults to base 0 arrays.
    Band 2 = A(B) thru A(B+B-1)

    And so on.

    Does that help, or do you need to discuss the actual sorting process?

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