Monday, April 4, 2011

Finding the Correct Include For Your AutoIT Scripts

Includes are files that contain prewritten functions for AutoIT. Think of them as functions written into your script that you can call to perform actions for you. You can utilize these files by adding them to your script with the following:

Code:
#include <filename.au3>

Table 1 lists the standard includes that accompany the AutoIT v3 installation.

Standard AutoIT v3 Includes Table

Include Description
Array.au3 Functions that assist with array management
AVIConstants.au3 AVI Constants
ButtonConstants.au3 Button Constants
Color.au3 Functions that assist with color management
ComboConstants.au3 ComboBox Constants
Constants.au3 Various AutoIt Constants
Date.au3 Functions that assist with dates and times
DateTimeConstants.au3 DateTime Control Constants
EditConstants.au3 Edit Constants
File.au3 Functions that assist with files and directories
GuiCombo.au3 Functions that assist with ComboBox
GUIConstants.au3 Includes all GUI related constants
GUIConstantsEx.au3 Constants to be used in GUI applications
GUIDefaultConstants.au3 GUI default control styles
GuiEdit.au3 Functions that assist with Edit control
GuiIPAddress.au3 Used to create a GUI IP Address Control
GuiList.au3 Functions that assist with Listbox
GuiListView.au3 Functions that assist with ListView
GuiMonthCal.au3 Functions that assist with MonthCal
GuiSlider.au3 Functions that assist with Slider Control “Trackbar”
GuiStatusBar.au3 Functions that assist with the Statusbar control
GuiTab.au3 Functions that assist with the Tab Control
GuiTreeView.au3 Functions that assist with TreeView
IE.au3 Internet Explorer Automation UDF Library for AutoIT v3
Inet.au3 Functions that assist with the Internet
ListBoxConstants.au3 ListBox Constants
ListViewConstants.au3 ListView Constants
Math.au3 Functions that assist with mathematical calculations
Memory.au3 Memory management routines
Misc.au3 Functions that assist with Common Dialogs
Process.au3 Functions that assist with process management
ProgressConstants.au3 Progress Constants
SliderConstants.au3 Slider Constants
Sound.au3 Functions that assist with Sound files
SQLite.au3 Functions that assist access to an SQLite database
SQLite.dll.au3 Inline SQLite3.dll
StaticConstants.au3 Static Constants
StatusBarConstants.au3 StatusBar Constants
String.au3 Functions that assist with String manipulation
TabConstants.au3 Tab Constants
TreeViewConstants.au3 TreeView Constants
UpDownConstants.au3 UpDown Constants
Visa.au3 VISA (GPIB & TCP) library
WindowsConstants.au3 Windows Constants

!Important Note! Variants—Arrays with Differing Data Types

An array using different data types is known as a variant and can contain anything from a number to a Boolean value. Variants are not restricted in AutoIt; however, they are not recommended. Using differing data types in an array—especially arrays within an array—can dramatically decrease the execution speed of your scripts.

Wednesday, March 30, 2011

AutoIT Example 3. Two-Dimensional Array

Code:
$letter[0][0] = "w"
$letter[0][1] = "x"
$letter[1][0] = "y"
$letter[1][1] = "z"

A visual representation of Example 3 would be a 2×2 matrix as displayed in Figure 1.

AutoIT Constants and Arrays

Constants

 A constant is a variable that never changes. It remains a static value for the entire
script execution. You cannot change the value of a constant, nor can you convert
an existing variable into a constant. Placing Const after Dim, Global or Local makes
the variable a constant. You can also declare a constant variable without explicit
declaration. The following example illustrates how to declare a constant variable
in each scenario:

Code:
Const $example = 0
Dim Const $example1 = 1
Global Const $example2 = 2
Local Const $example3 = 3
Arrays

 An array is a matrix of data in which all the elements are of the same data type and
size. For example, an array of two numbers—“5” and “3”—is declared as follows:

Code:
$num[0] = "5"
$num[1] = "3"



Figure 1. Visual representation of Example 3. Two-Dimensional Array.
Arrays can also be multidimensional, with up to 64 dimensions. Example 3 shows a two-dimensional array.

AutoIT Variable Explicit Declaration Is Not Required

AutoIt does not require the explicit declaration of variables. However, as a debugging measure it is wise to explicitly declare all variables used within a script. If you do not explicitly declare variables, it can become very difficult to find a mistyped variable name that may be causing your script to error on
execution. You should include the following in your scripts to require the explicit declaration of variables in order to avoid bugs:

Code:
Opt("MustDeclareVars", 1)

With this option enabled, all variables must now be explicitly declared using Global, Local, or Dim.

Tuesday, March 29, 2011

AutoIT Variable Types

Dim, Global, and Local
There are three types of variables in AutoItT:

Dim
  Declaring a variable using Dim gives it the scope of its current location within   the script. If the variable is declared outside any functions, its scope is global.

  The following is an example of declaring a Dim variable in the global scope. It
runs setup.exe in the directory where the script is located:

Code:
Dim $variable = @ScriptDir & "\setup.exe"
  Run($variable)

  The next example shows how declaring a Dim variable inside a function allows it only Local scope and how the variable is destroyed once the function is complete.
 The result is a script that errors out when run because $variable is not declared globally:

Code:
function()
  Func function()
    Dim $variable = @ScriptDir & "\setup.exe"
  EndFunc

  Run($variable)

 You should explicitly declare variables as Global or Local to avoid problems. If a Dim variable is declared inside a function but a Global variable already exists, the Global variable is overwritten. The following example shows what happens if a Global variable exists when the same variable is declared as Dim within a
function. The result is that setupbad.exe runs instead of setup.exe; the Global $variable is modified to setupbad.exe because Dim was used to declare the variable locally within the function:

Code:
Global $variable = @ScriptDir & "\setup.exe"
  function()

  Func function()
    Dim $variable = @ScriptDir & "\setupbad.exe"
  EndFunc

  Run($variable)

Global
  This type of variable can be read from or written to from anywhere in the script.
Global variables can be used in functions without being destroyed when the
functions complete. The following is an example of declaring a Global variable:

Code:
  Global $variable = 2

Local
 A Local variable is used in the scope of a function. Once the function is complete,the variable is destroyed. If a Global variable of the same name already exists, the function modifies the Global variable and it is not destroyed when
the function completes. Variables are always checked in the local scope first,
then in the global scope. The following example shows the use of a Local variable
within a function:

Code:
function()
  Func function()
    Local $variable = @ScriptDir & "\setup.exe"
    Run($variable)
  EndFunc