Jump to content

I need some help to check a bunch of scripts for duplicate functions


Recommended Posts

Ths situation is like this, i have a script which first uses _FileReadToArray to load an .au3 script and then it works on the array (renaming and deleting some stuff) but here my problems come. Sometimes i get duplicate funktion-names which of course make the scripts fail :)

So i was thinking i need to check the array for duplicate function-names before i _FileWriteFromArray back all the edited contents but i must be to tired or something because nothing i do work :)

If someone could help me with this it would be greatly appreciated!!

Link to comment
Share on other sites

Hi,

If you need to delete duplicate elements in array, then ty this:

Func _ArrayDeleteClones(ByRef $sArray)
    If Not IsArray($sArray) Then Return SetError(1)
    If UBound($sArray, 0) > 1 Then Return SetError(2)
    Local $NewArr[1], $ClonesArr[1], $IsFound=0, $NewArrCnt=0, $Extended=0
    For $i = 1 To UBound($sArray) - 1
        $IsFound = 0
        For $j = 1 To UBound($NewArr)-1
            If $sArray[$i] = $NewArr[$j] Then
                $IsFound = 1
                $Extended += 1
                ReDim $ClonesArr[UBound($ClonesArr)+1]
                $ClonesArr[UBound($ClonesArr)-1] = $sArray[$i]
                ExitLoop
            EndIf
        Next
        If Not $IsFound Then
            $NewArrCnt += 1
            ReDim $NewArr[$NewArrCnt+1]
            $NewArr[$NewArrCnt] = $sArray[$i]
        EndIf
    Next
    $NewArr[0] = UBound($NewArr) - 1
    $sArray = $NewArr
    $ClonesArr[0] = UBound($ClonesArr) - 1
    Return SetError(0, $Extended, $ClonesArr)
EndFunc

But if each element contain whole function content, then you will have to do some StringRegExpReplace() to find only function names and etc.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Ths situation is like this, i have a script which first uses _FileReadToArray to load an .au3 script and then it works on the array (renaming and deleting some stuff) but here my problems come. Sometimes i get duplicate funktion-names which of course make the scripts fail :)

So i was thinking i need to check the array for duplicate function-names before i _FileWriteFromArray back all the edited contents but i must be to tired or something because nothing i do work :P

If someone could help me with this it would be greatly appreciated!!

Help with what? You didn't show any code. What have you got so far?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi,

If you need to delete duplicate elements in array, then ty this:

Func _ArrayDeleteClones(ByRef $sArray)
    If Not IsArray($sArray) Then Return SetError(1)
    If UBound($sArray, 0) > 1 Then Return SetError(2)
    Local $NewArr[1], $ClonesArr[1], $IsFound=0, $NewArrCnt=0, $Extended=0
    For $i = 1 To UBound($sArray) - 1
        $IsFound = 0
        For $j = 1 To UBound($NewArr)-1
            If $sArray[$i] = $NewArr[$j] Then
                $IsFound = 1
                $Extended += 1
                ReDim $ClonesArr[UBound($ClonesArr)+1]
                $ClonesArr[UBound($ClonesArr)-1] = $sArray[$i]
                ExitLoop
            EndIf
        Next
        If Not $IsFound Then
            $NewArrCnt += 1
            ReDim $NewArr[$NewArrCnt+1]
            $NewArr[$NewArrCnt] = $sArray[$i]
        EndIf
    Next
    $NewArr[0] = UBound($NewArr) - 1
    $sArray = $NewArr
    $ClonesArr[0] = UBound($ClonesArr) - 1
    Return SetError(0, $Extended, $ClonesArr)
EndFuncoÝ÷ Ûú®¢×}÷ÜwöÆ¥-®(!µ»­{-y§h}×¥zاØ^vêeÆ­zÈ­Â¥u·zÛ^®'âµì^rë^vÊ&zØb b殶­seôÆ%õ6÷tW'&÷"gV÷C´GWÆ6FRgVæ·Föâf÷VæBgV÷C²

but your code is so complex :P i am not sure where i would insert it, may you please show me where??

They dont contain the whole function content, only one line per element because i load the file with _FileReadToArray, but i still think it would be better to only test the function names but i don't understand StringRegExpReplace() good enough to do that (yes i have read the helpfile!) maybe you could show me how to do that to?? :">

Well.... nothing that is usable in any way :)

It's time for me to go to bed but i will check in tomorrow.... Good night everone! :P

Link to comment
Share on other sites

#include <Array.au3> 


$String_Array=StringSplit("A|B|C|D|E|B|G","|")

_ArrayDisplay($String_Array,"")
_ArrayDeleteClones($String_Array)
_ArrayDisplay($String_Array,"")


Func _ArrayDeleteClones(ByRef $sArray)
    If Not IsArray($sArray) Then Return SetError(1)
    If UBound($sArray, 0) > 1 Then Return SetError(2)
    Local $NewArr[1], $ClonesArr[1], $IsFound=0, $NewArrCnt=0, $Extended=0
    For $i = 1 To UBound($sArray) - 1
        $IsFound = 0
        For $j = 1 To UBound($NewArr)-1
            If $sArray[$i] = $NewArr[$j] Then
                MsgBox(4096,"",$sArray[$i] )
                $IsFound = 1
                $Extended += 1
                ReDim $ClonesArr[UBound($ClonesArr)+1]
                $ClonesArr[UBound($ClonesArr)-1] = $sArray[$i]
                ExitLoop
            EndIf
        Next
        If Not $IsFound Then
            $NewArrCnt += 1
            ReDim $NewArr[$NewArrCnt+1]
            $NewArr[$NewArrCnt] = $sArray[$i]
        EndIf
    Next
    $NewArr[0] = UBound($NewArr) - 1
    $sArray = $NewArr
    $ClonesArr[0] = UBound($ClonesArr) - 1
    Return SetError(0, $Extended, $ClonesArr)
EndFunc

Link to comment
Share on other sites

It's almost right, but instead of deleting the duplicates it would be better if it executed something like

My function returns an array with all duplicates that it finds in passed array :)

#include <Array.au3>

Dim $Array[6] = [5, "Hello", "My", "Friend!", "Hello", "Friend!"]

_ArrayDisplay($Array, "Original Array")
$ClonesArr = _ArrayDeleteClones($Array)
_ArrayDisplay($ClonesArr, "Array With Deleted Clones ;)")
Edited by MsCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 1 month later...

My function returns an array with all duplicates that it finds in passed array :P

#include <Array.au3>

Dim $Array[6] = [5, "Hello", "My", "Friend!", "Hello", "Friend!"]

_ArrayDisplay($Array, "Original Array")
$ClonesArr = _ArrayDeleteClones($Array)
_ArrayDisplay($ClonesArr, "Array With Deleted Clones ;)")oÝ÷ Ûú®¢×¢¶§Øb±û§r+*º'$z·è­×¥zا۩zȧjºÚÊz-Z)ýÆz%Ëh}Û©zÄZÖ¥«­¢+Øìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô(ì(ìÍÉ¥ÁÑ¥½¸è}ÉÉå±ÑÕÁÌì±ÑÌÕÁ±¥ÑÌ¥¸¸ÉÉäÅ(ìMå¹Ñàè}ÉÉå±ÑÕÁÌ¡  åIÀÌØíÉ}ÉÉä¤(ìAɵÑȡ̤è$ÀÌØíÉ}ÉÉäôÅÉÉä(ìIÅեɵ¹Ð¡Ì¤è9½¹(ìIÑÕɸY±Õ¡Ì¤è=¸MÕÍÌ´IÑÕɹÌͽÉÑÉÉäÝ¥Ñ ¹¼ÕÁ±¥ÑÌ(ì=¸¥±ÕÉ´(ì$$$$$%ÉɽÈôÄ@(ì$$$$$%ÉɽÈôÈ(ì(ìÕÑ¡½È¡Ì¤èɹ±±(ìôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôôô)Õ¹}ÉÉå±ÑÕÁÌ¡  åIÀÌØíÉÉ%ѵ̤(%¥=MQeAôÅÕ½Ðí]%8ÌÉ}]%9=]LÅÕ½ÐìÑ¡¸ÉÑÕɸÀ($ÀÌØí½©¥Ñ¥½¹Éäô=©
ÉÑ ÅÕ½ÐíMÉ¥ÁÑ¥¹¹¥Ñ¥½¹ÉäÅÕ½Ðì¤(%½ÈÀÌØíÍÑÉ%Ñ´%¸ÀÌØíÉÉ%ѵÌ($%%9½ÐÀÌØí½©¥Ñ¥½¹Éä¹á¥ÍÑÌ ÀÌØíÍÑÉ%Ñ´¤Q¡¸($$$ÀÌØí½©¥Ñ¥½¹Éä¹ ÀÌØíÍÑÉ%Ñ´°ÀÌØíÍÑÉ%Ñ´¤($%¹%(%9áÐ($ÀÌØí¥¹Ñ%ѵÌôÀÌØí½©¥Ñ¥½¹Éä¹
½Õ¹Ð´Ä(%I¥´ÀÌØíÉÉ%ѵÍlÀÌØí¥¹Ñ%ѵ̬Åt($ÀÌØí¤ôÀ(%½ÈÀÌØíÍÑÉ-ä%¸ÀÌØí½©¥Ñ¥½¹Éä¹-åÌ($$ÀÌØíÉÉ%ѵÍlÀÌØí¥tôÀÌØíÍÑÉ-ä($$ÀÌØí¤¬ôÄ(%9áÐ(%ÉÑÕɸÄ)¹Õ¹ìôôÐí}ÉÉå±ÑÕÁÌ
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...