Adobe 26001360 Scripting Guide - Page 22
Variables, Option, Explicit
UPC - 718659321840
View all Adobe 26001360 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 22 highlights
22 Scripting concepts Variables Variables are containers for data. A variable might contain a number, a string, a list (or array), or an object reference. Variables have names, and you refer to a variable by its name. To put data into a variable, we assign the data to the variable. The file name of the current Illustrator document or the current date are both examples of data that can be assigned to a variable. Why not simply enter the value directly in the script rather than using a variable? When you use a value directly the flexibility of script is reduced. By using variables the scripts you write will be reusable in a wider variety of situations. As a script executes, it can assign data to the variables that reflect the state of the current document and selection, for example, and then make decisions based on the content of the variables. In AppleScript, it is not necessary to declare your variables before assigning values to them. In Visual Basic, however, it is considered good form to declare all of your variables before using them with the Dim statement. Using the Dim statement assigns a value type to the variable, which helps us keep our scripts clear and readable. Memory is also used more efficiently if variables are declared before use. If you start your scripts in Visual Basic with the line Option Explicit, you will be required to declare all variables before assigning data to them. Visual Basic Option Explicit Dim thisNumber As Single thisNumber = 10 Assigning values to variables is fairly simple, as shown below. AppleScript set thisNumber to 10 set thisString to "Hello, World!" Visual Basic thisNumber = 10 thisString = "Hello, World!" Variables can also be used to store references to objects. In AppleScript, a reference is returned when you create a new object in an Illustrator document. This returned reference points to the 12 Aug 03