RE: Addressing variables in subroutines
RE: Addressing variables in subroutines
- Subject: RE: Addressing variables in subroutines
- From: "Marc S.A. Glasgow" <email@hidden>
- Date: Thu, 20 Feb 2003 17:56:41 -0500
Jan,
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)".
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.
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).
4. Missing return value.
-- in the main body:
Local SomeText
Local OurCount
-- further down in the main body:
set SomeText to "This is the sample text to search for" as text
set OurCount to my zaehle(SomeText)
-- As the Handler
Local TheRecordCount
on zaehle (String1)
set TheRecordCount to 0
try
tell application "FileMaker Pro"
show every record of database "scheine.fp5"
show (every record whose cell "ES_Note" is String1)
set TheRecordCount to count of records as integer
end tell
return TheRecordCount
on error
display dialog "failure in handler Zaehle" buttons {"Cancel"}
default button 1
return -1 as integer
end try
end zaehle
Best Wishes,
=-= Marc Glasgow
---------------------------------------------------
Message: 3
Date: Thu, 20 Feb 2003 17:27:04 +0100
From: Jan Bruners <email@hidden>
Subject: Addressing variables in subroutines
To: email@hidden
Hi all,
I am trying to write a script using a subroutine like this:
on zaehle(var1,var2)
tell application "FileMaker Pro"
show every record of database "scheine.fp5"
show (every record whose cell "ES_Note" is string1)
set string2 to count of records
end tell
end zaehle
zaehle(note1,sg1)
-- snip
The subroutine obviously uses the current value of the variables, which
is ok for var1. But var2 should be treated as the variable's name (to
modify the variable's value in the subroutine), not as var2's value.
I already defined both vars as global.
Any help?
Thanks,
Jan
_______________________________________________
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.