Dent Posted June 25, 2016 Posted June 25, 2016 (edited) 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) Edited June 25, 2016 by Dent Solved
Developers Jos Posted June 25, 2016 Developers Posted June 25, 2016 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.
Dent Posted June 25, 2016 Author Posted June 25, 2016 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)
Developers Jos Posted June 25, 2016 Developers Posted June 25, 2016 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.
Dent Posted June 25, 2016 Author Posted June 25, 2016 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.
Developers Jos Posted June 25, 2016 Developers Posted June 25, 2016 I saw that after posting ....sorry. so do something like: Local $aGetHighestFiveAdditionalIncomesForAppOne[8][2] = [ _ ["Occupational pension income", Number($PensionsOne) _ ... Jos Dent 1 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now