Jump to content

Newbie question about Call


Go to solution Solved by jchd,

Recommended Posts

Function = Function

Call = Function + Parameters optional

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Link to comment
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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • Solution

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)

Link to comment
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

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.

Link to comment
Share on other sites

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

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

 

Link to comment
Share on other sites

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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

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