lordicast Posted September 3, 2008 Share Posted September 3, 2008 Im making a script that list to array 7 digits phone numbers from a phone list , is there a way to delete or not write duplicate numbers to array? [Cheeky]Comment[/Cheeky] Link to comment Share on other sites More sharing options...
lordicast Posted September 4, 2008 Author Share Posted September 4, 2008 Bump ^ example pleaseeeee $SourceFile = FileOpen(@ScriptDir&"\parsed.vir", 0) $strInput = fileread($sourcefile) $SourceMaster = Fileopen(@ScriptDir&"\masterlist.vir", 0) $strMaster = fileread($sourcemaster) If $SourceMaster = -1 Then MsgBox(0, "Unable to opent file", "please rename to parsed.vir") Exit EndIf $yoko = StringRegExp ($strinput,$strmaster[0][,1]) ConsoleWrite($yoko) [Cheeky]Comment[/Cheeky] Link to comment Share on other sites More sharing options...
Valuater Posted September 4, 2008 Share Posted September 4, 2008 (edited) Not tested.... #include <File.au3> #include <Array.au3> Dim $File_1 = @ScriptDir & "\parsed.vir" Dim $File_2 = @ScriptDir & "\masterlist.vir" Dim $aRecords, $bRecords If Not _FileReadToArray($File_1, $aRecords) Then ; read the parsed list MsgBox(4096, "Error", " Error reading File #1 to Array error:" & @error) Exit EndIf If Not _FileReadToArray($File_2, $bRecords) Then ; read the master list MsgBox(4096, "Error", " Error reading File #2 to Array error:" & @error) Exit EndIf For $i = 1 To $aRecords[0] ; go through the parsed list to see if a duplicate in already in the master list If _ArraySearch($bRecords, $aRecords[$i]) <> -1 Then _ArrayDelete($aRecords, $aRecords[$i]) ; if it is, delete it from the parsed list Next _ArrayDisplay($aRecords) ; the array info to be added to the master list $hFile = FileOpen($File_2, 1) ; 1 = append _FileWriteFromArray($hFile, $aRecords, 1) ; write to the master list FileClose($hFile) 8) Edited September 4, 2008 by Valuater Link to comment Share on other sites More sharing options...
lordicast Posted September 4, 2008 Author Share Posted September 4, 2008 Thank you for your help, im gettting this error when i try to load. test.au3 (20) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: If _ArraySearch($bRecords, $aRecords[$i]) <> -1 Then _ArrayDelete($aRecords, $aRecords[$i]) If _ArraySearch($bRecords, ^ ERROR the lists look like this in notepad. 5555556 5555557 5555558 5555559 5555557 5555551 5555553 5555554 [Cheeky]Comment[/Cheeky] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 4, 2008 Moderators Share Posted September 4, 2008 (edited) #include <array.au3> Local $a_array[5] = ["apple", "orange", "apple", "orange", "apple"] _ArrayUnique($a_array) _ArrayDisplay($a_array) Func _ArrayUnique(ByRef $aArray, $vDelim = '', $iBase = 0, $iCase = 0) If Not IsArray($aArray) Then Return SetError(1, 0, 0) If $vDelim = '' Then $vDelim = Chr(1) Local $sHold = "" For $iCC = $iBase To UBound($aArray) - 1 If Not StringInStr($vDelim & $sHold, $vDelim & $aArray[$iCC] & $vDelim, $iCase) Then $sHold &= $aArray[$iCC] & $vDelim EndIf Next $sHold = StringTrimRight($sHold, StringLen($vDelim)) If $sHold And $iBase = 1 Then $aArray = StringSplit($sHold, $vDelim) Return SetError(0, 0, $aArray) ElseIf $sHold And $iBase = 0 Then $aArray = StringRegExp($sHold & $vDelim, "(?s)(.+?)" & $vDelim, 3) Return SetError(0, 0, $aArray) EndIf Return SetError(2, 0, 0) EndFunc Edited September 4, 2008 by SmOke_N Forgot code tags Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
someone Posted September 4, 2008 Share Posted September 4, 2008 (edited) The reason the code is erroring is once it deletes an element in the array, the entire array becomes 1 element smaller, even though you are still stepping to the same number.IE;If you have an array[10], and delete one, its now an array[9], so the code will fail trying to read array[10]. You can approach it different ways, the easiest might just be to step through the array backwards. Or you could just grab all the numbers into an array, and then delete the duplicates.http://www.autoitscript.com/forum/index.ph...rray++duplicatehttp://www.autoitscript.com/forum/index.ph...rray++duplicateTheres probably a more intelligent fix but hey I'm eating lunch over here.EDIT: D'oh! too late Edited September 4, 2008 by someone While ProcessExists('Andrews bad day.exe') BlockInput(1) SoundPlay('Music.wav') SoundSetWaveVolume('Louder') WEnd Link to comment Share on other sites More sharing options...
lordicast Posted September 4, 2008 Author Share Posted September 4, 2008 (edited) I think i got it guys. thanks alot to everyone that helped you all had a big piece of the puzzle, this will really make life easier. Final product expandcollapse popup#include <File.au3> #include <Array.au3> Dim $File_1 = @ScriptDir & "\parsed.vir" Dim $aRecords If Not _FileReadToArray($File_1, $aRecords) Then; read the parsed list MsgBox(4096, "Error", " Error reading parsed error:" & @error) Exit EndIf _Array1MakeUnique($aRecords) _ArrayDisplay($aRecords); the array info to be added to the master list $hFile = FileOpen($File_1, 2); 2 = erase and write _FileWriteFromArray($hFile, $aRecords, 1); write to the master list FileClose($hFile) ;Function takes an array and removes all duplicate items. Upon return, array is in original order (not sorted) Func _Array1MakeUnique(ByRef $aIn, $iBase = 1, $CaseSense = 0) ;Check for proper input If UBound($aIn, 0) <> 1 Then SetError(1) Return 'This function only works on 1-d arrays' EndIf ;create a working array If $iBase Then $iBase = 1 $iInTop = $aIn[0] Else $iBase = 0 $iInTop = UBound($aIn) - 1 EndIf Local $aTemp[$iInTop + 2 - $iBase][2], $i For $i = $iBase To $iInTop $aTemp[0][0] = $aTemp[0][0] + 1 $aTemp[$aTemp[0][0]][0] = $aIn[$i] $aTemp[$aTemp[0][0]][1] = $i Next _ArraySort($aTemp, 0, 1, $aTemp[0][0], 2, 0) ;Remove duplicates from working array Local $Skip = 0 $i = $iBase While $i <= $aTemp[0][0] - $Skip ;Set $Skip to skip over duplicates ($Skip is an offset to copy (move) elements) While $i + $Skip + 1 <= $aTemp[0][0] And ((Not $CaseSense And $aTemp[$i][0] = $aTemp[$i + $Skip + 1][0]) Or ($CaseSense And $aTemp[$i][0] == $aTemp[$i + $Skip + 1][0])) ;Make sure you're using the earliest instance of the duplicate If $aTemp[$i][1] > $aTemp[$i + $Skip + 1][1] Then $aTemp[$i][0] = $aTemp[$i + $Skip + 1][0] $aTemp[$i][1] = $aTemp[$i + $Skip + 1][1] EndIf ;Increase $Skip to skip over this duplicate element $Skip = $Skip + 1 WEnd $i = $i + 1 If $Skip And $i + $Skip <= $aTemp[0][0] Then $aTemp[$i][0] = $aTemp[$i + $Skip][0] $aTemp[$i][1] = $aTemp[$i + $Skip][1] EndIf WEnd $aTemp[0][0] = $i - 1 ReDim $aTemp[$i][4] ;copy working array back to original array _ArraySort($aTemp, 0, 1, $aTemp[0][0], 2, 1) If $iBase Then ReDim $aIn[$aTemp[0][0] + 1] $aIn[0] = $aTemp[0][0] Else ReDim $aIn[$aTemp[0][0]] EndIf For $i = 1 To $aTemp[0][0] $aIn[$i - (1 -$iBase)] = $aTemp[$i][0] Next EndFunc Edited September 4, 2008 by lordicast [Cheeky]Comment[/Cheeky] 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