Jump to content

Recommended Posts

Posted

Disclaimer
Please note: The following information is being provided for observational purposes only and therefore, the examples provided are for illustrative purposes only!

1. I know that the following code illustration works:

; -----------------------------------------------
Example()
; ------
Func Example()
    ; A section of code
EndFunc ;==>Example
; -----------------------------------------------

2. However, does the following illustration "work"?

; -----------------------------------------------
Example()
; ------
Func Example()
    ; A section of code
    Inside()
    ; ------
    Inside()
    ; A section of code
    EndFunc ;==>Inside()
EndFunc ;==>Example
; -----------------------------------------------

Thank you for any assistance that one may provide.

Posted (edited)
24 minutes ago, mr-es335 said:

However, does the following illustration "work"?

No, unless Inside() is a call to a function named Inside that is defined outside the Example() function. As I said you in a previous thread such constructs as nested functions are not valid to AutoIt.

Func Example()
    ; A section of code
    Inside()
    ; ------
    Inside()            ;   <<< --- this can be here if it's a function call, but if this starts with Func Inside() it's totally wrong.
    ; A section of code
    EndFunc ;==>Inside()    <<< --- this cannot be here
EndFunc ;==>Example

This is valid code:

; -----------------------------------------------
Example()
; ------
Func Example()
    ; A section of code
    Inside()    ;  First call of the function Inside()
    ; ------
    Inside()    ;  Second call of the function Inside()
EndFunc ;==>Example

Func Inside()
    ; Some code
EndFunc

 

Edited by Andreik
Posted

Andreik,

Updated example:

Example()
; ------
Func Example()
    ; A section of code
    Inside()    ;  Call to the function Inside()
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc

Observations
1. From what I gather, a function should NOT be positioned inside another function
• Such would be referred to as "a nested function"
2. A function "call" can be inserted "within" another function
2. A function should be - in a real sense, a stand-alone section of code

Both of these fragments would be considered as correct:

; -----------------------------------------------
; Example #1
Example()
Inside()
; ------
Func Example()
    ; A section of code
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
-----------------------------------------------
; Example #2
Example()
; ------
Func Example()
    ; A section of code
    Inside()    ;  Call to the function Inside()
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
; -----------------------------------------------

Observations
1. In Example #1, Example() would be executed first, followed by Inside()
2. In Example #2, Example() would be executed first, as before
• However, Inside() would only be executed only if Inside() is called within another function, as shown in Example #2.

 

Posted

That's true. But this piece of code cannot run as a single script.

; -----------------------------------------------
; Example #1
Example()
Inside()
; ------
Func Example()
    ; A section of code
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
-----------------------------------------------
; Example #2
Example()
; ------
Func Example()
    ; A section of code
    Inside()    ;  Call to the function Inside()
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
; -----------------------------------------------

Example #1 should be a script and example #2 should be another script. This is because two functions cannot have the same in the same script or in the headers included with #include.

Posted (edited)

Andriek,

I gather that I should have displayed the above in the following manner - for clarity:

Both of these fragments would be considered as correct:

1) Example #1:

; -----------------------------------------------
; Example #1
Example()
Inside()
; ------
Func Example()
    ; A section of code
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
-----------------------------------------------

2) Example #2:

-----------------------------------------------
; Example #2
Example()
; ------
Func Example()
    ; A section of code
    Inside()    ;  Call to the function Inside()
EndFunc ;==>Example

Func Inside()
    ; A section of code
EndFunc
; -----------------------------------------------

PS: I thought that the term "fragment" [...a part broken off, detached, or incomplete] would be understood...but I gather NOT!

Edited by mr-es335

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...