• 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: Lists and Variables
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Lists and Variables


  • Subject: RE: Lists and Variables
  • From: "Frank W. Walker" <email@hidden>
  • Date: Fri, 16 May 2003 15:52:53 -0400
  • Thread-topic: Lists and Variables

When I tried compiling Deivy's script, it errored on the line:

{+class usrf;:theList}

with: expected "," or "}" but found identifier

It didn't like usrf.

When I commented it out, it compiled ok (didn't try running it).
How come?

Frank

> ----------
> From: Deivy Petrescu
> Sent: Friday, May 16, 2003 2:32 PM
> To: Larry Staton Jr.
> Cc: AppleScript
> Subject: Re: Lists and Variables
>
> On Friday, May 16, 2003, at 11:20 US/Eastern, Larry Staton Jr. wrote:
>
> > How does one go about assigning variables to a list of variable length?
> >
> > I have a variable length list of 1 to 10 strings. Each item of the
> > list must be assigned to a variable named "TitleX", where X is item X
> > of the list.
> >
> > Here's what I want to do in code:
> >
> > set tNames to {"bob", "sally", "alice", "timmy"}
> >
> > repeat with i from 1 to (count items in tNames)
> > set Titlei to item i of tNames
> > end repeat
> >
> > Result:
> > Title1 --> "bob"
> > Title2 --> "sally"
> > Title3 --> "alice"
> > Title4 --> "timmy"
> >
> > TitleX --> item X of tNames
> >
> > Unsurprisingly, the above does not compile.
> >
> > What I have hacked up is 10 "if" statements like this:
> >
> > if (count of tNames = 3) then
> > set {Title1, Title2, Title3} to tNames
> > end if
> >
> > if (count of tNames = 4) then
> > set {Title1, Title2, Title3, Title4} to tNames
> > end if
> >
> > if (count of tNames = X) then
> > set {Title1 . . . TitleX} to tNames
> > end if
> >
> > return Title1
> > -- Result: "bob"
> >
> > Is there a more efficient way to create dynamic variables from a list
> > of unknown length?
> >
> > TIA.
> >
> > --
> > Larry Staton Jr.
> >
>
> Larry, this is how I'd go about doing that:
>
> <script>
> to usrf(theList)
> script
> {+class usrf;:theList}
> end script
> run script the result
> end usrf
>
>
> set tNames to {"bob", "sally", "alice", "timmy"}
> set myrec to {}
> repeat with i from 1 to (count items in tNames)
> set end of myrec to ("Title " & i)
> set end of myrec to item i of tNames
> end repeat
>
> set rec to usrf(myrec)
>
> |Title 2| of rec -->"sally"
>
> </script>
> Regards
>
> Deivy Petrescu
> http://www.dicas.com/
> _______________________________________________
> 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.

  • Prev by Date: Re: automated Filemaker file saving
  • Next by Date: Re: Folder Labels in OS X?
  • Previous by thread: Re: Lists and Variables
  • Next by thread: RE: Lists and Variables
  • Index(es):
    • Date
    • Thread