|
-
Sep 22nd, 2005, 02:12 PM
#1
Thread Starter
Lively Member
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??
-
Sep 22nd, 2005, 02:33 PM
#2
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:
Private Sub QuickSort(C() As String, ByVal First As Long, ByVal Last As Long)
Dim Low As Long, High As Long
Dim MidValue As String
Low = First
High = Last
MidValue = C((First + Last) \ 2)
Do
While C(Low) < MidValue
Low = Low + 1
Wend
While C(High) > MidValue
High = High - 1
Wend
If Low <= High Then
Swap C(Low), C(High)
Low = Low + 1
High = High - 1
End If
Loop While Low <= High
If First < High Then QuickSort C, First, High
If Low < Last Then QuickSort C, Low, Last
End Sub
Private Sub Swap(ByRef A As String, ByRef B As String)
Dim T As String
T = A
A = B
B = T
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Sep 22nd, 2005, 02:46 PM
#3
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|