Jump to content
Sign in to follow this  
Haselnuzz

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

Share this post


Link to post
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".


Share this post


Link to post
Share on other sites

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)

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
UBound($FreqArray)-1

The ubound function returns the number of elements in the array - for example 15. The "-1" accounts to the fact that the first element of the array starts from index 0, so the elements are from 0 to 14 or = 15

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jahar
      I have an AutoIT script It monitors 2 websites for content that applys to me and the services that I provide. One site is : www.Freelancer.com The other: www.PeoplePerHour.com Both sites publish new jobs on their site hourly or so. My AutoIT app, will view those sites and present new jobs to me in a grid that pops up on my screen. Lately, the app has stopped showing me any jobs from PeoplePerHour.
       
      For freelancer.com,  Inetget is giving full html but for peopleperhour, now its not coming.
      Func _CheckPPH()
          Local Static $hTimer = 0
          Local Static $hDownload = 0
          Local $aTitlesandUrls = 0
          Local Static $sTempFile = ""
          If $hTimer = 0 Then $hTimer = TimerInit()
          If $hDownload = 0 Then
              $sTempFile = _WinAPI_GetTempFileName(@TempDir)
              ConsoleWrite("Checking PPH..." & @CRLF)
              ConsoleWrite(">Downloading..." & @CRLF)
      ;~         $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
              $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD)
      ;~         Return 0
          EndIf
      ;~     Sleep(30)
      ;~     Local $isCompleted = InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
      ;~     Local $isError = InetGetInfo($hDownload, $INET_DOWNLOADERROR)
      ;~     Sleep(30)
      ;~     If TimerDiff($hTimer) > 3000 And $isError Then
      ;~         ConsoleWrite("!PPH Fail" & @CRLF)
      ;~         InetClose($hDownload)
      ;~         $hDownload = 0
      ;~         Return 0
      ;~     EndIf
      ;~     Sleep(30)
          Local $Show = 0
      ;~     If TimerDiff($hTimer) > 3000 And $isCompleted Then
          If $hDownload > 0 Then
              ConsoleWrite("+Downloaded..." & @CRLF)
              Local $sPPHHtml = FileRead($sTempFile)
              $aTitlesandUrls = _StringBetween($sPPHHtml, '"title">' & @LF, 'time>')
      ;~         _ArrayDisplay($aTitlesandUrls)
              Local $aPPH[0][4]
              Local $sTitle = ""
              Local $sUrl = ""
              Local $sID = ""
              Local $sDate = ""
              Local $iRet=0
              Sleep(30)
              For $i = 0 To UBound($aTitlesandUrls) - 1
                  $sTitle = _StringBetween($aTitlesandUrls[$i], '<a title="', '" class')
                  $sUrl = _StringBetween($aTitlesandUrls[$i], 'href="', '">')
                  $sDate = _GetDate($aTitlesandUrls[$i])
                  If IsArray($sTitle) And IsArray($sUrl) Then
                      $sID = _GetID($sUrl[0])
      ;~                 _ArrayAdd($aPPH, $sDate & "|" & $sTitle[0] & "|" & $sUrl[0] & "|" & $sID)
                      $iRet = _BuildPopupsPPH($sID, $sDate, "PPH: " & $sTitle[0], $sUrl[0])
                      If $iRet Then $Show+=1
                  EndIf
              Next
              Sleep(30)
      ;~         If $Show > 0 Then ShowLatestJobs()
      ;~         _ArrayDisplay($aPPH)
              FileDelete($sTempFile)
              InetClose($hDownload)
              $hDownload = 0
              $hTimer = 0
              Return $Show
          EndIf
          Sleep(30)
      EndFunc   ;==>_CheckPPH
    • By malicioussoap
      back when I was still doing autohotkey you could write (in code) spanisha::á
      and whenever you were in google docs or notepad you could type (in the document) spanisha  and it instantly turns it into á 
      I tried doing this in autoit, here's what I have so far (my entire code so if this language requires a main function or a return/exit to function properly please let me know):
      ;is this a proper comment? HotKeySet ( "spanisha" , "SendAltered" ) Func SendAltered() Send("á", flag = 0); EndFunc I assume that autoit follows a sort of contemporary hotkey pressing model where you have to hold all keys at the same time? which makes this impossible. So
      I'm wondering if anyone has a workaround for this? or maybe an alternative to HotKeySet()
      I have a vague memory of someone saying that doing something like spanisha:á would work. I don't know if I'm slightly off syntax but this doesn't work.
      Also I tried doing 
      ;is this a proper comment? ;HotKeySet ( "a" , "SendAltered" ) ;spanisha::á Func SendAltered() Send("á"); EndFunc just to try and debug,
      I'm also wondering if my approach is fundamentally wrong since HotKeySet() was made for something like !^A. Or if Send() is syntactically wrong.
      I'm also noticing on these forums that specifying installation is important so to whom it may concern I downloaded both installers, editor and main files. Although I'm about to be real mad if the editor installation makes a difference.
    • By shelly
      I have to press tab to reach a selected button then double click on that
      Here's my script but its not working:
      WinActivate("Policy Decisions -- Webpage Dialog","")
      Sleep(3000)
      Send("{TAB}")
      Send("{TAB}")
      Send("{TAB}")                    // at this point its working according to my need  but double click is not working
      Mouseclick("Left",510, 320, 2, 0)

    • By TheDcoder
      See this thread for info:
    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
×
×
  • Create New...