Adobe 23101764 Scripting Guide - Page 29

Handlers, subroutines and functions

Page 29 highlights

Scripting basics 2 Handlers, subroutines and functions VB flag = False Do While flag = False retVal = MsgBox("Quit?", vbOKCancel) If (retVal = vbCancel) Then flag = True End If Loop flag = False Do Until flag = True retVal = MsgBox("Quit?", vbOKCancel) If (retVal = vbOK) Then flag = True End If Loop JS var flag = false; while (flag == false) { flag = confirm("Are you sure?"); } var flag = false; do { flag = confirm("Are you sure?"); } while (flag == false); 2.9 Handlers, subroutines and functions Subroutines, or handlers (in AppleScript) and functions (in JavaScript), are scripting modules you can refer to from within your script. These subroutines provide a way to re-use parts of scripts. Typically, you send one or more values to a subroutine and it returns one or more values. There's nothing special about the code used in subroutines - they are conveniences that save you from having to retype the same code lines in your script. Photoshop CS Scripting Guide 25

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105

Photoshop CS Scripting Guide
25
Scripting basics
Handlers, subroutines and functions
2
VB
flag = False
Do While flag = False
retVal = MsgBox("Quit?", vbOKCancel)
If (retVal = vbCancel) Then
flag = True
End If
Loop
flag = False
Do Until flag = True
retVal = MsgBox("Quit?", vbOKCancel)
If (retVal = vbOK) Then
flag = True
End If
Loop
JS
var flag = false;
while (flag == false)
{
flag = confirm("Are you sure?");
}
var flag = false;
do
{
flag = confirm("Are you sure?");
}
while (flag == false);
2.9 Handlers, subroutines and functions
Subroutines, or handlers (in AppleScript) and functions (in JavaScript), are scripting modules
you can refer to from within your script. These subroutines provide a way to re-use parts of
scripts. Typically, you send one or more values to a subroutine and it returns one or more
values.
There’s nothing special about the code used in subroutines — they are conveniences that save
you from having to retype the same code lines in your script.