Adobe 65009333 Scripting Guide - Page 11
Variables, Logical True or False
UPC - 883919155852
View all Adobe 65009333 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 11 highlights
Getting Started Scripting terminology and the InCopy object model 11 Value Type Boolean Integer Number String Array What it is Example Logical True or False True Whole numbers (no decimal 14 points). Integers can be positive or negative. A high-precision number that can 13.9972 contain a decimal point. A series of text characters. Strings appear inside (straight) quotation marks. "I am a string" A list of values (the values can be any type). ["0p0", "0p0", "16p4", "20p6"] Converting values from one type to another JavaScript provides ways to convert variable values from one type to another. Most commonly, numbers are converted to strings (so you can enter them in text or display them in dialogs) or strings are converted to numbers (so you can use them to set a point size or page location). //To convert from a number to a string: myNumber = 2; myString = myNumber + ""; //To convert from a string to an integer: myString = "2"; myNumber = parseInt(myString); //If your string contains a decimal value, use "parseFloat" rather than "parseInt": myNumber = parseFloat(myString); //You can also convert strings to numbers using the following: myNumber = +myString; Variables A variable is a container for a value. They are called "variables" because the values they contain might change. A variable might hold a number, a string of text, or a reference to an InCopy object. Variables have names, and you refer to a variable by its name. To put a value into a variable, you assign the data to the variable. In all examples and tutorial scripts that come with InCopy, all variables start with my. This enables you to easily differentiate variables we created in a script from scripting-language terms. Assigning a value to a variable Assigning values or strings to variables is fairly simple, as shown below: var myNumber = 10; var myString = "Hello, World!"; var myTextFrame = myDocument.pages.item(0).textFrames.add(); NOTE: In JavaScript, all variables not preceded by var are considered global by default; that is, they are not bound to a specific function. While var is not required, we recommend you use it in any script with more than one function.