• 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
Help with recursion
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Help with recursion


  • Subject: Help with recursion
  • From: Michelle Steiner <email@hidden>
  • Date: Tue, 11 May 2004 17:33:48 -0700

set target_date to get_date()
log "target date is " & target_date
set today to (current date)
set time_remaining to target_date - today
set Weeks_remaining to (time_remaining / weeks) div 1
set days_remaining to ((time_remaining - (Weeks_remaining * weeks)) / days) div 1 + 1

display dialog Weeks_remaining & " weeks, " & days_remaining & " days." as text giving up after 5

on get_date()
set target to false
repeat until target is true
set target_date to text returned of (display dialog "enter the target date" default answer "")
try
set target_date to date target_date
on error
get_date()
end try
set target to true
end repeat
return target_date
end get_date

If a correct entry is made the first time, the script works, but if there is an error the first time, and the script gets another input, the results of the first attempt are returned.

I see what the problem is; the incorrect entry is stored, and as the recursive loop unwinds, the first entry is the one that remains.

How do I fix it?

-- Michelle

--
"The optimist proclaims that this is the best of all possible worlds ;
and the pessimist fears this is true." --James Branch Cabell
_______________________________________________
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.


  • Follow-Ups:
    • Re: Help with recursion
      • From: Graff <email@hidden>
    • Re: Help with recursion
      • From: Walter Ian Kaye <email@hidden>
  • Prev by Date: Re: Toggle Modem Autoconnect Preference?
  • Next by Date: Re: Test, critique and ridicule this script!
  • Previous by thread: Re: Test, critique and ridicule this script!
  • Next by thread: Re: Help with recursion
  • Index(es):
    • Date
    • Thread