Jump to content

How to sort Data in an Array


Recommended Posts

Hi and Hello from a Noob..:-)

i have a very weird problem. I fill up a 2d array with a)numbers and b)letters from A-Z, so 2 columns. This works absolutely perfect. But as soon as i try to sort them (numbers ascending) the array ends up in some kind of "String-sortation". What exactly am i doin wrong? To make it easy, i post below the piece of code, which i am talking about. Hope that someone can help me out.

Func Analyse()

    Local $BasisArray[0]
    Local $aFill = "A" & "|B" & "|C" & "|D" & "|E" & "|F" & "|G" & "|H" & "|I" & "|J" & "|K" & "|L" & "|M" & "|N" & "|O" & "|P" & "|Q" & "|R" & "|S" & "|T" & "|U" & "|V" & "|W" & "|X" & "|Y" & "|Z"
    _ArrayAdd ($BasisArray, $afill)

    Local $FreqArray[0][2]=[[]]

 

    $row = 0


    For $i = 0 to 25

 

        $fummel = _ArrayToString ($BasisArray, ":" , $row, $row)

        $readout = _GUICtrlRichEdit_GetText ($hRichEdit)

        $anzAs = stringreplace ($readout, $fummel, $fummel)

        $extended = @extended

        $FreqFill = $extended & "|" & $fummel

        _ArrayAdd($FreqArray, $FreqFill)

 

        $row = $row + 1

    Next

    _ArrayDisplay($FreqArray, "2D - Item delimited")
    _ArraySort($FreqArray)
    _ArrayDisplay($FreqArray, "bla")

 

 

Thanks for helping me,

 

Cheers,

 

Patrick

Link to comment
Share on other sites

Hi Patrick.  Your code snippet refers to a RichEdit control.  What are the expected contents of the control? 

Can post some example code that runs on its own that represents the scenario your full script is encountering?  

BTW, if you use the Code button in the forum post editor (look like <> to the right of the Bold, Italics, Underline, etc. buttons), it will make your code more readable and easy to "export".

Link to comment
Share on other sites

2 hours ago, spudw2k said:

Hi Patrick.  Your code snippet refers to a RichEdit control.  What are the expected contents of the control? 

Can post some example code that runs on its own that represents the scenario your full script is encountering?  

BTW, if you use the Code button in the forum post editor (look like <> to the right of the Bold, Italics, Underline, etc. buttons), it will make your code more readable and easy to "export".

Hello and thanks for your reply. Well, like i already said....noob...:-).... What is the reason for using RichEdit. Well the target of the Project, is to code an application, to decrypt a simple encryption like subs chiffre. Therefore, i need to switch letters in the edit control (which would be possible with native autoit controls) BUT i want to switch the COLOR of the replaced letters. This seems to be impossible in native autoit. The only and last problem, was the sorting in the array. Decrypting such an encryption bases on the frequency of letters in an encrypted text. There was the culprit...sorting the letters from most frequent to less frequent.

Hope you understood what i wanted to do...:)...my english is not the best, sorry for that

Cheers, Patrick

Link to comment
Share on other sites

47 minutes ago, mikell said:

Using _ArrayAdd, "if $vValue is a delimited string all items are added to the array as strings."
So you might convert the elements in first column to Int before sorting

For $i = 0 to UBound($FreqArray)-1
    $FreqArray[$i][0] = Int($FreqArray[$i][0])
Next
_ArraySort($FreqArray)

 

Hi Mikell. Thanks to you too for your reply...i will try this out, as soon as possible. Since i like to know what i do...:-)...could you give me a (SIMPLE...for Noobs) tanslation in english, what the above code does? Would be great...

Thank you very much,

Cheers, Patrick

Link to comment
Share on other sites

1 hour ago, gruntydatsun said:
For $i = 0 to UBound($FreqArray)-1                  ;for every element in the array in turn
    $FreqArray[$i][0] = Int($FreqArray[$i][0])      ;convert each element into an INT and overwrite self
Next
_ArraySort($FreqArray)                              ;sort the array

 

THAT is exactly what i was looking for! The only thing that is not really clear to me...Ubound...the array...and than, subtract - 1 ...why is that?

OK! Forget about that question if Ubound returns, like in my case 26,  but variable starts at 0 than it runs from 0-25 times, which is 26...:-)...:-)..:-)...

Edited by Haselnuzz
Found solution myself
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

×
×
  • Create New...