Nexx Posted January 30, 2011 Posted January 30, 2011 Hello you all, this is my first thread . I'm just asking what's the way (if there is of course), to make a function counter. I'll explain; in a script like this one...: _Function1 Func _Function1 msgbox(1,"hello","bye") _Function1 EndFunc ... the function1 is going to repeat itself all the time. What I'm searching and I can't find a way to do it, is to count the times that the _Function1 has been executed. Is there any way? How? Thanks for your time, waiting for answers
trancexx Posted January 30, 2011 Posted January 30, 2011 There is no way to do that. _Function1() Func _Function1() Local Static $iCounter $iCounter += 1 If $iCounter > 3 Then Return MsgBox(1, "hello No" & $iCounter, "bye No" & $iCounter) _Function1() EndFunc ♡♡♡ . eMyvnE
kylomas Posted January 30, 2011 Posted January 30, 2011 (edited) trancexx, What do you mean "does not work" "no way to do that? This was paraphrased from your code:local $icounter _Function1() MsgBox(1, "hello No" & $iCounter, "bye No" & $iCounter) Func _Function1() $iCounter += 1 If $iCounter > 3 Then Return _Function1() EndFuncand it works.kylomas Edited January 30, 2011 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
trancexx Posted January 30, 2011 Posted January 30, 2011 trancexx, What do you mean "does not work" "no way to do that? This was paraphrased from your code: local $icounter _Function1() MsgBox(1, "hello No" & $iCounter, "bye No" & $iCounter) Func _Function1() $iCounter += 1 If $iCounter > 3 Then Return _Function1() EndFunc and it works. kylomas Go to sleep. ♡♡♡ . eMyvnE
kylomas Posted January 30, 2011 Posted January 30, 2011 "zzzzzzz", "zzzzzzzz", "zzzzzzzz" Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
jchd Posted January 30, 2011 Posted January 30, 2011 @Nexx,First, welcome to the forum.Now your function1 isn't _repeating_ but _recursing_ and will promptly reach the recursion limit if no suitable logic blocks recursion at some reasonable point. With this in mind "the function1 is going to repeat itself all the time" is a dead end. I'd bet that your want the function to repeat in a loop instead of recurse upto crash.BTW the static variable can help but remember that static is still an unstable feature. OTOH a global variable initialized to 0 and incremented at every function1 invokation will do as well, less elegantly but without relying on any "use at your own risk" feature (see keyword static in help). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
Stanislav Posted January 30, 2011 Posted January 30, 2011 Why not just pass the counter to the function as a parameter? _Function1() Func _Function1($iCounter=1) If MsgBox(1, "_Function1", "I was called " & $iCounter & " time(s)") = 2 Then Exit EndIf $iCounter +=1 _Function1($iCounter) EndFunc
guinness Posted January 30, 2011 Posted January 30, 2011 Run your Example Stanislav and you will get >> Recursion level has been exceeded - AutoIt will quit to prevent stack overflow.: This is what jchd was talking about calling the same Function over and over without Returning from the previous Function, it's like an infinite mirror! UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
Stanislav Posted January 31, 2011 Posted January 31, 2011 Oh! Now I got it - there are 2 limits, MAXCALLRECURSE and MAXEXECUTERECURSE: Maximum number of times functions can recurse to themselves (5100). Thank you!
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