Re: compactness of expression question
Re: compactness of expression question
- Subject: Re: compactness of expression question
- From: Steven Angier <email@hidden>
- Date: Fri, 18 Jan 2002 08:29:22 +1100
- Organization: Macscript.com
billp wrote:
>
Is there a more compact way I can express the following?:
Several:
1. using 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
----
2. adding one global line:
----
global CharacterCount, WordCount, LineCount, ParagraphCount, TableCount
if ItemKind = "Characters" then
set CharacterCount to ItemCount
else if ItemKind = "Words" then
set WordCount to ItemCount
else if ItemKind = "Lines" then
set LineCount to ItemCount as integer
else if ItemKind = "Paragraphs" then
set ParagraphCount to ItemCount as integer
else if ItemKind = "Tables" then
set TableCount to ItemCount
end if
----
3. using the Macscript.com Library's GetOffsetInList() function (demo available from
http://www.macscript.com):
----
property kItemKindList : {"Characters", "Words", "Lines", "Paragraphs", "Tables"}
property gCounts : {0, 0, 0, 0, 0}
set theOffset to GetOffsetInList(ItemKind, kItemKindList)
if theOffset > 0 then set item theOffset of gCounts to ItemCount
----
Steven Angier
Macscript.com