Hest Posted May 5, 2009 Posted May 5, 2009 (edited) I'm having a little trouble finding the right function to count my array. I have an array that can have a random number of entries, but when I use Ubound to count the array, it also counts the entries that are empty. I can get up to 365 entries total in the array Global $value[10] = [100, 132, 138, 117, 122, 108, 130] Can I somehow make an array where I dont have a preset number ($value[] = [100, 132, 138, 117, 122, 108, 130]) or can I somehow find a result of 7 entries with my array example? I don't want to loop through the array and check for empty entries if there are other ways to do it. Edited May 6, 2009 by Hest Software:Model Train Calculator (Screen)Autoit3 beginner!
99ojo Posted May 5, 2009 Posted May 5, 2009 I'm having a little trouble finding the right function to count my array. I have an array that can have a random number of entries, but when I use Ubound to count the array, it also counts the entries that are empty. I can get up to 365 entries total in the array Global $value[10] = [100, 132, 138, 117, 122, 108, 130] Can I somehow make an array where I dont have a preset number ($value[] = [100, 132, 138, 117, 122, 108, 130]) or can I somehow find a result of 7 entries with my array example? I don't want to loop through the array and check for empty entries if there are other ways to do it.Hi, #include <array.au3> Global $value[10] = [100, 132, 138, 117, 122, 108, 130] $aresult = _ArrayFindAll ($value, "") MsgBox (0,"", UBound ($value) - UBound ($aresult)) ;-)) Stefan
MrCreatoR Posted May 5, 2009 Posted May 5, 2009 I don't want to loop through the array and check for empty entries if there are other ways to do it.No there isn't, you must loop through the array to check the empty entries. 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
Juvigy Posted May 5, 2009 Posted May 5, 2009 Sort the array , find the min and max value index. The empty entries will be right after the min or max value , have to test to find out.
MrCreatoR Posted May 5, 2009 Posted May 5, 2009 But it's better to generate the array in the way that allows you to use only non empty entries, for example: #include <Array.au3> Global $avArray[100] For $i = 1 To 15 $avArray[0] += 1 $avArray[$i] = "Some data #" & $i Next _ArrayDisplay($avArray) ;Here we use the [0] to indicate where non empty entries ending For $i = 1 To $avArray[0] ConsoleWrite($avArray[$i] & @CRLF) If $avArray[$i] = "" Then MsgBox(64, 'Title', 'Empty entry: ' & $i) ;This will never be shown, since we check only filed entries Next 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
Hest Posted May 5, 2009 Author Posted May 5, 2009 Thx to all of you. I'll give Stefans idear a try and see how it works out. Software:Model Train Calculator (Screen)Autoit3 beginner!
Zinthose Posted May 5, 2009 Posted May 5, 2009 Here are two examples but the" for loop" version is fastest.#include 'array.au3' Global $value[10] = [100, 132, 138, 117, 122, 108, 130] Global $result = 0 Global $timer = 0, $dif = 0 $timer = TimerInit() $result = _ArrayCount($value) $dif = TimerDiff($timer) ConsoleWrite("_ArrayCount = " & $dif & @CRLF) ConsoleWrite(" result = " & $result & @CRLF) $timer = TimerInit() $result = _ArrayCountv2($value) $dif = TimerDiff($timer) ConsoleWrite("_ArrayCountv2 = " & $dif & @CRLF) ConsoleWrite(" result = " & $result & @CRLF) Func _ArrayCount(ByRef $Array) Local $Undefined = _ArrayFindAll($Array, "") Return UBound($Array) - UBound($undefined) EndFunc Func _ArrayCountv2(ByRef $Array) Local $i, $count = 0 For $i = 0 To UBound($Array) - 1 If $Array[$i] <> "" Then $count += 1 Next Return $count EndFuncResults_ArrayCount = 0.613206427073832 ms_ArrayCountv2 = 0.0466539741782824 ms --- TTFN
GEOSoft Posted May 5, 2009 Posted May 5, 2009 How did you create the array? If it was with _FileReadToArray() then there is a faster method you could use with RegExp. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Hest Posted May 5, 2009 Author Posted May 5, 2009 How did you create the array? If it was with _FileReadToArray() then there is a faster method you could use with RegExp.I'll have a look at that also. I'm going to read everything from a file and into an array. Here are two examples but the" for loop" version is fastest.Thx to you too. I tried the script Stefan wrote and thats alot slower than the for script I have something to work with now. Software:Model Train Calculator (Screen)Autoit3 beginner!
GEOSoft Posted May 5, 2009 Posted May 5, 2009 $aRegExp = StringRegExp(FileRead("C:\some\path\myfile.txt", "(?i)\s*(\S\V*)\v?", 3) $iLines = Ubound($aRegExp) $aRegExp will not contain any blank Elements so $iLines will be the number of non-empty lines Note This can also be used to read the file to an array. It also strips leading space from each line. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
Hest Posted May 5, 2009 Author Posted May 5, 2009 $aRegExp = StringRegExp(FileRead("C:\some\path\myfile.txt", "(?i)\s*(\S\V*)\v?", 3) $iLines = Ubound($aRegExp) $aRegExp will not contain any blank Elements so $iLines will be the number of non-empty lines Note This can also be used to read the file to an array. It also strips leading space from each line. Thx, this I can use. Will make it alot faster. How can I store everything in an array? Software:Model Train Calculator (Screen)Autoit3 beginner!
GEOSoft Posted May 5, 2009 Posted May 5, 2009 (edited) Thx, this I can use. Will make it alot faster. How can I store everything in an array?$aRegExp is an array. It just doesn't have leading spaces or empty elements. Edited May 5, 2009 by GEOSoft George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
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