• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Checking a Record for a Field
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Checking a Record for a Field


  • Subject: Re: Checking a Record for a Field
  • From: Yvan KOENIG <email@hidden>
  • Date: Mon, 16 Nov 2015 16:15:50 +0100


Le 2015/11/16 à 15:17, S. J. Cunningham <email@hidden> a écrit :

I have a handler  to which I would like to pass a variable number of arguments.  I am using a record to pass the arguments and then checking in the handler whether or not a specific field exists so I can skip it if it doesn't. Here is how I am doing the check:

on myCoolHandler(someRecord)
display dialog Field_1 of someRecord
display dialog Field_2 of someRecord
if checkForField_3(someRecord) then
display dialog Field_3 of someRecord
else
display dialog "There ain't no Field 3"
end if
end myCoolHandler

on checkForField_3(theRecord)
set returnValue to true
try
get Field_3 of theRecord
on error
set returnValue to false
end try
return returnValue
end checkForField_3

set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}
myCoolHandler(theRecord)
"

Is there an easier way to accomplish this?  In particular, is there a way to parameterize the check?  As it is, I need a separate "check handler" for each field I want to check.


Steve
------------------


I would do the job in a single couple of handler :

on myCoolHandler(someRecord)
set {field1, field2, field3} to checkForFields(someRecord)
if field1 is false then
set report to "there is no field 1"
else
set report to field1
end if


if field2 is false then
set report to report & linefeed & "there is no field 2"
else
set report to report & linefeed & field2
end if


if field3 is false then
set report to report & linefeed & "there is no field 3"
else
set report to report & linefeed & field3
end if
display dialog report
end myCoolHandler

on checkForFields(theRecord)
try
set field1 to get Field_1 of theRecord
on error
set field1 to false
end try
try
set field2 to get Field_2 of theRecord
on error
set field2 to false
end try
try
set field3 to get Field_3 of theRecord
on error
set field3 to false
end try
return {field1, field2, field3}
end checkForFields

set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}
myCoolHandler(theRecord)

or even in a single one :

on myCoolHandler(someRecord)
try
set field1 to get Field_1 of someRecord
on error
set field1 to false
end try
try
set field2 to get Field_2 of someRecord
on error
set field2 to false
end try
try
set field3 to get Field_3 of someRecord
on error
set field3 to false
end try
if field1 is false then
set report to "there is no field 1"
else
set report to field1
end if


if field2 is false then
set report to report & linefeed & "there is no field 2"
else
set report to report & linefeed & field2
end if


if field3 is false then
set report to report & linefeed & "there is no field 3"
else
set report to report & linefeed & field3
end if
display dialog report
end myCoolHandler


set theRecord to {Field_1:"Field 1", Field_2:"Field 2"}
myCoolHandler(theRecord)


Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) lundi 16 novembre 2015 16:15:43



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Checking a Record for a Field (From: "S. J. Cunningham" <email@hidden>)

  • Prev by Date: Checking a Record for a Field
  • Next by Date: Re: Checking a Record for a Field
  • Previous by thread: Checking a Record for a Field
  • Next by thread: Re: Checking a Record for a Field
  • Index(es):
    • Date
    • Thread