Hi all!
Just a quickie really… Is there a better way of doing the following?
if layoutStyle = 1 then
set horCount to 2
set verCount to 1
else
if layoutStyle = 2 then
set horCount to 2
set verCount to 2
else
if layoutStyle = 3 then
set horCount to 4
set verCount to 2
else
if layoutStyle = 4 then
set horCount to 4
set verCount to 4
end if
end if
end if
end if
I’d appreciate any help on this, as this is something I will be using a lot in a script I’m using.
Thanks,
Juerg
: Hi all!
: Just a quickie really… Is there a better way of doing the
: following?
: if layoutStyle = 1 then
: set horCount to 2
: set verCount to 1
: else
: if layoutStyle = 2 then
: set horCount to 2
: set verCount to 2
: else
: if layoutStyle = 3 then
: set horCount to 4
: set verCount to 2
: else
: if layoutStyle = 4 then
: set horCount to 4
: set verCount to 4
: end if
: end if
: end if
: end if
: I’d appreciate any help on this, as this is something I will be
: using a lot in a script I’m using.
: Thanks,
: Juerg –
Is this what you had in mind?
set theCounts to {{2, 1}, {2, 2}, {4, 2}, {4, 4}}
set {horCount, verCount} to ¬
item layoutStyle of theCounts
vb
Ha! Yes! That’s PERFECT If feel a bit stupid for not realising it myself!!! And there I was thinking that I was getting the hang of scripting… Oh well…
Thanks VERY much for your help.
Juerg
Well, Von’s already given the ideal solution to your particular problem, but as far as simplifying if blocks in general goes, you should also be aware of the ‘else if’ construct as a way of avoiding unnecessary nesting; eg:
if x = 1 then
--do something
else if x = 2 then
--do something else
else
--do another thing
end if
Actually, THIS is what is was really after - thanks!
It just so happened that there was a better way of doing what I wanted to do!
I’ve now made good use of your suggestion in a different script
Many thanks,
Juerg