Jump to content

Recommended Posts

JdeB! Are you there, I dont know if you wrote the _ArraySort() Function to but I need help again.

I need to sort the below.

#include <Array.au3>

Dim $avArray[10]
$avArray[0] = "192"
$avArray[1] = "128"
$avArray[2] = "320"
$avArray[3] = "174"
$avArray[4] = "64"
$avArray[5] = "32"
$avArray[6] = "392"
$avArray[7] = "1"
$avArray[8] = "12"
$avArray[9] = "123"

_ArrayDisplay( $avArray, "Unsorted" )
_ArraySort( $avArray)
_ArrayDisplay( $avArray, "Sort Ascending" )
_ArraySort( $avArray,1)
_ArrayDisplay( $avArray, "Sort Decending" )

I want it to search from highest to lowest ie, 392,320,192,174,128,123,64,32,21,1. But instead it does like the _ArrayBinarySearch() way does something like 1,12,123,128,174,192,32,320,392,64.

Is that because it does a binary search? (I learnt what that was today :))

Is there a way, or another function that I can use to sort these numbers from highest to lowest, or do I have to make another function again?

Edit: I keep thinking it will be hard lol. I done it but, quite simple.

For $i = 0 to 9
   $max = _ArrayMax ($avArray,1)
   $maxindex = _ArrayMaxIndex ($avArray,1)
   If $i = 0 Then
      $test = _ArrayCreate($max)
   Else
      _ArrayAdd ( $test, $max)
   EndIf
   _ArrayDelete ( $avArray, $maxindex)
Next

Sorts it from highest to lowest. And if I want lowest to highest I can simply do the above and then use _ArrayReverse ()

Edited by Burrup

qq

Link to post
Share on other sites
  • Developers

I want it to search from highest to lowest ie, 392,320,192,174,128,123,64,32,21,1.

<{POST_SNAPBACK}>

Thats what the Descending option does for you. :) (see the example in your post)

You might want to convert the Array entries to Number() first because else it will do an Alphanumeric sort......

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 post
Share on other sites

In my example it doesnt sort from highest to lowest. In the array it will only ever be a number or "N/A". I've been using it and it seems to be working fine.

For $I = 0 To $Array - 1
   $Max = _ArrayMax ($Audio_Year,1)
   $Max_Index = _ArrayMaxIndex ($Audio_Year,1)
   If $I = 0 Then
      $Audio_Year_Correct = _ArrayCreate($Max)
   Else
      _ArrayAdd ($Audio_Year_Correct, $Max)
   EndIf
   _ArrayDelete ($Audio_Year, $Max_Index)
Next
$Audio_Year = $Audio_Year_Correct

Im using the above currently.

Edited by Burrup

qq

Link to post
Share on other sites
  • Developers

In my example it doesnt sort from highest to lowest. In the array it will only ever be a number or "N/A". I've been using it and it seems to be working fine.

<{POST_SNAPBACK}>

You are sorting Alphnumericly = strings !!!!

Try this version..:

#include <Array.au3>

Dim $avArray[10]
$avArray[0] = 192
$avArray[1] = 128
$avArray[2] = 320
$avArray[3] = 174
$avArray[4] = 64
$avArray[5] = 32
$avArray[6] = 392
$avArray[7] = 1
$avArray[8] = 12
$avArray[9] = 123

_ArrayDisplay( $avArray, "Unsorted" )
_ArraySort( $avArray)
_ArrayDisplay( $avArray, "Sort Ascending" )
_ArraySort( $avArray,1)
_ArrayDisplay( $avArray, "Sort Decending" )

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 post
Share on other sites

Hmmmmmmmmmmmmmmm, so it makes all the difference if I have the number in quotation marks?

Edit I cant do that but, because the number isnt just by itself... its in a string like

"192|XXXX| XXX|X |XXXXX" as an eg. So it doesnt work and I have to use my way, unless you have something else up your sleve :).

Edited by Burrup

qq

Link to post
Share on other sites
  • Developers

Hmmmmmmmmmmmmmmm, so it makes all the difference if I have the number in quotation marks?

<{POST_SNAPBACK}>

YES!

String compare goes from Left to Rigth!

Number compare is done on the actual Value!

:) (think i am going to charge a class fee here :D )

Edited by JdeB

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 post
Share on other sites
  • Developers

You a good teacher :). I still cant use it but lol, do you think my way will work fine? and can you see and problems with it.

<{POST_SNAPBACK}>

just convert to number first like:

#include <Array.au3>
$avArray = Stringsplit("123|234|4|67|32","|")
For $x = 1 to $avArray[0]
     $avArray[$x] = Number($avArray[$x])
Next
_ArraySort( $avArray,1)
_ArrayDisplay( $avArray, "Sort Decending" )

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 post
Share on other sites

I cant! Like I said the values of the array will be something like

$array[0] = "192|XXXX| XXX|X |XXXXX"
$array[1] = "128|XXXX| XXX|X |XXXXX"
$array[2] = "64|XXXX| XXX|X |XXXXX"
$array[3] = "320|XXXX| XXX|X |XXXXX"

I am designing this for my 'Media Player' so when you click the 'Bit Rate' List Column it will sort the files by bit rate, which means that all the information has to be attached to the bit rate so I can then StringSplit() it and retrieve the values for the other columns.

The X's in "XXXX| XXX|X |XXXXX" represent a title/artist etc. They are split up by "|". It is way to much work to spilt each array up for each file just to get the Bit rate and then sort it and then search the other arrays for the matching information, piece it back together and split it up again so each column has the right value. *Erhm.

Thats why I just have like above. When I arrange by title name the format is

"Title|Artist|Album Title|Duration|Year|Genre|Track #|Bit Rate"

and when by Bit Rate I swap the Bit Rate and the title so now its up the front

"Bit Rate|Artist|Album Title|Duration|Year|Genre|Track #|Title"

hence the format "192|XXXX| XXX|X |XXXXX".

As I have just explained that is why I am doing it my way :).

qq

Link to post
Share on other sites
  • Developers

I cant! Like I said the values of the array will be something like

$array[0] = "192|XXXX| XXX|X |XXXXX"

[post="74073"]<{POST_SNAPBACK}>[/post]

Just work with 2 dimentions and sort on the "Column" you want sequence it on.... must be a piece of cake now for you :)

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

    No registered users viewing this page.

×
×
  • Create New...