Jump to content

Recommended Posts

Posted (edited)

Hello. What is the aim of the #Region II:

#include <MsgBoxConstants.au3>

Func func1 ()

   Return True

EndFunc

#Region I(call function with parentheses)

MsgBox($MB_SYSTEMMODAL, "", func1())

#EndRegion

#Region II(call function without parentheses)

MsgBox($MB_SYSTEMMODAL, "", func1)

#EndRegion

I know that #Region II func1 returns itself by reference(its address) to MsgBox(nothing to see but fact).

I am going to prove what I said before:

#include <MsgBoxConstants.au3>

Func func1 ()

   Return True

EndFunc

Global $varFunc1 = func1

MsgBox($MB_SYSTEMMODAL, "", $varFunc1())

What is the aim of calling function without parentheses? Give example. Thank you...

Edited by rizaado
  • Moderators
Posted

rizaado,

Welcome to the AutoIt forums.

I think you have answered your own question - you use the function name without parentheses to assign it to a variable. One advantage is that you can then pass this variable as a parameter to another function which can then internally call whatever function was assigned to the variable - look at the use of $hUserFunction in  _ArrayDisplay to see this in action.

I am afraid that you will have to wait for someone more knowledgeable than me to get more info than that.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Melba23, thank you once again for your comment but if someone wants to continue discussing this topic try on I will be waiting. I think I understand my misunderstood before. Some days I have professional deviation... I think that there are parts of the documentation that must be updated and must be written for the first time. I offer my services...

Edited by rizaado
Posted

..... What is the aim of the #Region II:

....
#Region II(call function without parentheses)
MsgBox($MB_SYSTEMMODAL, "", func1)
#EndRegion

....

My understanding is there are two way to call a function ( maybe 3 ways when using Execute):-

"function name" followed by parentheses; and,

Call ( "function name" [, param1 [, param2 [, paramN]]] ).

In all cases the "function name" may be stored in a variable.

An example.

#include <MsgBoxConstants.au3>

func2(MsgBox, func1) ; The two parameters are names of functions.

#region II(Is not calling a function when without parentheses)
MsgBox($MB_SYSTEMMODAL, "2", func1) ; Meaningless - just a function name
#endregion II(Is not calling a function when without parentheses)

#region III(function names without parentheses as parameters)
MsgBox($MB_SYSTEMMODAL, "3", func1, MsgBox, Chr) ; More meaningless function names.
#endregion III(function names without parentheses as parameters)


Func func2($sBuiltInFunc, $Func)
    $sBuiltInFunc($MB_SYSTEMMODAL, "1", $Func()) ; Function name in variable with following parentheses, calls that function.
    Return True
EndFunc   ;==>func2

Func func1()
    Return True
EndFunc   ;==>func1

 

 

Posted

I guess you could go this route too.

; the practices you see here aren't exactly always the best
; only meant for demonstration purposes

#include <Array.au3>

Const $numbers[10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Const $numbers_by_two = Map($numbers, MultByTwo)

_ArrayDisplay($numbers_by_two)

Func Map(Const $list, Const $function)
    Local Const $u_bound = UBound($list) 
    
    Local $new_list[$u_bound]
    
    For $i = 0 To $u_bound - 1
        $new_list[$i] = $function($list[$i])
    Next
    
    Return $new_list
EndFunc

Func MultByTwo(Const $number)
    Return $number * 2
EndFunc

 

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...