WideBoyDixon Posted May 11, 2009 Share Posted May 11, 2009 (edited) I've had this kicking around for some time now. My original intention was to write a WinDiff style application in AutoIt but my enthusiasm for it was waned dramatically over the last couple of months. I've attached two files here. The first one contains the _ArrayCompare function which can be used to compare two one-dimensional arrays. My first reason for writing this was to use it after _FileReadToArray() to compare two similar files. However, I subsequently realised that I could use it to do other array comparisons from any of the AutoIt functions that return an array (WinList() for example). The second file contains some example code for how it could be used; together with a very basic WinDiff style dialog which has swathes of missing functionality The basic premise is this. Call _ArrayCompare() with two one-dimensional arrays $aLeft and $aRight. It works best if they're at least similar. The return is an array of arrays which has two elements. The first element is the script for $aLeft and the second element is the script for $aRight. The scripts themselves are arrays with the same dimensions as the original arguments but with a zero or one in each entry to indicate whether the array entry at that point is unchanged (zero) or changed (one). By processing these scripts intelligently you can determine whether entries have been deleted/changed/inserted as appropriate.Of course, I realise as I'm typing this that it all sounds rather complex. However, it should be straightforward so I'll try to explain a scenario:Global $aLeft[9] = ["The", "big", "black", "cat", "sat", "on", "the", "mat", "again."] Global $aRight[8] = ["The", "dog", "sat", "on", "the", "white", "cat", "ouch!"] Glboal $aRet = _ArrayCompare($aLeft, $aRight)From this code you should get:$aRet[0] = [0, 1, 1, 1, 0, 0, 0, 1, 1] $aRet[1] = [0, 1, 0, 0, 0, 1, 1, 1]The zeroes show where the two arrays "line up" which is on ["The"] (element zero) and ["sat", "on", "the"] (elements 4-6 in $aLeft and 2-4 in $aRight).I hope someone finds this useful in some way. My code is based on the diff algorithm from GNU but is much simplified for AutoIt implementation. The code can be found HERE.As always, have fun.WBD Edited May 20, 2009 by WideBoyDixon [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
WideBoyDixon Posted May 13, 2009 Author Share Posted May 13, 2009 Normally I wouldn't do this but since I spent a few days on this one I was hoping that someone would provide some feedback. I won't bump again I promise ... [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Yashied Posted May 13, 2009 Share Posted May 13, 2009 Very interesting. One remark: I think it would be better to use ByRef for _ArrayCompare() function. Func _ArrayCompare(ByRef $aLeft, ByRef $aRight) My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
pillbug Posted July 6, 2009 Share Posted July 6, 2009 I've had this kicking around for some time now. My original intention was to write a WinDiff style application in AutoIt but my enthusiasm for it was waned dramatically over the last couple of months. I've attached two files here. The first one contains the _ArrayCompare function which can be used to compare two one-dimensional arrays. My first reason for writing this was to use it after _FileReadToArray() to compare two similar files. However, I subsequently realised that I could use it to do other array comparisons from any of the AutoIt functions that return an array (WinList() for example). The second file contains some example code for how it could be used; together with a very basic WinDiff style dialog which has swathes of missing functionality The basic premise is this. Call _ArrayCompare() with two one-dimensional arrays $aLeft and $aRight. It works best if they're at least similar. The return is an array of arrays which has two elements. The first element is the script for $aLeft and the second element is the script for $aRight. The scripts themselves are arrays with the same dimensions as the original arguments but with a zero or one in each entry to indicate whether the array entry at that point is unchanged (zero) or changed (one). By processing these scripts intelligently you can determine whether entries have been deleted/changed/inserted as appropriate. Of course, I realise as I'm typing this that it all sounds rather complex. However, it should be straightforward so I'll try to explain a scenario: Global $aLeft[9] = ["The", "big", "black", "cat", "sat", "on", "the", "mat", "again."] Global $aRight[8] = ["The", "dog", "sat", "on", "the", "white", "cat", "ouch!"] Glboal $aRet = _ArrayCompare($aLeft, $aRight) From this code you should get: $aRet[0] = [0, 1, 1, 1, 0, 0, 0, 1, 1] $aRet[1] = [0, 1, 0, 0, 0, 1, 1, 1] The zeroes show where the two arrays "line up" which is on ["The"] (element zero) and ["sat", "on", "the"] (elements 4-6 in $aLeft and 2-4 in $aRight). I hope someone finds this useful in some way. My code is based on the diff algorithm from GNU but is much simplified for AutoIt implementation. The code can be found HERE. As always, have fun. WBD I've been looking for something like this for sorting some data. I've been using unix libraries, but this let's me sort the data in autoit. Thanks so much for posting how you did this! Link to comment Share on other sites More sharing options...
Liendil Posted May 17, 2014 Share Posted May 17, 2014 (edited) Hello WideBoyDixon, I know this post is old but I need some help on this if you don't mind. First of all, let me thank you for this, I think it is exactly what I was seeking for and I would like to ask you something : You said "By processing these scripts intelligently you can determine whether entries have been deleted/changed/inserted as appropriate.". It seems I'm not as clever as I thought xD So let me explain my problem. I try to develop a program in which it has to compare two texts and counting the mistakes made by the user (that means that I'm not really interested in knowing if the word has been changed, inserted or if it's missing). The first one is an original one copied from a text file to a simple Edit control. The second text is entered by the user in a RichEdit (because I would like to color some words later). So could you help me to count each mistake made by the user with your two "0 or 1" arrays? Like some kind of formula... I would be grateful for that (The two arrays are already in my script and it's working well : "1" if there's a difference, "0" if there's none). Edited May 17, 2014 by Liendil 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