SorryButImaNewbie

Newbie question about Call

11 posts in this topic

Hello!

Can someone please explain to me the difference between these 2 functions?

Func Example1()
Function
EndFunc

Func Example2()
Call("Function")
EndFunc

Just because I used to "call" some of my functions without the Call function, I'm sure that I miss something, but for me it looks like they do the same thing.

Thank you!

Share this post


Link to post
Share on other sites



Function = Function

Call = Function + Parameters optional

Share this post


Link to post
Share on other sites

Thank you for the help!

It's still not a 100% clear to me.

I gave parameters to functions before, without Call.

Like this:

Local $TopUpName = "TopUpHUFKiadási(sztornó)_" & ControlGetText("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox5]")
    ;1. PDF
    RenamePDF($TopUpName)
    ;2. PDF
    $TopUpName = "" & $TopUpName & "(2)"
    RenamePDF($TopUpName)
    ;3.PDF
    Local $TopUpName = "TopUpHUFKiadásiSzámla(sztornó)_" & ControlGetText("PDFCreator 1.", "", "[CLASSNN:ThunderRT6TextBox5]")
    RenamePDF($TopUpName)
    ;4.PDF
    $TopUpName = "" & $TopUpName & "(2)"
    RenamePDF($TopUpName)

Or do you mean, that If I use call then giving parameter is optional? How would something that needs parameter would run without them?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It is not optional, the failure return value of Call states:

Failure:    sets the @error flag to 0xDEAD and @extended to 0xBEEF if the function does not exist or invalid number of parameters.

to make a Function call you can do it a couple ways:

Local $test = False
 
Example($test) ; simple function call passing 1 parameter
 
Func Example($bool)
    If $bool = False Then MsgBox(0, "Test", "1 Parameter = " & $bool)
EndFunc

Or

Local $test = True
 
Call("Example", $test) ; using call to call the function with 1 parameter
 
Func Example($bool)
    If $bool = True Then MsgBox(0, "Test", "1 Parameter = " & $bool)
EndFunc

All clear? :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Thank you @MikahS!

I know how to call a function (now I used both your above methods in my scripts), but I don't know whats the difference? Maybe more importantly, when should I use Call("FunctionName") and when should I just simply use FunctionName()?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Also:

Local $fct = ConsoleWrite

$fct("Hello!")

Call offers only one unique possibility: passing arguments in CallArgArray

Edited by jchd

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

The call function can be handy when you have multiple functions with similar naming conventions

ex:

#include <GUIconstants.au3>
$gui = GUIcreate("Test",400,400)
$button1 = GUICtrlCreateButton("1",10,10,380,80)
$button2 = GUICtrlCreateButton("2",10,110,380,80)
$button3 = GUICtrlCreateButton("3",10,210,380,80)
$button4 = GUICtrlCreateButton("4",10,310,380,80)
GUISetState(@SW_SHOW)
while 1
    switch GUIGetMsg()
        Case $Button1,$Button2,$button3,$button4
            $mouse = GUIGetCursorInfo()
            Call("func" & GUIctrlRead($mouse[4]))
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func func1()
    msgbox(0,0,"Func1 called!")
EndFunc

Func func2()
    msgbox(0,0,"Func2 called!")
EndFunc

Func func3()
    msgbox(0,0,"Func3 called!")
EndFunc

Func func4()
    msgbox(0,0,"Func4 called!")
EndFunc

Regards

Javi

1 person likes this

give a man an application, and he'll be frustrated for the day, Teach him how to program applications and he'll be frustrated for a lifetime.

Share this post


Link to post
Share on other sites

Thank you guys, for all of your help!

I can say I learnt something today :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

For one, as jchd stated you can use a special array to pass arguments, like so:

Local $aArgs[4]
$aArgs[0] = "CallArgArray" ; required, otherwise the array won't be recognized as containing argmts
$aArgs[1] = "I am a string parameter"
$aArgs[2] = 50
$aArgs[3] = True

Call("Example", $aArgs)

Func Example($str, $int, $bool)
    MsgBox(0, "test", "string is: " & $str & @CRLF & _
            "Int is: " & $int & @CRLF & _
            "Bool is: " & $bool)
EndFunc   ;==>Example

In my experience, I've only ever used it with functions that have many parameters, with an array like above. Otherwise, I just use the normal function call like so:

Local $test = "hi"
 
Example($test)
 
Func Example($text)
    MsgBox(0, "", $text)
EndFunc

Edit: Good to hear. :)

Edited by MikahS
1 person likes this

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Thank you Master @MikahS! :)

1 person likes this

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

It is my pleasure, @SorryButImaNewbie.  ^_^

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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