Array Variables; Converting Values From One Type To Another - Adobe 27510753 - InDesign CS2 - PC Manual

Scripting guide
Hide thumbs Also See for 27510753 - InDesign CS2 - PC:
Table of Contents

Advertisement

12
Scripting Basics
Like VB.NET, JavaScript does not require Set when you assign values to variables, regardless of the type of the
variable:
var myDocument = app.documents.add();
var myString = "X";

Array variables

AppleScript, VBScript, and JavaScript all support arrays, which is a variable type that is a list of values. In
AppleScript, an array is called a list.
AppleScript
VBScript
JavaScript
To refer to an item in an array, refer to the item by its index in the array. The first item in an array in VBScript
and JavaScript is item 0; in AppleScript, the first item in an array is item 1.
AppleScript
VBScript
JavaScript
Note:
The Visual Basic Option Base statement can be used to set the first item of an array to item 1. The ex-
amples in this book and on your InDesign CD assume that the first item in an array is item 0, not item 1,
because that is the default. If you have set the Option Base to 1, you must adjust all the array references
in the example scripts accordingly.
Arrays can include other arrays, as shown in the following examples.
AppleScript
VBScript
JavaScript

Converting values from one type to another

All the scripting languages supported by InDesign provide ways to convert variable values from one type to
another. The most common conversions involve converting numbers to strings (so that you can enter them in
text or display them in dialog boxes) or converting strings to numbers (so that you can use them to set a point
size or other numeric values).
AppleScript
--To convert from a number to a string:
set myNumber to 2
set myString to (myNumber as string)
--To convert from a string to a number:
set myString to "2"
set myNumber to (myString as integer)
--if your string contains a decimal value, use "as real" rather than "as integer"
set myArray to {1, 2, 3, 4}
myArray = Array(1, 2, 3, 4)
Rem In Visual Basic.NET: myArray = New Double (1, 2, 3, 4)
myArray = [1, 2, 3, 4];
set myFirstArrayItem to item 1 of myArray
myFirstArrayItem = myArray(0)
myFirstArrayItem = myArray[0];
set myArray to {{0, 0}, {72, 72}}
myArray = Array(Array(0,0), Array(72, 72))
Rem In Visual Basic.NET: myArray = New Array(New Double(0,0),
NewDouble (0,0))
myArray = [[0,0], [72,72]];
Adobe InDesign CS2 Scripting Guide

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents