Finding The Value Type Of A Variable - Adobe 27510753 - InDesign CS2 - PC Manual

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

Advertisement

Adobe InDesign CS2 Scripting Guide
Scripting Basics
13
VBScript
Rem To convert from a number to a string:
myNumber = 2
myString = cstr(myNumber)
Rem To convert from a string to an integer:
myString = "2"
myNumber = cInt(myString)
Rem If your string contains a decimal value, use "cDbl" rather than "cInt":
myNumber = cDbl(myString)
JavaScript
//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;

Finding the value type of a variable

Sometimes, your scripts must make decisions based on the value type of an object. If you're working on a
script that operates on a text selection, for example, you might want that script to stop if the type of the
selection is a page item. All of the scripting languages allow you to determine the type of a variable.
AppleScript
-- Given a variable of unknown type, "myMysteryVariable"...
set myType to class of myMysteryVariable
--myType will be an AppleScript type (e.g., rectangle)
VBScript
Rem Given a variable of unknown type, "myMysteryVariable"...
myType = TypeName(myMysteryVariable)
Rem myType will be a string corresponding to the variable type (e.g., "Rectangle")
JavaScript
//Given a variable of unknown type, "myMysteryVariable"...
var myType =typeof (myMysteryVariable);
//If the variable is an object, "typeof" will return "object".
//To get the specific type of the object, add the following:
if (myType == "object"){
myType = myMysteryVariable.constructor.name;
}
//myType will be a string corresponding to the JavaScript type (e.g., "Rectangle")
When you are iterating through a collection, JavaScript insists that the type of the item is the type of the
collection. When you iterate through a pageItems collection, for example, the type of each item will be
, rather than Rectangle , Oval , Polygon , GraphicLine , or TextFrame . To get the specific type
PageItem
of an item when you are iterating through a collection of unlike items, use the getElements() method, as
shown in the following example:

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Indesign cs2

Table of Contents