bobele Posted August 12, 2009 Share Posted August 12, 2009 Hi I have a file, which contains a lot of numbers line by line. Most of them are in correct order. For example, the file contains the following data: 12 13 14 16 18 18 19 20 21 22 23 I need to check if the files contains duplicates and if the order of the numbers is correct. I only need to know if the order is correct, and if there are existing duplicates. It doesn't matter where. Until now, I've written the attached script. I'm a bit clueless how to continue. Thank you FindDuplicates_CheckOrder.au3 Link to comment Share on other sites More sharing options...
Manjish Posted August 12, 2009 Share Posted August 12, 2009 As I see u sorted the array in descending or ascending order (whichever u want).. Now simply write it to the file by filewriteline() and a for loop.. To check duplicate entries.. Take each element of this array and check if the consecutive element is same.. like this: ;$array is ur sorted array for $i=1 to $array[0] if $array[$i]=$array[$i+1] then msgbox(4096,"Message","Duplicate No." & $array[$i]) [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
rudi Posted August 12, 2009 Share Posted August 12, 2009 (edited) Hi. [howto check, if a file has numbers unique and in correct order] Check out _filereadtoarray(),_arrayunique(), _arraysort(). If the numbers are all unique, ubound() of the original and the resulting array (_arrayunique) will be the same. For the order just step through all array elements and error out, if the next value isn't greater than the last one. _arraysort() will help to get the correct order in case you wanna save it out to a file. Regards, Rudi. Edited August 12, 2009 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! Link to comment Share on other sites More sharing options...
Manjish Posted August 12, 2009 Share Posted August 12, 2009 Here's what I mean: #include <Array.au3> Dim $File,$ARRAY[1] Dim $FileReadLine $file = FileOpen("targetnums.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop _ArrayAdd($ARRAY,$line) Wend FileClose($file) _ArraySort($ARRAY) ;_ArrayDisplay($ARRAY) $file1=FileOpen("targetnums.txt",2) For $i=1 to UBound($array)-1 FileWriteLine($file1,$array[$i]) If ($i+1)>(UBound($array)-1) Then Exit Else If $array[$i]=$array[$i+1] Then MsgBox (4096,"message","duplicate No."& $array[$i]) EndIf Next [font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com Link to comment Share on other sites More sharing options...
bobele Posted August 14, 2009 Author Share Posted August 14, 2009 Thanks Rudi and Manjish Finally I figured out, how to do the checks with your help. Thanks to you BobeleFindDuplicates_CheckOrder.au3 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