Jump to content

[SOLVED] _ArraySort problem


Recommended Posts

I've been searching for a solution on the forum and came across a partial solution in this topic...

My problem is that I have a 2D array; column one has the description (a string) of the integer in column two. I want to sort this array by the value of column two from highest to lowest. Only my _ArraySort produces a strange result.

Here is the code and the output before and after...

Local $PensionsOne = ($MonthlyPensionIncomeOne + $MonthlyPensionCreditIncomeOne)
Local $SecondEmploymentOne = ($SecondSalaryOne + $SecondBonusOne + $SecondOvertimeOne + $SecondCommissionOne)
Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _
   ["Occupational pension income", $PensionsOne], _
   ["2nd job", $SecondEmploymentOne], _
   ["Working Tax Credits", $MonthlyUniversalTaxCreditIncomeOne], _
   ["Disability living allowance", $MonthlyStateDisabilityIncomeOne], _
   ["Investment or dividend income", $MonthlyInvestmentIncomeOne], _
   ["Maintenance", $MonthlyMaintenanceIncomeOne], _
   ["Rental income", $MonthlyUnencumberedRentalIncomeOne], _
   ["Self-employed income", $SecondNetPreTaxProfitLatestYrOne]]

_ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne)
_ArraySort($aGetHighestFiveAdditionalIncomesForAppOne, 0, 0, 2)
_ArrayDisplay($aGetHighestFiveAdditionalIncomesForAppOne)

 

Before.PNG

After.PNG

Edited by Dent
Solved
Link to comment
Share on other sites

  • Developers

Looks correctly sorted to me since it are strings. Just convert the the Col1 to Values and try the sort again and you'll see it will work fine.

Jos 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I believed I had already changed the strings to integers, here is a sample of the code I've used...

$MonthlyInvestmentIncomeOneRaw = _ArrayToString($aArray, ":", 93, 93)
Local $MonthlyInvestmentIncomeOneStart = StringInStr($MonthlyInvestmentIncomeOneRaw, ":")
Local $MonthlyInvestmentIncomeOne = StringMid($MonthlyInvestmentIncomeOneRaw, ($MonthlyInvestmentIncomeOneStart + 1), 8)
StringFormat("%i", $MonthlyInvestmentIncomeOne)

 

Link to comment
Share on other sites

  • Developers

I don't see you filling the cell for $aGetHighestFiveAdditionalIncomesForAppOne in there.
How are the values put in?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Just now, Jos said:

I don't see you filling the cell for $aGetHighestFiveAdditionalIncomesForAppOne in there.
How are the values put in?

Jos

The code in my original post shows the values being input into the array.

Link to comment
Share on other sites

  • Developers

I saw that after posting ....sorry.

so do something like:

Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _
   ["Occupational pension income", Number($PensionsOne) _
...

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...