Tapes Posted July 17, 2013 Share Posted July 17, 2013 So I have a hopefully not too complicated question! I have three arrays right now that are declared. Two txt files have been Read into two of these arrays seperately.I am comparing the two Arrays to decipher the differences between the two.If there is a difference, I am outputing the string that can't be found into the third array (Array3). The third Array is then written back into a new text file. For example lets say this is what my arrays looks like. Array2 should be the correct texts, while Array1 may have some variances. Array 1 = "text1,text2,text3,text4" Array 2 = "text1,text2,text3,text5" My third Array would then output Array 3 = "text4" This is what I have working right now, but I am trying to achieve a script more complicated. The two Arrays should normally be the same, but I need to check for differences. These differences may include different version of files, and missing files. The two Arrays should normally look exactly the same, but I need to check for different versions and missing strings.Array2 should be the correct versions and string, while Array1 may have some variances. Lets say these are how the Arrays look now v = version Array1 = "text1V1,text2V1,text3V2" Array2 = "text1v1,text2v1,text3v1,text4v1" Output of: Array 3 = " Missing ) text4v1, Wrong Version) text3v2" I want the output to tell me that text4v1 is "MISSING" from the first Array, and that text3v2 is the "WRONG VERSION". I am having trouble writing code to differentiate between cases. My code of what I have right now is shown below. expandcollapse popupGlobal $Array1, $Array2,$Array3 $File1 = "Path of text file" $File2 = "Path of text file" _FileReadToArray($File1, $Array1) _FileReadToArray($File2, $Array2) If IsArray($Array1) Then $iMax = UBound($Array1); get array size EndIf For $i = 1 to $iMax-1 _ArraySearch($Array2, $Array1[$i]) If @error Then _ArrayAdd($Array3, $Array1[$i]) EndIf Next _FileWriteFromArray("Results.txt", $Array3) I've tried adding the *** line to the for loop, but that didn't work either. For $i = 1 to $iMax - 1 _ArraySearch($Array1, $Array[$i]) If @error Then If NOT($Array2[$i] == $Array1) Then *** _ArrayAdd($Array3, "Missing) " & $Array2[$i]) ;_ArrayAdd($Array3, "test") Else _ArrayAdd($Array3, "Wrong Version) " & $Array2[$i]) EndIf EndIf Next Sorry still learning AutoIt, so hopefully I didn't explain it too confusingly! Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted July 17, 2013 Moderators Solution Share Posted July 17, 2013 Tapes, This seems to work correctly when I test: expandcollapse popup#include <Array.au3> ;Global $Array1, $Array2, $Array3 ;$File1 = "Path of text file" ;$File2 = "Path of text file" ;_FileReadToArray($File1, $Array1) ;_FileReadToArray($File2, $Array2) ; Simulate reading in files Global $Array1[4] = [3, "text1V1", "text2V1","text3V2"] Global $Array2[5] = [4, "text1v1", "text2v1", "text3v1", "text4v1"] Global $Array3[1] = [0] For $i = 1 To $Array2[0] ; Extract the text# part $sItem = StringRegExpReplace($Array2[$i], "(?i)^(.*)v.*$", "$1") ; Check if it exists in Array1 $iIndex = _ArraySearch($Array1, $sItem, 0, 0, 0, 1) If $iIndex = -1 Then ; It does not so add to Array3 $Array3[0] += 1 ReDim $Array3[$Array3[0] + 1] $Array3[$Array3[0]] = "Missing ) " & $Array2[$i] Else ; It does so check version If $Array1[$iIndex] <> $Array2[$i] Then ; And add to Array3 if wrong $Array3[0] += 1 ReDim $Array3[$Array3[0] + 1] $Array3[$Array3[0]] = "Wrong Version ) " & $Array1[$iIndex] EndIf EndIf Next _ArrayDisplay($Array3) All clear? M23 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...
Tapes Posted July 17, 2013 Author Share Posted July 17, 2013 Thank you for answering! I will give this a try and let you know If it works! Link to comment Share on other sites More sharing options...
Tapes Posted July 17, 2013 Author Share Posted July 17, 2013 This worked amazingly! Thank you so much Melba!!! Xandy 1 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