Jump to content

array sort problem


Valuater
 Share

Recommended Posts

i want 10 to be #1 in the array.

10

8

6

4

2

instead i get

8

6

4

2

10

EXAMPLE

#include <Array.au3>

; Example sort Array created with StringSplit.
$avArray = StringSplit("6,8,10,4,2",",")

_ArraySort( $avArray,1,1) ; sort and start at 1.. skip array[0]
_ArrayDisplay( $avArray, "Sorted Desc starting at 1" )

thx

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Here's a shot at it for ya Val:

#include <Array.au3>

; Example sort Array created with StringSplit.
$avArray = StringSplit("6,8,10,4,2,13,12,129,106",",")

ArraySortNum($avArray)
_ArrayDisplay( $avArray, "Sorted Desc starting at 1" )

Func ArraySortNum(ByRef $nArray, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        For $x = $i To UBound($nArray) - 1
            If Int($nArray[$SE]) < Int($nArray[$x]) Then $SE = $x
        Next
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

This is probably better, it handles decimals:

#include <Array.au3>

; Example sort Array created with StringSplit.
$avArray = StringSplit("6,8,10,4,2,13,12,129,106.3,106.4",",")

ArraySortNum($avArray)
_ArrayDisplay( $avArray, "Sorted Desc starting at 1" )

Func ArraySortNum(ByRef $nArray, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        For $x = $i To UBound($nArray) - 1
            If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
        Next
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Lmao... ok, last one I promise, for acending or decending:

#include <Array.au3>

; Example sort Array created with StringSplit.
$avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4",",")

ArraySortNum($avArray, 0)
_ArrayDisplay( $avArray, "Sorted Desc starting at 1" )

Func ArraySortNum(ByRef $nArray, $Decending = 1, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        If $Decending = 1 Then
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
            Next
        Else
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x
            Next
        EndIf
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc
Back to work for me!! Cool, I made your list :o

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Yeh, however you want... I don't know if I'd ever personally use it, but your right, $Decending I think should be $Decending = 0, that and If $Decendign = 0 Then, that way you could put 1 if you want to make acend, and nothing if you just want it to do decending.

Edit:

Yeh that looks better IMHO:

#include <Array.au3>

; Example sort Array created with StringSplit.
$avArray = StringSplit("6,8,10,4,2,13,12,129,106.1,106.4",",")

ArraySortNum($avArray, 1)
_ArrayDisplay( $avArray, "Sorted Desc starting at 1" )

Func ArraySortNum(ByRef $nArray, $Ascending = 0, $Start = 1)
    For $i = $Start To UBound($nArray) - 2
        Local $SE = $i
        If $Ascending = 0 Then
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) < Number($nArray[$x]) Then $SE = $x
            Next
        Else
            For $x = $i To UBound($nArray) - 1
                If Number($nArray[$SE]) > Number($nArray[$x]) Then $SE = $x
            Next
        EndIf
        Local $HLD = $nArray[$i]
        $nArray[$i] = $nArray[$SE]
        $nArray[$SE] = $HLD
    Next
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

i want 10 to be #1 in the array.

Rolling Stones

You can't always get what you want

You can't always get what you want

You can't always get what you want

But if you try sometimes well you just might find

You get what you need

SmOke_N thought that you needed that UDF :-)

Maybe we should adopt that for Newbies

...if you try (post some code)...

we might give you what you need

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Rolling StonesSmOke_N thought that you needed that UDF :-)

Maybe we should adopt that for Newbies

...if you try (post some code)...

we might give you what you need

SmOke_N really tried and it is appreciated

i did want it......

and i got what i needed...

i think that would be a great idea for ALL Newbies

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Rolling StonesSmOke_N thought that you needed that UDF :-)

Maybe we should adopt that for Newbies

...if you try (post some code)...

we might give you what you need

Hmm, Did I do something wrong, or am I just not understanding this? Didn't you want the highest value number to the lowest value number? I assumed this because of using _arraysort()... or maybe I'm just not understanding what plato's saying here.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

...or maybe I'm just not understanding what plato's saying here.

I thought that this might happen when I tried to work you and your posts/code into that joke...

I thought of that song as soon as I saw "want" in the first post - before there were any replies. I went off to look at the Array UDF to see if I could help (like I had a chance at understandin' that code). Once I saw that the solution was in your capable hands, I just waited for a chance to inject the jest.

I was tryin' to say that you gave Val what exactly what he needed (and coded well to boot).

In keeping with the Newbie jest, it is Val that should have tried (more than the mere 3 lines that showed the problem - where is the attempt at the solution in the first post Val?) Of course, if we had all just ignored Val, he would have posted the answer to his own question soon enough.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Wow... guess i was wrong

I would never ask without trying many times to get what i am after

these are true in a message box

01 + 1 = 2

01 + 01 = 2

I was in the middle of 3 for/next loops cheking a stringsplit...

I actually thought that maybe one of the base/ubounds/index/ or whatever might do the trick and someone might know what to put in this line

_ArraySort ( ByRef $a_Array, [$i_Descending[, $i_Base=0[, $i_Ubound=0[, $i_Dim=1[, $i_SortIndex=0]]]]] )

i think i got lucky in one of the last lines i was able to do the test

If StringLen($LC[$j]) = 1 Then $LC[$j] = 0 & $LC[$j]

... again another for/next loop

yes... i always try.. i just dont always put my non-working code in

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

I thought that this might happen when I tried to work you and your posts/code into that joke...

I thought of that song as soon as I saw "want" in the first post - before there were any replies. I went off to look at the Array UDF to see if I could help (like I had a chance at understandin' that code). Once I saw that the solution was in your capable hands, I just waited for a chance to inject the jest.

I was tryin' to say that you gave Val what exactly what he needed (and coded well to boot).

In keeping with the Newbie jest, it is Val that should have tried (more than the mere 3 lines that showed the problem - where is the attempt at the solution in the first post Val?) Of course, if we had all just ignored Val, he would have posted the answer to his own question soon enough.

:o I get it... :geek:

Actually, the idea that Val even asked for help as much as he gives (as do you), I would have spent a couple of hours trying to figure out a solution for it if needed, but it just so happens that I was working on something similar last week. Although his code was short indeed, the UDF he was using told me specifically what he was trying to do (so I thought until I didn't understand the jesting :sorcerer: ).

Although it was only a few lines, it was interpretable for me... unlike a

"I want to make a "Program" to read my girlfriends messenger, and upload a file to my ftp server when she has decided to stop talking... can someone help?

Thanks

(Actually that description is better than most! ;)) God those post piss me off! First off to use the word "I", then not provide anything that "I" has done is so condescending!! Then have the audacity after someone posts something (although I don't think they should) to say "No, that's not what I want to do"! :huggles:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Wow... guess i was wrong...

no no no... I'm just too tired to convey humor tonight.

I assumed that he took this "SmOke_N really tried and it is appreciated" combined with my joke to mean that he tried and failed. So I went for - it was you that should have tried. :-)

...but alas, your first post was great - it showed the problem in just enough code - and since you did try in your first post, I had to reach for "no attempted solution code" to make my analogy work. [You just don't make a good Newbie!]

My, "where is the attempt at the solution in the first post Val?" should have been followed by many smilies!

[size="1"][font="Arial"].[u].[/u][/font][/size]

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

  • Recently Browsing   0 members

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