AutoIt Function Arguments

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

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)
EndFunc

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)
EndFunc

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.

Post comment

Links that you insert are not nofollowed, but will be removed by admins if they are considered spam.

[url=Absolute URL for page]TITLE[/url]

You should insert code boxes around code examples, which will be automatically syntax highlighted.

[code1 html|css|javascript|php|sql]Your Code Here[/code1]

You may want to read our Privacy Policy before submitting your comment.