Re: Scripting in Excel -> search different words in column and color them
Re: Scripting in Excel -> search different words in column and color them
- Subject: Re: Scripting in Excel -> search different words in column and color them
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 24 Oct 2002 08:52:48 -0700
On 10/24/02 2:36 AM, "David Wignall" <email@hidden> wrote:
>
>
Just vaguely apropos to this, does AppleScript have a For Each object In
>
collection type of statement? The ASLG doesn't reveal anything to me.
ASLG, pp. 256-7, but notice the catch described in the NOTES, requiring
'contents of' operator, or else evaluating the list item explicitly to a
variable. For that reason (i.e. forgetting about it), it's usually simpler
to use the 'Repeat With (loopVariable) From (startValue) To (stopValue)'
method.
p.256:
Repeat With (loopVariable) In (list)
In the Repeat With (loopVariable) In (list) form of the Repeat statement,
the loop variable is a reference to an item in a list. The number of
iterations is equal to the number of items in the list. In the first
iteration, the value of the variable is item 1 of list (where list is the
list you specified in the first line of the statement), in the second
iteration, its value is item 2 of list, and so on.
SYNTAX
repeat with loopVariable in list
[ statement ]...
end [ repeat ]
where
loopVariable is any previously defined variable or a new variable you
define in the Repeat statement (see 3Notes2).
list is a list or a reference (such as words 1 thru 5) whose value is a
list.
list can also be a record; AppleScript coerces the record to a list (see
3Notes2).
statement is any AppleScript statement.
EXAMPLE The following script examines a list of words
with the Repeat With (loopVariable) In (list) form of the Repeat statement,
displaying a dialog if it finds the word 3hammer2 in the list.
set wordList to words in "Where is the hammer?"
repeat with currentWord in wordList
--log currentWord
if currentWord as text is equal to "hammer" then
display dialog "I found the hammer!"
end if
end repeat
For a description of the commented-out statement --log currentWord,
see 3Debugging Control Statements2 (page 239).
NOTES
You can use an existing variable as the loop variable in a Repeat statement
or define a new one in the Repeat statement. In either case, the loop
variable is defined outside the loop. You can change the value of the loop
variable inside the loop body but it will get reset to the next loop value
the next time through the loop. After the loop completes, the loop variable
retains its last value.
AppleScript evaluates loopVariable in list as item 1 of list, item 2 of
list, item 3 of list, and so on until it reaches the last item in the list,
as shown in the following example.
repeat with i in {1, 2, 3, 4}
set x to i
end repeat
--result: item 4 of {1, 2, 3, 4}
To set a variable to the value of an item in the list, rather than a
reference to the item, you can use the contents of operator:
repeat with i in {1, 2, 3, 4}
set x to contents of i
end repeat
--result: 4
--
Paul Berkowitz
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.