Re: compactness of expression question
Re: compactness of expression question
- Subject: Re: compactness of expression question
- From: Paul Berkowitz <email@hidden>
- Date: Thu, 17 Jan 2002 13:24:23 -0800
On 1/17/02 12:51 PM, "billp" <email@hidden> wrote:
>
Is there a more compact way I can express the following?:
>
>
if ItemKind = "Characters" then
>
global CharacterCount
>
set CharacterCount to ItemCount
>
else
>
if ItemKind = "Words" then
>
global WordCount
>
set WordCount to ItemCount
>
else
>
if ItemKind = "Lines" then
>
global LineCount
>
set LineCount to ItemCount as integer
>
else
>
if ItemKind = "Paragraphs" then
>
global ParagraphCount
>
set ParagraphCount to ItemCount as integer
>
else
>
if ItemKind = "Tables" then
>
global TableCount
>
set TableCount to ItemCount
>
end if
>
end if
>
end if
>
end if
>
end if
>
Use else if':
if ItemKind = "Characters" then
global CharacterCount
set CharacterCount to ItemCount
else
if ItemKind = "Words" then
global WordCount
set WordCount to ItemCount
else
if ItemKind = "Lines" then
global LineCount
set LineCount to ItemCount as integer
else
if ItemKind = "Paragraphs" then
global ParagraphCount
set ParagraphCount to ItemCount as integer
else
if ItemKind = "Tables" then
global TableCount
set TableCount to ItemCount
end if
end if
end if
end if
end if
if ItemKind = "Characters" then
global CharacterCount
set CharacterCount to ItemCount
else if ItemKind = "Words" then
global WordCount
set WordCount to ItemCount
else if ItemKind = "Lines" then
global LineCount
set LineCount to ItemCount as integer
else if ItemKind = "Paragraphs" then
global ParagraphCount
set ParagraphCount to ItemCount as integer
else if ItemKind = "Tables" then
global TableCount
set TableCount to ItemCount
end if
I've never made a global statement midway through a script rather than at
the top, but I believe that will work. (Otherwise you'd declare them all as
global at the top, then just define the one you need - not so good.) Any
particular reason not just to declare
global ItemCount
and then just do:
if {ItemKind} is in {"Lines", "Paragraphs"} then
set ItemCount to ItemCount as integer
end if
Or do you need all these different ItemCounts at once?
--
Paul Berkowitz