Sign in to follow this  
Followers 0
Nexx

A Function counter?

9 posts in this topic

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 ;)

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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()
EndFunc

and it works.

kylomas

Edited 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

"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

Share this post


Link to post
Share on other sites

@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 here
RegExp tutorial: enough to get started
PCRE 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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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!


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Oh! Now I got it - there are 2 limits, MAXCALLRECURSE and MAXEXECUTERECURSE: Maximum number of times functions can recurse to themselves (5100).

Thank you!

Share this post


Link to post
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
Sign in to follow this  
Followers 0