Sign in to follow this  
Followers 0
Memories

_ArraySort trouble

3 posts in this topic

Hi.

Here is an example - 2 arrays, 1st is array of numbers, it sorts correctly, 2nd is array of same numbers, but declared as strings. It sorts uncorrectly.

What should I do with $array_str to sort it correctly? I mean - like numbers. I tried to Number(my array) successfully, but it doesn't help.

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to 7
    If IsNumber($array_num[$i])=1 then
        $array_num[$i]=Number($array_num[$i])
    EndIf
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"Still not correct - String=>Number")

Share this post


Link to post
Share on other sites



you mean something like this?:

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to UBound($array_str)-1
    $array_str[$i]=Number($array_str[$i])
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"correected - String=>Number")

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

you mean something like this?:

#include <array.au3>
Dim $array_num[8] = [93999998.98,94000000.01,95000000.0,95000000.01,99999998.99,100000000.0,107100002.0,117889900.0]
Dim $array_str[8] = ["93999998.98","94000000.01","95000000.0","95000000.01","99999998.99","100000000.0","107100002.0","17889900.0"]
_ArraySort ($array_num,0,0,0, 0)
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_num,"Correct sort - Numeric")
_ArrayDisplay($array_str,"Not correct sort - Strings")

For $i=0 to UBound($array_str)-1
    $array_str[$i]=Number($array_str[$i])
Next
_ArraySort ($array_str,0,0,0, 0)
_ArrayDisplay($array_str,"correected - String=>Number")

Thanks, this was just what I needed.

Share this post


Link to post
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
Sign in to follow this  
Followers 0