By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

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: 2014-12-28 07:31

AutoIt Logo

Its time to learn about AutoIt Function Arguments. To prepare a function for input, insert some variables in between the parentheses, these will contain the input supplied, and can then be used throughout the function.

AutoIt Function Arguments Examples

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.