pixelsearch Posted March 20, 2022 Share Posted March 20, 2022 Hi everybody Could you please confirm the Console display of this script on your computer ? Local $r1 = _NaturalSort("15", "-15") ; - 1 Local $r2 = _NaturalSort(".12", "15") ; - 1 Local $r3 = _NaturalSort("-15", ".12") ; - 1 ConsoleWrite("$r1 = " & $r1 & " $r2 = " & $r2 & " $r3 = " & $r3 & @crlf) Func _NaturalSort($sElem1, $sElem2) Return DllCall("shlwapi.dll", 'int', 'StrCmpLogicalW', 'wstr', $sElem1, 'wstr', $sElem2)[0] EndFunc Console display : $r1 = -1 $r2 = -1 $r3 = -1 I got -1 three times, which means that : * $r1 : "15" has a lesser value than "-15" (msdn page) * $r2 : ".12" has a lesser value than "15" * $r3 : "-15" has a lesser value than ".12" But something seems wrong because of the following incompatibility. It will be sorted this way, when based on $r1 and $r3 results : "15" < "-15" < ".12" Or that way, based on $r2 and $r1 results : ".12" < "15" < "-15" Or even like that, based on $r3 and $r2 results : "-15" < ".12" < "15" This could explain why I got "naturally sorted" rows placed differently, based on a same* initial array (same* means the same value of the elements, not considering their initial position in the unsorted array) In my mind, no matter how the initial array is displayed before sorting, the result should be the same after the natural sort... but it's not : an array having its rows initially displayed as "15", "-15", ".12" won't naturally sort same as if its rows were displayed as ".12" , "-15", "15" and the output will very often be different. I'm aware this kind of values should be better treated using a numeric sort, but it's not a reason to ignore the potential problem caused by dots and minus signs during a natural sort. There's a guy at this link who commented about this, at the very end of the web page : It seems to be a misfeature of the "Natural sorting" function StrCmpLogicalW, which sorts numbers by their value instead of sorting them althabetically, e.g. 99 comes before 100. I guess it sees the "-" as a negative sign, and therefore ignores it. Author of Total Commander http://www.ghisler.com But I'm not even sure this applies fully to the preceding issue (his comment about the minus sign) So could you guys, please confirm that you got the Console display result "-1" three times ? I hope you'll get a different result, it could mean that your newer version of "shlwapi.dll" has corrected this kind of discrepancy. Especially when this note is written at the end of MS web page (msdn link above) Note Behavior of this function, and therefore the results it returns, can change from release to release. It should not be used for canonical sorting applications. Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 20, 2022 Moderators Share Posted March 20, 2022 pixelsearch, $r1 = -1 $r2 = -1 $r3 = 1 3.3.16.0 on 64-bit Win 10 Hone 21H2. M23 pixelsearch 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
pixelsearch Posted March 20, 2022 Author Share Posted March 20, 2022 (edited) Great, that explains it all. I was about to add a comment in my initial post, indicating that all values were unique (to eliminate the unstable/stable sort question) but it's not necessary now that you indicate that $r3 = 1 on your computer, which means a newer version of "shlwapi.dll" (this issue has nothing to do with AutoIt) Ty M23 Edited March 20, 2022 by pixelsearch M23, not MB23 Link to comment Share on other sites More sharing options...
Exit Posted March 20, 2022 Share Posted March 20, 2022 AutoItVersion: 3.3.16.0 AutoItX64: 1 CPUArch: X64 OSArch: X64 OSVersion: WIN_11 OSBuild: 22000 $r1 = -1 $r2 = -1 $r3 = 1 pixelsearch 1 App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
pixelsearch Posted March 20, 2022 Author Share Posted March 20, 2022 (edited) Thanks Exit for the test Now that you and M23 confirmed that $r3 = 1 on your computers, It makes me wonder if the C++ update code I added yesterday in this link was really necessary : "Added a 2nd way for Natural sorting (LarsJ's index creation adapted to C++) Anyway it's done and I'll let it there, especially I'm not sure how C++ Sort native function (which is boolean) can correctly deal with StrCmpLogicalW() which returns 3 possible values : -1, 0 or 1 And also because I added a personal stable sort part to LarsJ's code, in another C++ function. Who knows, it may be useful at times. But where is LarsJ, long time no see ! Edited March 20, 2022 by pixelsearch typo Link to comment Share on other sites More sharing options...
Musashi Posted March 20, 2022 Share Posted March 20, 2022 Your issue has apparently been resolved. Nevertheless, here is the result from an older system environment . AutoIt = 3.3.14.0, OS = WIN_7 Service Pack 1 CPU : X64 OS : X64 $r1 = -1 $r2 = -1 $r3 = 1 pixelsearch 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
argumentum Posted March 23, 2022 Share Posted March 23, 2022 (edited) XP 32 bit: $r1 = -1 $r2 = -1 $r3 = -1 ( both, 3.3.14.5 and 3.3.16.0 ) Edit: same in XP64SP2. Edited March 23, 2022 by argumentum pixelsearch 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
ad777 Posted March 25, 2022 Share Posted March 25, 2022 Windows 7 32 bit. AutoIt_Version: 3.3.16.0 $r1 = -1 $r2 = -1 $r3 = 1 pixelsearch 1 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
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