Jump to content

Recommended Posts

Posted (edited)

Hello,

I have a problem: Basically i want to sort a 2d array using one column that contains numeric values.

My code looks like this:

For $iz = 1 To UBound($CCinvoices) -1

$CCinvoices[$iz][1] = StringReplace($CCinvoices[$iz][1], " ", "")
$CCinvoices[$iz][1] = Number($CCinvoices[$iz][1])


Next






_Arraydisplay($CCinvoices, "$CCinvoices")

_ArraySort($CCinvoices, 1, 0, 0,1)



_Arraydisplay($CCinvoices, "$CCinvoices")

 

image.png.b118d8532f3663a9954ca31c6fc856a0.pngThis is how array looks before sorting.

 

 

 

After i sort the array, I got the following result:

image.png.318997a94f62340d3db328e1f0760d2e.png

As you see 227.21 was sorted after 29.79 so i dont know why i got this.

 

I tried the following solutions:

1) Removing blank spaces

2) Converting strings to Number before sorting.

 

Any ideas?

 

Edited by rony2006
  • Moderators
Posted

rony2006,

Converting the strings to numbers should give you a numerical sort. Can you please post the code that you used to convert the column - perhaps that might be helpful to see where it has gone wrong.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

rony2006 , if your conversion loop is that in the first post (For $iz = 1 to ...), you should try to start the for/next loop from 0 instead of from 1

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...