RE: Addressing variables in subroutines
RE: Addressing variables in subroutines
- Subject: RE: Addressing variables in subroutines
- From: Jan Bruners <email@hidden>
- Date: Fri, 21 Feb 2003 11:14:42 +0100
Marc,
Marc S.A. Glasgow <email@hidden> schrieb am Donnerstag, 20. Februar 2003:
>
the things that come to mind (and they may not be the right
>
answers) are:
>
>
1. I don't see where var1 or var2 are called by their names within the
>
routine (or change within it) -- are they supposed to be the same as
>
string1 and string2? If so, they must be named the same at the "on
>
Zaehle" definition (i.e. - "On Zaehle (string1, string2)".
>
I am sorry. The version of the script I submitted came from a modification timepoint and was inconsistent. Of course, I used var1, var2 bothe top and within the subroutine.
>
2. Coercion. To ensure that the variable is of the right type when it
>
arrives at the handler (the AppleScript name for a subroutine), try
>
casting a local copy of it in the expected format and
>
then using the local copy; at the end, copy the local back to the
>
global.
Thanks! I did that and it made my script more elegant (although it's still very clumsy.
>
>
3. Explicit globals -- don't globalize variables for this handler,
>
since it only needs one piece of data (the text to compare ES_Note to,
>
which doesn't change within the handler), and returns only 1 piece of
>
data (the count). Instead, pass in a single value (the text to search
>
for) and return 1 value (the count).
>
You're right. I did that.
>
4. Missing return value.
Yes! I did:
repeat with i from 1 to count items of noten
set thenote to item i of noten
set contents of item i of anzahlen to thezahl
end repeat
with setting thezahl in the subroutine zaehle. But it's smarter to:
repeat with i from 1 to count items of noten
set thenote to item i of noten
set contents of item i of anzahlen to zaehle(thenote)
end repeat
with zaehle returning the needed value. Thanks!
- Jan
--
Jan Bruners
University of Cologne
Department of German Linguistics and Literature
Albertus Magnus Platz - 50923 Koeln - Germany
_______________________________________________
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.