Haselnuzz Posted October 23, 2018 Posted October 23, 2018 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
spudw2k Posted October 24, 2018 Posted October 24, 2018 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". Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
mikell Posted October 24, 2018 Posted October 24, 2018 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)
Haselnuzz Posted October 24, 2018 Author Posted October 24, 2018 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
Haselnuzz Posted October 24, 2018 Author Posted October 24, 2018 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
gruntydatsun Posted October 24, 2018 Posted October 24, 2018 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
Haselnuzz Posted October 24, 2018 Author Posted October 24, 2018 (edited) 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 October 24, 2018 by Haselnuzz Found solution myself
Haselnuzz Posted October 24, 2018 Author Posted October 24, 2018 The piece of code provided worked like a charm! I want to say thank you again to all involved helpful people. Cheers, Patrick
Juvigy Posted October 24, 2018 Posted October 24, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now