icadea Posted May 30, 2009 Share Posted May 30, 2009 Hi all, I would like help on how to accomplish this. The data file in text that I am having Data -56 -40 -40 -32 -3 -32 I would like to AUTO count of occurance or repetition of the number within the given data set as shown below. Number of Occurance -56,1 -40,2 -32,2 -3,1 Would like to know how would I accomplish this? I have searched the forum but found mostly that you have to defined the item that need to be searched. Thanks Link to comment Share on other sites More sharing options...
Valuater Posted May 30, 2009 Share Posted May 30, 2009 The easy approach is... _FileReadToArray() _ArraySearch() FileWrite() 8) Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 30, 2009 Share Posted May 30, 2009 (edited) expandcollapse popup#include <Array.au3> ;$sData = FileRead("Data.txt") $sData = _ "-56" & @CRLF & _ "-40" & @CRLF & _ "-40" & @CRLF & _ "-32" & @CRLF & _ "-3" & @CRLF & _ "-32" $sData = StringStripCR(StringStripWS($sData, 3)) $aData = StringSplit($sData, @LF) ;It's the array of our data to check ;Creating data counting array to hold the results Dim $aData_Count[$aData[0]+1][2] ;Looping thru the array of data (each element is a number from data above) For $i = 1 To $aData[0] If $aData[$i] == "" Then ContinueLoop ;If current data element is empty, continue the loop from next element (next code will not be executed)... ;Second loop to check our new created array for existing entries (from the end to the begining, see «Step -1»), wich is filled later on For $j = $aData_Count[0][0] To 1 Step -1 ;Here we compare the current element from new counting array with the element from data array, to see if it's a duplicate (if so, just increese the counter for current element and continue the loop again from next element of data array) If $aData_Count[$j][0] = $aData[$i] Then $aData_Count[$j][1] += 1 ;Here is the counter adding proc ContinueLoop 2 ;Continue from first loop EndIf Next ;Creating new element for counting data array (with current data array element and first count) $aData_Count[0][0] += 1 $aData_Count[$aData_Count[0][0]][0] = $aData[$i] $aData_Count[$aData_Count[0][0]][1] += 1 Next ;Redim the array to remove empty elements ReDim $aData_Count[$aData_Count[0][0]+1][2] ;Display results array (data counting array :) ) _ArrayDisplay($aData_Count, "Number of Occurance")Edit: Works directly (no need in file for this example). Edited June 1, 2009 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
icadea Posted May 31, 2009 Author Share Posted May 31, 2009 Valuater, your guide and MsCreator examples have point me to the solution. Thank you. Link to comment Share on other sites More sharing options...
MrCreatoR Posted May 31, 2009 Share Posted May 31, 2009 Valuater, your guide and MsCreator examples have point me to the solution. Thank you.“point”?! I thought i gave you the full working example of your task . Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
trancexx Posted May 31, 2009 Share Posted May 31, 2009 But Ms lol ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 31, 2009 Share Posted May 31, 2009 But Ms lolOMG .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Roman9 Posted May 31, 2009 Share Posted May 31, 2009 #include <Array.au3> ;$sData = FileRead("Data.txt") $sData = _ "-56" & @CRLF & _ "-40" & @CRLF & _ "-40" & @CRLF & _ "-32" & @CRLF & _ "-3" & @CRLF & _ "-32" $sData = StringStripCR(StringStripWS($sData, 3)) $aData = StringSplit($sData, @LF) Dim $aData_Count[$aData[0]+1][2] For $i = 1 To $aData[0] If $aData[$i] == "" Then ContinueLoop For $j = $aData_Count[0][0] To 1 Step -1 If $aData_Count[$j][0] = $aData[$i] Then $aData_Count[$j][1] += 1 ContinueLoop 2 EndIf Next $aData_Count[0][0] += 1 $aData_Count[$aData_Count[0][0]][0] = $aData[$i] $aData_Count[$aData_Count[0][0]][1] += 1 Next ReDim $aData_Count[$aData_Count[0][0]+1][2] _ArrayDisplay($aData_Count, "Number of Occurance") Edit: Works directly (no need in file for this example). I'm having lots of trouble understanding the for loop/array jungle. Could you please clarify it for me with comments or something? I need something similar to this in what I'm making :/ Thanks! Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 1, 2009 Share Posted June 1, 2009 Could you please clarify it for me with comments or something?Added comments to my post with this example. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Roman9 Posted June 1, 2009 Share Posted June 1, 2009 Thank you very much MrCreatoR Link to comment Share on other sites More sharing options...
icadea Posted June 1, 2009 Author Share Posted June 1, 2009 Sorry Seem to type MS instead of Mr. Thank you for the full example Link to comment Share on other sites More sharing options...
MrCreatoR Posted June 1, 2009 Share Posted June 1, 2009 (edited) Sorry Seem to type MS instead of Mr. Thank you for the full example It's ok, if you look at my Display Name History, you will see that my nick name originaly was MsCreatoR (since i didn't knew back then how to write correctly a shorted version of «Mister» ). Edited June 1, 2009 by MrCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: 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 ProgramUDFs: 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 Examples: 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 ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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