By using this site you agree to the use of cookies.

Learn more

Share via:

AutoIt Function Arguments

How to pass arguments to functions in AutoIt, includes an example using a simple MsgBox to show errors depending on input.

Edited: 2017-02-08 02:48

AutoIt Logo

It's time to learn about Function Arguments in AutoIt. Function arguments can be used to pass data on to your functions from elsewhere in your script.

To make a function accept input through arguments, simply place variables in between the parentheses of the function. The variables will then contain the input, and can then be used throughout the function.

Continuing the example script from the last tutorial, here is how we pass a single variable to our newly created function.

MessageFun('This is some message')

Func MessageFun($Msg)
  MsgBox(4096, "Result", $Msg)

Above can be used to output a message, could be a error message, or whatever you have going on.

To make the function accept multiple values, simply separate the arguments with comma.

MessageFun('Error: Unable to install file: ', '(Name of File)')

Func MessageFun($Msg, $Msg2)
  MsgBox(4096, "Result", $Msg & $Msg2)

Also note that we used the ampersand to join the two strings in $Msg and $Msg2, this is referred to as String Concatenation, you can read more about that in the tutorial on AutoIt Variables.