Jump to content
Sign in to follow this  
Guest tamirousmc77

Function within a function

Recommended Posts

Guest tamirousmc77

I have had issues where a function run inside another function fails or does not run. Is this by design or is there something missing? Any thoughts or suggestions are welcome. Need this information for a high priority script I am finishing up.

:)

Share this post


Link to post
Share on other sites
SlimShady

You can't nest functions in functions in AutoIt.

I haven't programmed much but this does make sense to me.

Share this post


Link to post
Share on other sites
Blue_Drache

You can't nest functions in functions in AutoIt.

I haven't programmed much but this does make sense to me.

<{POST_SNAPBACK}>

Why not? My string manipulation examples are a perfect demonstration of nested functions. See below:

I have had issues where a function run inside another function fails or does not run.  Is this by design or is there something missing?  Any thoughts or suggestions are welcome.  Need this information for a high priority script I am finishing up.

:)

<{POST_SNAPBACK}>

Functions can call other functions all day long. It's called "recursion" and you are allowed *checks help file* "Maximum depth of recursive function calls: 384 levels"

That's very deep, and if you run out of recursive space, then you need to restructure your script.

Example:

$ppn = StringUpper(StringRight(StringMid($screen, $tem, 23), 6))

There's 3 levels of recursion on default functions in that example. StringMid is performed first, then StringRight, and finally StringUpper.

Example 2:

If Inelg($a,"400","273") = 1 then MsgBox(0x23,"Stop!","Found an error code!")


Func Inelg($sScreen, $sCode1, $sCode2 = "")
   GetScreen($sScreen)
   Local $inel
   
   $inel = ClipGet()
   If @error Then Return 0
   
   $inel = StringStripWS($inel, 8)
   $inel = StringMid($inel, StringInStr($inel, "INELRSNS:"), 30)
   $inel = StringTrimLeft($inel, 9)
   $inel = StringLeft($inel, 9)
      
   If StringRight($inel, 3) = $sCode1 Or StringLeft($inel, 3) = $sCode1 Or StringTrimLeft(StringLeft($inel, 6), 3) = $sCode1 _
         Or StringRight($inel, 3) = $sCode2 Or StringLeft($inel, 3) = $sCode2 Or StringTrimLeft(StringLeft($inel, 6), 3) = $sCode2 _
         Then Return 1   
   Return 0
EndFunc ;==>Inelg

Func GetScreen($screen)
   WinActivate($screen)
   Send("{ctrldown}{insert 2}{ctrlup}")
EndFunc ;==>GetScreen

The above uses the GetScreen function within the Inelg function.

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites
Valik

Blue_Drache, you demonstrate nesting but explain it as if it were recursion. There is a difference. Recursion is when you call functionA from within functionA or from within functionB which calls functionA. Or in other words. A function is called multiple times before returning. Although I'm sure the recursion limit is applied to nested function calls as well, it's still not actually recursion so shouldn't be described using that terminology.

Example of recursion:

Func functionA()
    functionA()
EndFunc

As to the original question, it's too vague. It could mean defining local functions:

Func A()
    Func B()
       ; Do Stuff
    EndFunc
    
    B()
EndFunc

; B() <--- Would be illegal, B would be local to A()

That is of course, not supported.

It could mean nested function calls (As demonstrated by Blue_Drache):

$ppn = StringUpper(StringRight(StringMid($screen, $tem, 23), 6))

It could mean calling functions from within another function:

Func A()
   StringUpper("test")
EndFunc

Or it could mean something else entirely. Not enough information has been provided.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.