RE: using variables in place of property labels
RE: using variables in place of property labels
- Subject: RE: using variables in place of property labels
- From: Dennis Cox <email@hidden>
- Date: Fri, 5 Dec 2003 13:52:33 -0600
You can't refer to a record with a variable, it's not allowed. You have to
use the actual property name. What is happening is that it is looking for a
record property with a literal name myProperty, not whatever value you have
assigned to myProperty.
You can make a list of records, then compare the names of each of the
records in the list.
set bigList to {}
set rec1 to {name:"Bobby", age:11, shoe_size:7, height:"4 feet 9
inches", weight:"105lbs."}
copy rec1 to end of bigList
set rec2 to {name:"Robert", age:32, shoe_size:13, height:"6 feet 3 inches",
weight:"216lbs."}
copy rec2 to end of bigList
if name of item 1 of bigList is not equal to name of item 2 of bigList then
set name of item 2 of bigList to name of item 1 of bigList
--add the other comparisons
end if
Dennis
>
----------
>
From: Wallace, William
>
Sent: Friday, December 5, 2003 12:11 PM
>
To: email@hidden
>
Subject: using variables in place of property labels
>
>
Say for instance I have a record:
>
>
set myRecord to {name:"Robert", age:32, shoe_size:13}
>
>
Is there no way to do this:
>
>
set myLabel to "name"
>
get myLabel of myRecord
>
-->bob
>
>
or more specifically:
>
>
set myRecord to {name:"Robert", age:32, shoe_size:13}
>
set myLabels to {"name","age","shoe_size"}
>
>
repeat with i from 1 to count of myLabels
>
set myProperty to item i of myLabels
>
get myProperty of myRecord
>
end repeat
>
>
I have in my script, a large record. Actually two records. One is a record
>
of the initial state of an object the other is a record of the
>
subsequently modified state of the same object. I'd like to compare some
>
(but not all) of the properties of the new state to the old state and
>
change them back to their initial settings. There are enough of these
>
properties to be checked that I thought it would be convenient to loop
>
through the process in manner similar to the above, but it don't work.
>
Does anybody know of a way to achieve this without having to hardwire a
>
bunch of if-then statements for each individual property to be examined?
>
>
what I really want to do is something like this:
>
>
set myOldRecord to {name:"Bobby", age:11, shoe_size:7, height:"4 feet 9
>
inches", weight:"105lbs."}
>
set myNewRecord to {name:"Robert", age:32, shoe_size:13, height:"6 feet 3
>
inches", weight:"216lbs."}
>
set myLabels to {"name","shoe_size","weight"}
>
>
repeat with i from 1 to count of myLabels
>
set myProperty to item i of myLabels
>
if myProperty of myNewRecord is not myProperty of myOldRecord
>
set myProperty of myNewRecord to myProperty of myOldRecord
>
end if
>
end repeat
>
--{name:"Bobby", age:32, shoe_size:7, height:"6 feet 3 inches",
>
weight:"105lbs."}
>
>
(I know... Bobby's a weird looking dude)
>
>
B!ll
>
>
PS - Thanks for all your help with that other stuff, Hans.
>
_______________________________________________
>
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.
_______________________________________________
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.